
$(document).ready(function () {
  $('a[rel=lightbox]').lightBox({fixedNavigation:true});
  
  $("#homeslider").scrollable({ circular: true }).autoscroll({autoplay: true, interval: 5000});
  $("#imgsliderleft").scrollable({ circular: true }).autoscroll({autoplay: true, interval: 5000}).navigator();

  $.ajaxSetup({ scriptCharset: "utf-8" ,contentType: "application/x-www-form-urlencoded; charset=UTF-8" });
  
  // Form placeholder
  function placeholder() {
    $("input[type=text], input[type=password], textarea").each(function () {
      var phvalue = $(this).attr("placeholder");
      $(this).val(phvalue);
    });
  }
  placeholder();
  $("input[type=text], input[type=password], textarea").focusin(function () {
    var phvalue = $(this).attr("placeholder");
    if (phvalue == $(this).val()) {
      $(this).val("");
    }
  });
  $("input[type=text], input[type=password], textarea").focusout(function () {
    var phvalue = $(this).attr("placeholder");
    if ($(this).val() == "") {
      $(this).val(phvalue);
    }
  });
  
  $('.corner5').corner("5px");
  $('.cornerl5').corner("5px left");
  $('.cornerr5').corner("5px right");
  
  $('form#contactForm').submit(function() {
		$('form#contactForm .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
			if($(this).hasClass('textarea') && ( jQuery.trim($(this).val()) == '' || $(this).val() == $(this).attr('placeholder') ) ) {
				var labelText = $(this).prev('label').text();
				$(this).parent().prepend('<span class="error"><img src="'+template_url+'/vis/error.png" title="Bitte vervollst&auml;ndigen Sie: '+labelText+'." alt="" /><br /></span>');
				hasError = true;
			}
      else if(jQuery.trim($(this).val()) == '' || $(this).val() == $(this).attr('placeholder') ) {
				var labelText = $(this).prev('label').text();
				$(this).parent().prepend('<span class="error"><img src="'+template_url+'/vis/error.png" title="Bitte vervollst&auml;ndigen Sie: '+labelText+'." alt="" /></span>');
				hasError = true;
			} else if($(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text();
					$(this).parent().prepend('<span class="error"><img src="'+template_url+'/vis/error.png" title="Fehlerhafte Eingabe f&uuml;r: '+labelText+'." alt="" /></span>');
					hasError = true;
				}
			}
		});
		if(!hasError) {
			$('form#contactForm li.buttons button').fadeOut('normal', function() {
				$(this).parent().append('<img src="'+template_url+'/images/lightbox-ico-loading.gif" alt="Loading&hellip;" height="31" width="31" />');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('form#contactForm').slideUp("fast", function() {				   
					$(this).before('<p class="thanks"><strong>Vielen Dank!</strong> Ihre Anfrage wurde erfolgreich versendet. Wir werden Ihre Anfrage schnellstm&ouml;glich bearbeiten.</p>');
				});
			});
		}
		
		return false;
		
	});
  
});

