// wisselen van sponsor
var klantLijst = new Array();
var counter = 0;
var currentKlant;

$(document).ready(function(){
	
	if ($("#faqs")) {
		if ($(document.location.hash) && document.location.hash) {
			$('#faqs').activate(document.location.hash);
		}
	}

	truePath = $('script[@src$=jquery.js]').attr('src').replace("js/jquery.js", "");

	// PNG FIX
	$('img[@src$=.png], #panel').pngfix();

	// change language
	$("#lSelect").change(function() {
		eval("top.location='"+$(this).val()+"'");
	});

	// Move the floater when scrolling
	/*$(window).scroll(function(){
		var ScrollTop = document.body.scrollTop;
		if(ScrollTop == 0){
			var yOff = window.pageYOffset;
			if (yOff){
				ScrollTop = yOff;
			}else{
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}
		$('#floater').css({ top: ScrollTop+'px' });
	});*/

	$('ul#menu li').hover(
		function(){
			menuOver($(this));
		},
		function() {
			menuOut($(this));
		}
	);

	$('#menu > li').hover(function(){
		$(this).attr('id', 'over');
	},function(){
		$(this).attr('id', 'up');
	});

	// Sifr headers
	var source = {
		src: truePath + 'swf/gillsans.swf'
	};

	sIFR.useDomContentLoaded = false;

	sIFR.activate();

	sIFR.replace(source, {
		selector: '.menulink'
		,wmode: 'transparent'
		,fitExactly: 'true'
		,forceWidth: 'true'
		,css: {
			'.sIFR-root': { 'color': '#FFFFFF', 'font-size': '14px' }
			,'a': {'color': '#FFFFFF', 'text-decoration': 'none' }
			,'a:hover': {'color': '#FFFFFF' }
		}
	});
	
	// Sifr headers
	var source = {
		src: truePath + 'swf/corporate.swf'
	};

	sIFR.replace(source, {
		selector: 'h3'
		,wmode: 'transparent'
		,css: {
			'.sIFR-root': { 'color': '#333366', 'font-size': '24px', 'font-weigth': 'bold' }
		}
	});

	sIFR.replace(source, {
		selector: 'h1'
		,wmode: 'transparent'
		,css: {
			'.sIFR-root': { 'color': '#333366', 'font-size': '24px', 'font-weigth': 'bold' }
		}
	});

	if($('.klanten img').length > 1){
		for(var i = 0; i < $('.klanten img').length; i++){
			klantLijst.push($('.klanten img').eq(i));
			klantLijst[i].hide();
		}
		currentKlant = klantLijst[counter];
		currentKlant.show();
		window.setInterval('showKlanten()', 2000);
	}
	
	/*$("#nlForm").submit(function() {
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "/php/newsletter.php",
			data: "email="+$("#nlEmail").val()+"&name="+$("#nlName").val()+"&language_id="+$("#nlLanguage").val(),
			success: function(msg){
				alert(msg.errorDescr);
				if (!msg.error=='0') {
					$("#nlEmail").val("");
					$("#nlName").val("");
				}
			}
		});
		return false;
	});*/
	
	$("#nlForm").submit(function() {
		if($("#nlName").val() != "Naam"){
			$("#naam_txt").val($("#nlName").val());
		}
		if($("#nlSurname").val() != "E-mailadres"){
			$("#achternaam_txt").val($("#nlSurname").val());
		}
		$("#newsletter").css("display", "block");
		return false;
	});
	
	// aanmelden
	$("#confirm").click(
		function(){
			var errorTxt = "";
			if($("#name_txt").val() == ""){
				$("#name_txt").css("border", "1px solid red");
				errorTxt = "error";
			} else {
				$("#name_txt").css("border", "1px solid #B1B1C7");
			}
			if($("#email_txt").val() == ""){
				$("#email_txt").css("border", "1px solid red");
				errorTxt = "error";
			} else {
				$("#email_txt").css("border", "1px solid #B1B1C7");
			}
			if($("#message_txt").val() == ""){
				$("#message_txt").css("border", "1px solid red");
				errorTxt = "error";
			} else {
				$("#message_txt").css("border", "1px solid #B1B1C7");
			}			
			if(errorTxt == ""){
				// send mail after validation
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "/mailsender.php",
					data: "name_txt="+$("#name_txt").val()+"&email_txt="+$("#email_txt").val()+"&message_txt="+$("#message_txt").val()+"&messagesubject_txt="+$("#messagesubject_txt").val()+"&code="+$("#code").val(),
					success: function(msg){
						if(msg.error==0){
							$("#code").css("border", "1px solid #B1B1C7");
							alert( "Uw opmerkingen zijn verzonden!" );
							window.location="./";
						} else {
							$("#code").css("border", "1px solid red");
						}
					}
				});
				return false;
			}
			else{
				return false;
			}
		}
	);
	
	/* Aanmeld formulier voor de nieuwsbrief */
	
	$("#close_newsletter").click(
		function(){
			$("#newsletter").css("display", "none");
		}
	);

	$("#send_newsletter").click(
		function(){
			var geslacht = "";
			var taal = "";
			
			if($("#m_radio").attr("checked")) {
				var scope = $("#m_radio").parent();
				geslacht = $("label" ,scope).html();
			}
			if($("#v_radio").attr("checked")) {
				var scope = $("#v_radio").parent();
				geslacht = $("label" ,scope).html();
			}
			if($("#v_radio_2").attr("checked")) {
				var scope = $("#v_radio_2").parent();
				geslacht = $("label" ,scope).html();
			}
			//
			if($("#ned_radio").attr("checked")) {
				var scope = $("#ned_radio").parent();
				taal = $("label" ,scope).html();
			}
			if($("#eng_radio").attr("checked")) {
				var scope = $("#eng_radio").parent();
				taal = $("label" ,scope).html();
			}
			
			// send mail after validation
			$.ajax({
				type: "POST",
				dataType: "json",
				url: "/php/newsletter.php",
				data: "naam_txt="+$("#naam_txt").val()+"&achternaam_txt="+$("#achternaam_txt").val()+"&geslacht="+geslacht+"&taal="+taal+"&code="+$("#code2").val()+"&mail_txt="+$("#mail_txt").val()+"&language_id="+$("#nlLanguage").val()+"&bedrijf_txt="+$("#bedrijf_txt").val(),
				success: function(msg){
					alert(msg.errorDescr);
					$("#newsletter").css("display", "none");
				}
			});
			return false;
	});

});

//function for sliding the menu out
function menuOver(thisItem){
	if(thisItem.is('.up')){
		thisItem.attr('class', 'down');
	}else if(thisItem.is('.none')){
		thisItem.attr('class', 'down');
		$('div', thisItem).slideDown('fast', function(){
			if(thisItem.is('.up')){
				thisItem.attr('class', 'out');
				menuOut(thisItem);
			}else{
				thisItem.attr('class', 'out');
			}
		});
	}
}

//Function for sliding the menu back up
function menuOut(thisItem){
	if(thisItem.is('.down')){
		thisItem.attr('class', 'up');
	}else if(thisItem.is('.out')){
		thisItem.attr('class', 'up');
		$('div', thisItem).slideUp('fast', function(){
			if(thisItem.is('.down')){
				thisItem.attr('class', 'none');
				menuOver(thisItem);
			}else{
				thisItem.attr('class', 'none');
			}
		});
	}
}

function showKlanten(){
	if(counter >= $('.klanten img').length){
		counter = 0;
	}
	currentKlant.hide();
	currentKlant = klantLijst[counter];
	currentKlant.show();

	counter++;
}