sendReqKerstPakket = {
    addElem: function () {
    	$('#kerstPakket').wrap('<div id="kerstHolder" style="position:relative; display:none; zoom:1"></div>');
    }
}

$(document).ready(function () {
	var windowLoc  = window.location;

	var margW = ($("#headH").width() - $("#headH ul").width()) / 2;
	$("#headH ul").css({'margin-left':margW});
	$("div.etaInfo h1").each(function (i){
		$(this).clone().prependTo("div#eta_"+(i+1)+" div.etaInfo").addClass('shadow');
	});
	$("div.etaInfo b").each(function (i){
		$(this).clone().prependTo("div#eta_"+(i+1)+" div.etaInfo").addClass('shadow');
	});
	$('div#footer div#footH h2,  .defH h2').append(' <img src="' + r + 'images/layout/footer/curls.gif" width="64" height="30"/>');

	
	$("a.readM").prepend('<img src="' + r + 'images/layout/btns/left_curl_norm.gif" class="etaLeft" width="12" height="23"/>');
	$("a.readM").append('<img src="' + r + 'images/layout/btns/right_curl_norm.gif" class="etaRight"  width="12" height="23"/>');
	
	
	$("div.eta").append('<ul id="etaMenu"></ul>');

	for (var i = 0; i < $("div.eta div.etaH").length; i++) {
		$("#etaMenu").append('<li id="et_'+(i + 1)+'"><a href="javascript: void(0);">'+(i + 1)+'</a></li>');
	}
	var widthDecl = 0;
	$("ul#etaMenu li").each(function () {widthDecl += $(this).width();})
	$("ul#etaMenu").css({'width':widthDecl+'px'});
	$("ul#etaMenu").prepend('<li class="etLeftNav"><img src="' + r + 'images/layout/btns/eta_curl_left.gif" width="17" height="23"/></li>').
	append('<li class="etRightNav"><img src="' + r + 'images/layout/btns/eta_cur_right.gif" width="13" height="23"/></li>');
	
	sendReqKerstPakket.addElem();
	
	var intPaus;
	var total = $("ul#etaMenu").children().length  - 2;
	var totalLi = total;
	var intNext = 1;
	var nameEtaBtn = 1;
	var stopSlide = false;
	
	$("ul#etaMenu").children().each(function (i){
		$(this).click(function (i){
			var idData = $(this).attr('id').replace('et_', '');
			n = idData -1;
			stopSlide = true;
			goN ();
		});
	});
	
	var n = 0;
	var nInt;
	var st = 4000;
	
	function goN () {
		st = 3000;
		n++;
		
		clearInterval(nInt);
		$("div.etaH").each(function (){
				$(this).stop();
				$(this).hide();
				$("#eta_"+(n - 1)).show();
		});
		
		$("#eta_"+(n - 1)).fadeOut('slow');
		if (stopSlide) {
			$("#eta_"+n).fadeIn('slow');
		}else{
			$("#eta_"+n).fadeIn('slow', reGen);
		}

		$("ul#etaMenu li").removeClass("curSlide");
		$("#et_"+n).addClass("curSlide");
		if (n == 1) {
				$("#eta_"+total).fadeOut('slow');
		}
		if (n > (total -1)) {
				n = 0;
		}
	}
	function reGen () {
		nInt = setInterval(goN, st);
	}
	goN ();
	
	
	var lengthHold = $("#hold_k").children().length * 850;
	var heightH = $("#hold_k").children().height() + 100;
	var arMenus = new Array();
	var iM = 0;
	$('.menuHold').each(function (){
		arMenus[iM] = $(this).attr('id');
		iM++;
	});
	
	if (heightH < 400) {
		heightH = 550;
	}
	var counterM = 0;
	var totalM = $("#hold_k").children().length;
	
	$("#hold_k").css({'width':lengthHold+'px'});
	$("#kHolder").css({'padding-bottom':heightH+'px', 'overflow':'hidden'});	
	$("#mHolder ul").prepend('<li class="leftK"></li>');
	$("#mHolder ul").append('<li class="rightK"></li>');
	$("#mHolder ul li a").each(function () {
		$(this).click(function () {
			var idPanels = Number($(this).attr('id').replace('b_', ''));
			counterM = idPanels;
			$("#kHolder").animate({paddingBottom:($("#"+arMenus[counterM]).height() + 150)+'px'}, 500);
			$("#mHolder ul li a").each(function () {
				$(this).removeClass('active');
			});
			$(this).addClass('active');
			var curVal = -(idPanels * 850);
			$("#hold_k").animate({left:curVal+'px'},1000);
		});
	});
	$("#mHolder ul .leftK").click(function () {
		
		if (counterM > 0) {
			counterM--;
			$("#kHolder").animate({paddingBottom:($("#"+arMenus[counterM]).height() + 150)+'px'}, 500);
			$("#mHolder ul li a").each(function () {
				$(this).removeClass('active');
			});
		$("#b_"+counterM).addClass('active');
			var curVal = -counterM * 850;
			$("#hold_k").animate({left:curVal+'px'},1000);
		}
	});
	$("#mHolder ul .rightK").click(function () {
		
			if (counterM < totalM - 1) {
			counterM++;
			$("#kHolder").animate({paddingBottom:($("#"+arMenus[counterM]).height() + 150)+'px'}, 500);
			$("#mHolder ul li a").each(function () {
				$(this).removeClass('active');
			});
		$("#b_"+counterM).addClass('active');
			var curVal = -counterM * 850;
			$("#hold_k").animate({left:curVal+'px'},1000);
		}
	});
	$(".fotoMenu").parent().prettyPhoto();
	$("#newsBrief").wrap('<div id="messHolder" style="position:relative; display:none; zoom:1"></div>');
	var getFormHeight  = 0;
	
	$("#newsBr, #newBr_v").click(function (){
		
		$('html, body').animate({scrollTop: 0}, 1000, function(){
			$('#newsBrief').show();
			$('#messHolder').slideDown(1000, function () {getFormHeight =  $("#newsBrief").parent().height();});
		});
		
	})
	$("#newsBrief a").click(function (){
		$("#messHolder").slideUp(1000);
	});
	
	$(".openKerstpakket").click(function (){
		$('html, body').animate({scrollTop: 0}, 1000, function(){
			$('#kerstPakket').show();
			$('#kerstHolder').slideDown(1000, function () {getFormHeight =  $("#kerstPakket").parent().height();});
		});
	});
	
	
	if ($('a[href*="#2"]')) {
		//alert("Gevonden");
		
	
		$('a[href*="#2"]').click(function () {
			window.location = $(this).attr('href'); 
			if ($(this).parent().parent().attr('id') == 'kaart_111') {
				window.location.reload();
			}
			//window.location.reload();
			return false;
		});
	}
	
	function slidePanel () {
		if (String(windowLoc).indexOf('#') > 0) {
			var win = String(windowLoc).split('#');
		
			var num = Number(win[1]);
			counterM = -(num - 1) ;
			var curVal = counterM * 850;
			$("#hold_k").animate({left:curVal+'px'},1000);
		
		}
		
	}

	slidePanel ();
	
	function valForm () {
	$("#newsBrief form").validateform({
			
				btn:'#nBtn', 
				radioMessage: "Nieuwsbrief ontvangen is verplicht",
				onComplete:function (){
					var htmlForm = $("#messHolder").html();
					
					$.post('/aj_scripts/sav_em.php', 
										{
										name : $('form #naam').val(),
										surname : $('form #achternaam').val(),
										gender : $("input[@name='geslacht']:checked").val(),
										company : $('form #nBedrijf').val(),
										email : $('form #email').val(),
										address : $('form #adres').val(),
										state : $('form #woonplaats').val(),
										postcode :$('form #postcode').val(),
										telephone : $('form #phone').val(),
										accepted : $("form #nCheck").val()
										}
						,
						function () {
							$("#newsBrief form").fadeOut('slow', function (){
									
									$("#newsBrief").html('<div id="messageN"style="height:'+Math.round(getFormHeight / 2)+'px; padding-top:'+(getFormHeight / 2)+'px; position:relative;">Bedankt uw informatie is bewaard! <a style="left:0px; top:'+Math.round((getFormHeight / 2) + 40)+'px" href="javascript: void(0);">sluiten</a></div>').hide().fadeIn('slow');
									setTimeout(hideMess,5000);
									$("#messageN a").click(function (){
											$("#messHolder").slideUp(1000, function () {
												$("#messHolder").html(htmlForm);
												$("#messHolder form input").each(function (){
														if ($(this).attr('type') == 'text')
														$(this).val('');
												})
												$("#messHolder form").find('.errorMess').remove();
												$('#nBtn').val('verzenden');
												valForm ();
											});
											
									});
							});
						}	
					)
				}
	})
	};
	valForm ();
	
	//----------------------------------------------------------------------
	//----------------------------------------------------------------------
	//-----------VALIDATE EN SEND KERSTPP
	//----------------------------------------------------------------------
	//----------------------------------------------------------------------
	
	function valKerstForm () {
	$("#kerstPakket form").validateform({
			
				btn:'#kerstBtn', 
				onComplete:function (){
					var htmlForm = $("#kerstHolder").html();
					
					$.post('/aj_scripts/send_kerst.php', 
										{
										aanhef : $('#kerstPakket form input:checked').val(),
										name : $('form #naam').val(),
										achternaam : $('form #achternaam').val(),
										bedrijfsnaam : $('form #kerstBedrijf').val(),
										email : $('form #email').val(),
										telephone : $('form #phone').val(),
										checkthis : $("form #checkthis").val()
										}
						,
						function () {
							$("#kerstPakket form").fadeOut('slow', function (){
									
									$("#kerstPakket").html('<div id="messageKerst"style="height:'+Math.round(getFormHeight / 2)+'px; padding-top:'+(getFormHeight / 2)+'px; position:relative; color:#FFF;">Bedankt, uw informatie is verstuurd! <a style="left:0px; top:'+Math.round((getFormHeight / 2) + 40)+'px" href="javascript: void(0);">sluiten</a></div>').hide().fadeIn('slow');
									setTimeout(hideMess,5000);
									$("#messageKerst a").click(function (){
											$("#kerstHolder").slideUp(1000, function () {
												$("#kerstHolder").html(htmlForm);
												$("#kerstHolder form input").each(function (){
														if ($(this).attr('type') == 'text')
														$(this).val('');
												})
												$("#kerstHolder form").find('.errorMess').remove();
												$('#kerstBtn').val('verzenden');
												valForm ();
											});
											
									});
							});
						}	
					)
				}
	})
	};
	valKerstForm ();
	
	
	
	function hideMess () {
		$("#messHolder").slideUp(1000);
	}
	
	/*----=====Regular function s======------*/
	function closeAllSlides () {
		$('#geo-bieden-holder').hide();
		$('#geo-shop-holder').hide();
		$('#messHolder').hide();
	}
	
	/*----=====ETALAGE======------*/
	$("#shop_1").slideDown(3000);
	$("#shop_1 .btnSluiten").click(function () {
		$("#shop_1").slideUp(1000);
	});
	
});



