// JavaScript Document

function CufonReplace() {
	Cufon.replace('h1', { fontFamily: 'Myriad Pro', hover: true } );
	Cufon.replace('h2', { fontFamily: 'Myriad Pro', hover: true } );
	Cufon.replace('#hoofdmenu a', { fontFamily: 'Myriad Pro', hover: true } );
	Cufon.replace('.kop', { fontFamily: 'Myriad Pro', hover: true } );
	
}

$(document).ready(function(){ 	

	$(document).pngFix(); 

	$("#inp_zoeken").blur();
	$("#inp_zoeken").focus(function(){  
		var input = $(this).attr("title")
		var text = $(this).val();
		if (text==input) { 
			$(this).val("");
		}
	});
	$("#inp_zoeken").blur(function(){ 
		var input = $(this).attr("title")
		var text = $(this).val();
		if (text=="") { 
			$(this).val(input);
		}								 
	});
	$("#inp_zoekenbutton").click(function(){
		var zoekveld 	= $("#inp_zoeken").val();	
		var input 		= $("#inp_zoeken").attr("title")
		if (zoekveld!="" && zoekveld!=input) { 
			$("#frm_zoeken").submit();
		} 
		return false;
    });
	
	$(".resultaat-rij li, .specials li").mouseover(function() {
		$(this).children("a").css("display","block");
	});
	
	$(".resultaat-rij li, .specials li").mouseout(function() {
		$(this).children("a").css("display","none");
	});	
	
	$(".resultaat-rij li, .specials li").click(function() { 
		var url = $(this).find("a").attr("href");
		document.location.href=url;
	});

	$(".hoofdblok").click(function() { 
		var url = $(this).find("a").attr("href");
		document.location.href=url;
	});	
	$(".hoofdblok, .specials li").mouseover(function() {
		$(this).find(".meerinfo").css("visibility","visible");
	});
	
	$(".hoofdblok").mouseout(function() {
		$(this).find(".meerinfo").css("visibility","hidden");
	});		
	
	
	$('ul.resultaat-rij, ul.specials').each(function(index) {
		var hoogte = 0;
		$(this).children().each(function(index2) { 
			if ($(this).height()>hoogte) { 
				hoogte = $(this).height();
			}
		});
		$(this).children().each(function(index2) { 
			$(this).height(hoogte)
		});
	});

// C1000 actie ---------------------------------------------------------------------------------------------------------
$("#inp_c1000_aantal").live("change",function() { 
	var aantal = parseInt($(this).val());
	$(".voucher input").val("");
	$(".voucher").hide(); 
	$(".voucher:lt("+aantal+")").show(); 
	$(".voucher-chk:lt("+aantal+")").val("1");
});
$(".voucherveld, .codeveld").keyup(function() { 
	var voucher 	= $(this).parent(".voucher").find(".voucherveld").val();
	var code		= $(this).parent(".voucher").find(".codeveld").val();
	var element 	= $(this).parent(".voucher").find(".status");
	var voucher_cl 	= $(this).parent(".voucher").find(".voucherveld");
	var code_cl		= $(this).parent(".voucher").find(".codeveld");

	$.post("/views/ajax/c1000status.php", { voucher: voucher, code: code }, 
	   function(data) { 
    	 	element.html(data);
   	});	
	$.post("/views/ajax/c1000validate.php", { voucher: voucher, code: code }, 
	   function(data) { 
	   		if (parseInt(data)==1) { 
	    	 	voucher_cl.removeClass("statusnok");
	    	 	code_cl.removeClass("statusnok");
			} else { 
	    	 	voucher_cl.addClass("statusnok");
	    	 	code_cl.addClass("statusnok");
			} 
   	});		
});

// Ajax pagina's inladen -------------------------------------------------------------------------------------------------
	$(".filter").click(function() {
		$.post("/views/ajax/productoverzicht.php", $("#frm-filters").serialize(), function(data) {
			  $('#overzicht').html(data);
		});
	});
	$(".sorteer").live('click', function() {
		var filter = $(this).text();
		var cat_id = $("#inp_cat_id").val();
		$.post("/views/ajax/productoverzicht.php", { sorteer: filter, inp_cat_id: cat_id  }, function(data) {
			  $('#overzicht').html(data);
		});
		return false;
	});	
	
	
// Fotofader productdetail ----------------------------------------------------------------------------------------
	function thumbOver() {
		$(".foto-groot").stop(true,true);
		var obj = $(".foto-groot").clone(true);
		obj.addClass("copy");
		var image = $(this).next(".thumb2groot").css("background-image");								
   
		obj.insertAfter(".foto-groot").hide().css({"background-image":image});
		$(".foto-groot").hide();
		obj.fadeIn(200);
	}
	function thumbOut() {
		$(".foto-groot").stop(true,true);
		$(".copy").remove();
		$(".foto-groot").fadeIn(200);
    }
	
	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: thumbOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, // number = milliseconds delay before onMouseOut    
		 out: thumbOut // function = onMouseOut callback (REQUIRED)    
	};7
		
	$(".thumbnail2").hoverIntent( config )
	
});
