//---------------------------------//
//JQUERY
//---------------------------------//

Cufon.replace('#header .lang', 			{ fontFamily: 'Century Gothic' });
Cufon.replace('#slider-home h1', 		{ fontFamily: 'Calibri' });
Cufon.replace('#slider-home h1 span', 	{ fontFamily: 'Calibri' });

Cufon.replace('#content h1', 		{ fontFamily: 'Century Gothic' });
Cufon.replace('#wrapper h1', 		{ fontFamily: 'Calibri' });
//Cufon.replace('.box div h1', 		{ fontFamily: 'Calibri' });
Cufon.replace('.box.download a', 		{ fontFamily: 'Calibri' });

Cufon.replace('#products-default a h2', { fontFamily: 'Calibri' });
Cufon.replace('#support h1', 			{ fontFamily: 'Calibri' });

function popUp(theURL,winName,features) { 
	window.open(theURL,winName,features);
}

function openUrl(theURL) { 
	window.location = theURL;
	return false;
}

$(document).ready(function() {	
	
	//---------------------------------
	//START - MAINMENU
	//---------------------------------	
	var enable_timeout = false;
	$("#menu .topnav li").each(function(){
		
		var subNavExist = $(this).find("ul.subnav").length;
		if(subNavExist == 1){ 
			//$(this).append("<span></span>"); 
			$(this).find("a").not("ul.subnav li a").css("padding-right","20px");
			$(this).find("a").not("ul.subnav li a").before("<span></span>");
		}
	});	
	
	
	$.disableActive = function() {
		$("#menu .topnav").find("li#active").attr("id", "active2");
	};
	
	$.enableActive = function() {
		$("#menu .topnav").find("li#active2").attr("id", "active");
	};	
	
	
	$("ul.topnav li").not("ul li ul li").mouseover(function() { 
		
		$dropdownMenu = $(this);
		$(this).addClass('active');	
		$.disableActive();		
		$("ul.subnav",this).css("display", "block"); 
		
		if(enable_timeout){
			clearTimeout(enable_timeout);
		}		
		
		$(this).hover(function() {
		}, function(){	
			$dropdownMenu.removeClass('active');
			
			if(enable_timeout){
				clearTimeout(enable_timeout);
			}			
			
			enable_timeout = setTimeout('$.enableActive();',1500);
			
			$(this).find("ul.subnav").css("display", "none"); 
		});
 
		}).hover(function() { 
			$(this).addClass("subhover"); 
		}, function(){	
			$(this).removeClass("subhover");
			
	});
    
	//---------------------------------
	//END - MAINMENU
	//---------------------------------		
	
	
	
	
	
	//*********************************
	//START - GLOBAL PAGE SETTINGS
	//*********************************	
	
		//start lightbox
		$(".screenshots a[data-rel^='screenshots']").prettyPhoto({animationSpeed:'slow',theme:'facebook'});
		$("a[data-rel^='youtube']").prettyPhoto({animationSpeed:'slow',theme:'facebook', social_tools: false, overlay_gallery: false, default_width:600, default_height:340});
	
	    //start pngFix
		$('div').pngFix();
			  
	    //start alt-title
	    $('.social').attr('title', function() {
	    	return this.alt;
	    });   		    
	         

		//check if submenu exist, if exist do nothing
		if (!$('#content-default div').hasClass('subnav')) {
			$('#content-default .left').css("width","750px");
		}
				
	    
		//START SEARCH HEADER
		var searchField = "#header input[name=search]";
		var searchValue = $(searchField).val();
	    $(searchField).focus(function(){
			if ($(this).val() == searchValue) {
				$(this).val("");
				$(this).css("color", "#000000");	
			}
		});
		$(searchField).blur(function(){
			if (!$(this).val()) {
				$(this).val(searchValue);
				$(this).css("color", "#b3b3b3");
			}
		});				
		//END SEARCH HEADER
     
		
		
		//START DROPDOWN PRODUCT HEADER		
		
			/*  function selectproduct movein animation */
			$.sp_moveIn = function() {
				$("#header .selectproduct_off").removeClass('selectproduct_off').addClass('selectproduct_on');
				$("#container #db_products").slideDown(100);
			};

			/*  function selectproduct moveout animation */
			$.sp_moveOut = function() {
				$("#header .selectproduct_on").removeClass('selectproduct_on').addClass('selectproduct_off');
				$("#container #db_products").slideUp(100);
			};	
		
		var sp_timeout = false;
		$("#header .selectproduct_off").click(
			function() {			
				if ($(this).hasClass('selectproduct_off')) { 
					$.sp_moveIn();		
				}
				else {
					$.sp_moveOut();	
				}	
			}		
		);
		
		//mouse-over
		$("#header .selectproduct_on, #header .selectproduct_off, #container #db_products").mouseover(
			function() {
				if(sp_timeout){
					clearTimeout(sp_timeout);
				}
			}
		);
		//mouse-out
		$("#header .selectproduct_on, #header .selectproduct_off, #container #db_products").mouseout(
			function() {
				sp_timeout = setTimeout('$.sp_moveOut();',500);
			}
		);	
		//END DROPDOWN PRODUCT HEADER		
		
		
		
		//START NEWSLETTER BOX
		var emailField = ".box input[name=email]";
		var emailValue = $(emailField).val();
				
	    $(emailField).focus(function(){
			if ($(this).val() == emailValue) {
				$(this).val("");
				$(this).css("color", "#000000");	
			}
		});
		$(emailField).blur(function(){
			if (!$(this).val()) {
				$(this).val(emailValue);
				$(this).css("color", "#898989");
			}
		});				
		//END NEWSLETTER BOX
		
		//START DISCOUNT BOX
		$(".discount #product .price span").each(
				function() {
					//start price value
					var value = $(this).html().split(",");
					$(this).html('<div class="num">'+value[0]+'</div><img class="dot" src="template/images/labels/img-6455-dot-red.gif" border="0" alt="" width="9" height="9"/><div class="dec">'+value[1]+'</div>');
					//end price value
				}	
					
		);
		Cufon.replace('.discount #product .price .num', { fontFamily: 'Myriad Pro' });
		Cufon.replace('.discount #product .price .dec', { fontFamily: 'Myriad Pro' });	
		
		$(".discount #product .price2 span").each(
				function() {
					//start price value
					var value = $(this).html().split(",");
					$(this).html('<div class="num">'+value[0]+'</div><div class="percent">%</div>');
					//end price value
				}	
					
		);
		Cufon.replace('.discount #product .price2 .num', { fontFamily: 'Myriad Pro' });
		Cufon.replace('.discount #product .price2 .percent', { fontFamily: 'Myriad Pro' });	
				
		
		//END DISCOUNT BOX
		

	//*********************************
	//END - GLOBAL PAGE SETTINGS
	//*********************************
    
		
		
		
    
	//*********************************
	//START PAGE HOME
	//*********************************	    
    
	    //start slideshow
	    slideShow();
		
		//start product-slider
	    $("#productslider-home #slider").codaSlider();		
		
	    
		//START SWITCHBOX PRODUCT HOME
		
		    /*  function switchbox product moveout animation */
			$.sb_moveOut = function() {
				$("#switch-home .view").slideUp(100);
				$("#switch-home .view div").hide();
				
				$("#switch-home ul li div").removeClass('switch_on').addClass('switch_off');
				$("#switch-home ul li div[data-rel^=book]").attr('class', 'active'); 		
			};	
		
		var sb_timeout = false;
		$("#switch-home ul li div").click(
			function() {			
				var rel= $(this).attr("data-rel");
				
				$("#switch-home .view div").hide();
					
				//clear .active
				$("#switch-home ul li div").attr('class',''); 
	
				
				if ($(this).hasClass('switch_on')) { 
					$("#switch-home .view").slideUp(100);
					$("#switch-home .view #" +rel).hide();
					$("#switch-home ul li div").removeClass('switch_on').addClass('switch_off');
				}
				else {
					$("#switch-home .view").slideDown(100);
					$("#switch-home .view #" +rel).show();
					$("#switch-home ul li div").removeClass('switch_on').addClass('switch_off');
					$(this).removeClass('switch_off').addClass('switch_on');
				}
		
	
				var select = true;
				if ($("#switch-home ul li div").hasClass('switch_on')) { var select = false; }
				if(select){
					$("#switch-home ul li div[data-rel^=book]").attr('class', 'active'); 
				}	
				
				
				
			}		
		);
		
		//mouse-over
		$("#switch-home .view, #switch-home ul li div").mouseover(
			function() {
				if(sp_timeout){
					clearTimeout(sp_timeout);
				}
			}
		);
		//mouse-out
		$("#switch-home .view").mouseout(
			function() {
				sp_timeout = setTimeout('$.sb_moveOut();',500);
			}
		);		
		//END SWITCHBOX PRODUCT HOME
	
		
	//*********************************
	//END PAGE HOME
	//*********************************	 
    

		
		
	
	//*********************************
	//START PAGE PRODUCTS
	//*********************************		
	
		//start products item/image marge
		var i = 0;
		$("#products-default .item, #products-default .clear").each(
				function() {			
					var className 	= $(this).attr('class'); 
					var imgObj	 	=  $(this).find('img').not("img#hd");
					var hdObj	 	=  $(this).find('img#hd');
					
					var spanObj	 	=  $(this).find('span').not(".price span");
					var imgWidth	=  imgObj.width();
					
					//image
					imgObj.addClass('product');
					spanObj.addClass('link');
					
					imgObj.css("margin-left","-"+(imgWidth/2)+"px");
					hdObj.css("right",((253-imgWidth)/2));
					
					//marge
					if(className == 'clear'){ if(i%2 == 0){ i=i+1; } }
					if(i%2 == 0){
						$(this).css("margin-right","13px");
					}
					i++;
					
				}		
		);
		//end products item marge
	
		//start price value
		$("#products-default .price span").each(
				function() {
						
					var value = $(this).html().split(",");
					$(this).html('<div class="num">'+value[0]+'</div><img class="dot" src="template/images/labels/img-5846-dot-red.gif" border="0" alt="" width="7" height="7"/><div class="dec">'+value[1]+'</div>');

				}	
					
		);
		Cufon.replace('#products-default .price .num', { fontFamily: 'Myriad Pro' });
		Cufon.replace('#products-default .price .dec', { fontFamily: 'Myriad Pro' });
		//end price value		
		
		
	//*********************************		
	//END PAGE PRODUCTS
	//*********************************		
	
		
		
	//*********************************		
	//START PAGE DOWNLOAD
	//*********************************	

		$("#page-download a.button").each(
			function() {
				
				var rel= $(this).attr("data-rel");
				
				$(this).attr("href",'http://'+window.location.hostname+"/nl/download.ajax.php?ajax=true&width=480&height=190&link="+rel);	
				$(this).prettyPhoto({animationSpeed:'slow',theme:'facebook',default_width:'480',default_height:'190', social_tools: false, overlay_gallery: false});	
			}	
		);		
				
		
		
	//*********************************		
	//END PAGE DOWNLOAD
	//*********************************	
		
		
	//*********************************		
	//START PAGE TIPUWVRIENDEN
	//*********************************			
		
		$("#page-tipuwvrienden a.tipbutton").each(
			function() {
				
				var rel= $(this).attr("data-rel");
				
				$(this).attr("href",'http://'+window.location.hostname+"/nl/tipuwvrienden.ajax.php?ajax=true&width=640&height=480&link="+rel);	
				$(this).prettyPhoto({animationSpeed:'slow',theme:'facebook',default_width:'640',default_height:'480', social_tools: false, overlay_gallery: false });
				
			}	
		);		
							
	//*********************************		
	//END PAGE TIPUWVRIENDEN
	//*********************************				
		
	
});  


