$(window).load(function(){
		 //center the image with position absolute in the 'marche' section
	if($('#linee #main ul li a img').length){
		$('#linee #main ul li a img').each(function(){
			var imgWidth = $(this).width();
			var marginLeft = (180-imgWidth)/2;
			$(this).css({
				'margin-left':marginLeft
				})
			})
		
		}
	})
$(document).ready(function(){
	//lets center the site from the top
	if($('.container').length){
		setInterval('centerSite()',10);
		}
	//let's start the footer bg loop
	if($('#mainFooter').length){
		startBgAnimation();
	}
	//home page carousel
	if($('#homecarousel').length){
	 $('#homecarousel').jcarousel({
		 wrap:'circular',
		 //fix
		 auto: 5
		 //end fix
		 });
	 }
	 //center the image with position absolute in the 'marche' section
	if($('#linee #main ul li a img').length){
		$('#linee #main ul li a img').each(function(){
			var imgWidth = $(this).width();
			var marginLeft = (180-imgWidth)/2;
			$(this).css({
				'margin-left':marginLeft
				})
			})
		
		}
	//menu backgroun hover animation
	if($('#mainHeader nav ul li a').length){
		$("#mainHeader nav ul li:not(li:has(a.active))").append("<span></span>"); 

		$("#mainHeader nav ul li:not(li:has(a.active))").each(function() {
			var linkText = $(this).find("a").html(); 
			$(this).find("span").show().html(linkText);
		}); 
	
		$("#mainHeader nav ul li:not(li:has(a.active))").hover(function() {	
			$(this).find("a").stop().animate({
				marginTop: "0"
			}, 250);
		} , function() { //On hover out...
			$(this).find("a").stop().animate({
				marginTop: "-25"  
			}, 250);
		});

	}
	//product photogallery coverflip
	$('#productGallery img').length

	if($('#productGallery img').length){
		if ($('#productGallery img').length > 1){
			var productGallery =  new ImageFlow();
			 productGallery.init({ 
				ImageFlowID: 'productGallery',
				//fix
				//qua gli imposti la callback ogni qual volta un immagine viene cambiata
				onMove: function(imageid){
				$(".articleShow").hide();
				$("#"+imageid+"-article").show();
				}
			//end fix
		  });
		} else {
		$('#productGallery img').css({
			'visibility':'visible',
			'position':'relative',

			'margin': '0 0 0 180px'
			})
		$('#productGallery').css({
			'visibility':'visible'
			})
		}
	 }
});
//creating loop for the footer bg animation
function loopAnimateBg(){
	$('#mainFooter').css({'background-position': '0 top'});
	startBgAnimation();
}
function startBgAnimation(){
	$('#mainFooter').animate({'background-position': '-=995'},10000,'linear',function(){loopAnimateBg()});
}
function centerSite(){
	var offsetTop = ($(window).height()/2)-($('.container').height()/2);
	if (offsetTop > 10 ) {
	$('.container').css({marginTop:offsetTop});
	}

}
$(function(){
	$(".articleShow").hide();
	$(".articleShow:first").show();
})
