/*Funzioni Per Jquery*/
$(document).ready(
	function () {
		hoverElemento('');
		scrollaTo('');
		selectCampo('');
		imageRotatore();
		inviaFormW2l('');
	}
);

function inviaFormW2l(idElemento){
	$(".linkInviaW2l").click(function(){
		$("#moduloinfo").submit();
	});
}

function hoverElemento(idElemento){
	$(idElemento +".boxElemento").hover(function(){
		el=$(this)
		$(el).children(".hoverLayer").hide().css({ 
			backgroundColor: '#242424', opacity:'0.7' 
		}).fadeIn("fast",
		function(){});
		$(el).children(".pulsanti").show();
	},
	function(){
		$(this).children(".pulsanti").hide();
		$(this).children(".hoverLayer").fadeOut();
	});
}

function scrollaTo(idElemento){
	$(idElemento +".goto").click(function(){
		scrollWin("body","slow");								  
	});
	
	//Reindirizzo la pagina al punto corretto
	if(window.location.hash!=""){
		doveHash=window.location.hash.replace("#","") +"pag";
		scrollWin($("a[name='"+ doveHash +"']"),"slow");
	}
}

function selectCampo(idElemento){
	$(idElemento +" input[type='text'], "+ idElemento +" textarea").focus(function(){
		$(this).addClass("selezionato");
	}).blur(function(){
		$(this).removeClass("selezionato");
	});
}

function imageRotatore(){
	$(".paging").show();
	$(".paging a:first").addClass("active");
	
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	rotate= function(){
		triggerID=$(".paging a").index($(".paging a.active"))+1;
		if(triggerID==imageSum) triggerID=0;
		image_reelPosition = triggerID * imageWidth;
		
		$(".paging a").removeClass('active');
		$(".paging a").eq(triggerID).addClass('active');

		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
		t=setTimeout(rotate,3000);
	}
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearTimeout(t); //Stop the rotation
	}, function() {
		t=setTimeout(rotate,3000); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		clearTimeout(t);
		triggerID=$(".paging a").index($(this))-1;
		$(".paging a").removeClass('active');
		$(".paging a").eq(triggerID).addClass('active');

		rotate(); //Trigger rotation immediately

		return false; //Prevent browser jump to link anchor
	});
	
	var t=setTimeout(rotate,3000);
}
