$(function(){
	/* CHANGE LIST-IMAGE IF THERE IS AN <A> INSIDE AN <LI> */	
	$(".mainContent ul a").each(function(){
		$(this).parent().addClass("arrow");
	});
	
	/* SEARCH FORM */
	$(".searchForm").submit(function() {
		if ($.trim($(this).find('input[type=text]:first').val()) != "" && $.trim($(this).find('input[type=text]:first').val()) != $(this).find('input[type=text]:first').attr("title")) {
			return true;	
		}
		return false;
	});

	/* EMPTY FIELDS on focus */	
	$(".emptyFields").live('click',function() {
		if (!$(this).hasClass('passwordField')) {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}
		} else {
			if ($(this).attr('type') == 'text') {
				$('<input type="password" name="loginPass" class="normalInput passwordField emptyFields" value="" title="Uw wachtwoord" />').insertAfter($(this));
				$('.passwordField').focus();
				$(this).remove();
			}
		}
	});
	$(".emptyFields").live('blur',function() {
		if (!$(this).hasClass('passwordField')) {
			if ($.trim($(this).val()) == '') {
				$(this).val($(this).attr('title'));
			}
		} else {
			if ($.trim($(this).val()) == '') {
				$('<input type="text" name="loginPass" class="normalInput passwordField emptyFields" value="Uw wachtwoord" title="Uw wachtwoord" />').insertAfter($(this));
				$(this).remove();
			}
		}
	});
	// SLIDER VESTIGINGEN
	$('#sliderHeader').cSlider({
		cSlideItemClass : 'cSliderItemHeader',
		animationSpeed : 2000,
		showTime : 5000,
		cSliderPager : true,
		cSliderPageNumber : true,
		cSliderAutoSlide : true,
		cSlideDirection	: 4			// 0 is naar rechts sliden 1 is naar links sliden 2 is boven naar onder 3 is onder naar boven
	});	
	
	
// HOMPAGE SCRIPTS
	$(".expandContentBtn").click(function(){
		$(".headerSmallContainerEnglish").css({display:'none'});
		$(".headerSmallContainerDutch").css({display:'block'});
		$("#langBtn").removeClass("dutchBtn");
		$("#langBtn").addClass("englishBtn");
		var headerSmallContent = $(this).parent().find(".headerSmallContainer");
		if(headerSmallContent.is(":hidden")){
			$(".headerSmallExpand").css({zIndex:1});
			$(".headerSmallContainer").stop(true, true).fadeOut(300);
			$(".headerSmallContent, .headerSmallContentBottom").css({display:"none"});
			$(this).parent().css({zIndex:100});
			headerSmallContent.stop(true, true).show(300, function(){
				$(".headerSmallContent, .headerSmallContentBottom").fadeIn(500);
			});
		}
		return false;
	});
	
	$(".closeContentBtn").click(function(){
		var headerSmallContent = $(this).parent();
		headerSmallContent.stop(true, true).fadeOut(300);
		return false;
	});

	$("#langBtn").click(function(){
		$(".headerSmallContainerEnglish").toggle();
		$(".headerSmallContainerDutch").toggle();

		if($(this).hasClass("dutchBtn")) {
			$(this).removeClass("dutchBtn").addClass("englishBtn");
		}
		else {
			$(this).removeClass("englishBtn").addClass("dutchBtn");
		}

		return false;
	});

	
/*	$("#langBtn.englishBtn").click(function(){
		$(".headerSmallContent").hide();
		$(".headerSmallContentEnglish").show();
		$(this).removeClass("englishBtn");
		$(this).addClass("dutchBtn");
	});
	
	$("#langBtn.dutchBtn").click(function(){
		$(".headerSmallContent").show();
		$(".headerSmallContentEnglish").hide();
		$(this).removeClass("dutchBtn");
		$(this).addClass("englishBtn");
	});*/
	
	// SLIDER
	$('#slider1').cSlider({
		cSlideItemClass : 'cSliderItem',
		animationSpeed : 2000,
		showTime : 5000,
		cSliderPager : true,
		cSliderPageNumber : true,
		cSliderAutoSlide : true,
		cSlideDirection	: 4			// 0 is naar rechts sliden 1 is naar links sliden 2 is boven naar onder 3 is onder naar boven
	});
	
	$('.sendButtonLeft, .sendButtonRight').click(function() {
		if ($.trim($('#nieuwsLetter').val()) != '' && $('#nieuwsLetter').val() != 'Uw e-mailadres') {
		if($(this).val() == 'Aanmelden') {
			var type = 'aanmelden';	
		} else {
			var type = 'afmelden';
		}
		$('#newsletterStatusBox p').html('Bezig met ' + type);		
		$('#newsletterStatusBox').css({opacity:'0.9', display:'block'});
		
			$.post('/subscribe-newsletter.php',{type: type, email: $('#nieuwsLetter').val()}, function(data) {
				if(data.succes) {
					$('#newsletterStatusBox p').html('Het ' + type + ' is gelukt');
				} else {
					$('#newsletterStatusBox p').html('Het ' + type + ' is niet gelukt');
				}
				setTimeout(function(){
					$('#newsletterStatusBox').css({display:'none'});
				},1500);
			},'json');
		}
	});
	
	
	//Accordeon
	$(".arrowLinkEnews").click(function(){
		var openDiv = true;
		if($(this).next(".eNewsToggleDiv").hasClass("toggleDivOpen")) {
			openDiv = false;
		}

		$(".toggleDivOpen").animate({
			height:'toggle'},600, function(){
			$(this).prev().find(".toggleButton").text("+");
			$(this).prev().removeClass("active");
			$(this).removeClass("toggleDivOpen");
		});
		
		if(openDiv) {
			$(this).next(".eNewsToggleDiv").animate({
				height:'toggle'
			},600, function() {
				$(this).prev().find(".toggleButton").text("-");
				$(this).prev().addClass("active");
				$(this).addClass("toggleDivOpen");
			});
		}
		
		return false;
	})
	$(".eNewsToggleDiv").hide();
	$(".toggleButton").text("+");
});	
