// starting the script on page load
$(document).ready(function(){
	imagePreview();
	
	// shipment address

	$(".shipmentaddress input[@value='no']").click(function () {
    	$("#shipping").css({ display:"block" });
    });
	$(".shipmentaddress input[@value='yes']").click(function () {
    	$("#shipping").css({ display:"none" });
    });
	
	//$(".btn-large-wrap").fadeTo(500, 0.3).fadeTo(500, 1.0).fadeTo(500, 0.3).fadeTo(500, 1.0).fadeTo(500, 0.3).fadeTo(500, 1.0).fadeTo(500, 0.3).fadeTo(500, 1.0);

	//fade(".btn-large-wrap");
	
	//setInterval ( "fadeBtn('.btn-large-wrap')" , 1000 );
	
	// Animated sprite button
	var i=1;
	function animate(){
		
	    var amount=(56/28); // 900px (+100px of a single frame) / 100ms
	    
	    
	    if(i>=amount){ i=1; } // animation done, reset it
	    if(o=document.getElementsByClassName('anibtn')){
	    	if (o[0] != null){
	    		if (o[0].style.backgroundPosition=='left top'){
	    			o[0].style.backgroundPosition='left bottom';
	    		}else{
	    			o[0].style.backgroundPosition='left top'
	    		}
	    	}
	    }
	    i++; // next animation frame in following animate() call.
	    window.setTimeout(animate,500);
	}
	window.setTimeout(animate,500);
	
	
	

});


function fadeBtn(obj) {
	var obj = $(obj);
	$(obj).fadeTo(500, 0.5)
	$(obj).fadeTo(500, 1.0)	
}


// image popup
this.imagePreview = function(){	
		
		xOffset = 20; 
		yOffset = 20;
		siteWidth = 940; 
		windowWidth = $(window).width();
		sidebar = (windowWidth - siteWidth) /2; 
		previewimagewidth = 400+xOffset;

	$("a.preview").hover(function(e){
	
		windowWidth = $(window).width();
		sidebar = (windowWidth - siteWidth) /2; 

		if(((e.pageX)+(previewimagewidth)) > windowWidth){ 
			x = e.pageX - (previewimagewidth + xOffset);
		}else {
			x = e.pageX + xOffset;
	  	}
		
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='photo-preview'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");								 
		$("#photo-preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(x) + "px")
			.fadeIn("fast");					
    },
	function(){
		this.title = this.t;	
		$("#photo-preview").remove();
    });	
	$("a.preview").mousemove(function(e){
	
		windowWidth = $(window).width();
		sidebar = (windowWidth - siteWidth) /2;
		previewimagewidth = $("#photo-preview").width()+xOffset 
		
		if(((e.pageX)+(previewimagewidth)) > windowWidth){ 
			x = e.pageX - (previewimagewidth + xOffset);
		}else {
			x = e.pageX + xOffset;
		}
		if(e.pageY >400){
			y = e.pageY -250; 
		}else{
			y = e.pageY - xOffset;
		} 
		$("#photo-preview")
			.css("top",(y) + "px")	
			.css("left",(x) + "px");
	});	
	

};

function siteoverlayopen(id){
	
	//$(".loginoverlay").fadeOut('fast');
	//$("#"+id).fadeIn('fast');
}
function siteoverlayclose(){
	$("#siteoverlaywrapper_ajax").fadeOut('fast');
	//$("#siteoverlaywrapper_ajax").css('display','none');
}
function siteoverlayopenajax(id){

	$("#siteoverlaywrapper_ajax").load("/nl/products/productoverlay/"+id,ajaxloaded); 
	//$("#siteoverlaywrapper_ajax").css('display','block');
}


function ajaxloaded(){
	$("#siteoverlaywrapper_ajax").fadeIn("fast");
	$("#productcarousel").jCarouselLite({
        btnNext: ".right",
        btnPrev: ".left",
        visible: 1,
        speed: 400
    });
  
}