function validateTip(id){
	
	var yourname 	= $(id).find("#yourname").val();
	var youremail 	= $(id).find("#youremail").val();
	var email1 		= $(id).find("#email1").val();
	var email2 		= $(id).find("#email2").val();
	var email3 		= $(id).find("#email3").val();
	
	var validate = true;
	
	if(yourname == ''){
	    alert("U heeft geen naam opgegeven!");
	    validate = false;		
	}
	else {
	
		if (!/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(youremail)) {
		    alert("Uw e-mailadres is onjuist!");
		    validate = false;
		}
		else {
	
			if (!/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(email1)) {
			    alert("Het opgegeven eerste e-mailadres is onjuist!");
			    validate = false;
			}
			else {
			
				if (!/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(email2)) {
				    alert("Het opgegeven tweede e-mailadres is onjuist!");
				    validate = false;
				}
				else {
				
					if (!/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(email3)) {
					    alert("Het opgegeven derde e-mailadres is onjuist!");
					    validate = false;
					}
					else {
						
						if(youremail == email1){  
							validate = false;
							alert("Het eerste e-mailadres komt overeen met uw e-mailadres.\nDit wordt niet toegestaan!"); 
						}
						else {
							if(youremail == email2){  
								validate = false; 
								alert("Het tweede e-mailadres komt overeen met uw e-mailadres.\nDit wordt niet toegestaan!"); 
							}
							else {
								if(youremail == email3){  
									validate = false; 
									alert("Het derde e-mailadres komt overeen met uw e-mailadres.\nDit wordt niet toegestaan!"); 
								}
								else {
									if(email1 == email2){  
										validate = false; 
										alert("Het eerste e-mailadres komt overeen met het tweede e-mailadres.\nDit wordt niet toegestaan!"); 
									}
									else {
										if(email1 == email3){  
											validate = false; 
											alert("Het eerste e-mailadres komt overeen met het derde e-mailadres.\nDit wordt niet toegestaan!"); 
										}
										else {
											if(email2 == email3){  
												validate = false; 
												alert("Het tweede e-mailadres komt overeen met het derde e-mailadres.\nDit wordt niet toegestaan!"); 
											}											
										}	
									}	
								}
							}
						}
					}
				}
			}
		}
	}
	
	
	return validate;
	
}


function getLines(id){
	return $(id).val().split("\n").length
}

function maxTextarea(field){
	
	$(field).limit('150','.characters');
	
	var allowedNumberOfLines = 3;
	if(getLines(field) > allowedNumberOfLines){
		modifiedText = $(field).val().split("\n").slice(0, allowedNumberOfLines);
		$(field).val(modifiedText.join("\n"));
	}	
	
};

