// JavaScript Document

$(document).ready(function()
{
	//alert("Dcument ready");
		
	// PREMI
	for (i=0; i<3; i++)
	{
		strTempImg		= "#premiFoto" + i + " img";
		strTempDescr	= "#premiDescription" + i;
		strTempArrow	= "#premiArrow" + i + " img";
		
		if(i==0)
		{
			$(strTempImg).attr("bStatus","open");
			strCurrentPremiImg = strTempImg;
		}
		else
		{
			$(strTempImg).attr("bStatus","close");
			$(strTempDescr).hide();
			$(strTempArrow).attr("src","img/stile/vuoto.png");	
		}
	
		$(strTempImg).attr("iValue",i);
		
		
		$(strTempImg).hover(
			function()
			{
				if($(this).attr("bStatus") == "close")
				{
					this.src = this.src.replace("_off","_on");
				}
			},
			function()
			{
				if($(this).attr("bStatus") == "close")
				{
					this.src = this.src.replace("_on","_off");
				}
			}
		);	
		
		
		$(strTempImg).click(function () 
		{	
			if($(this).attr("bStatus") == "close")
			{
				// RESETTO FOTO VECCHIA
				strOldImg = $(strCurrentPremiImg).attr("src");
				strNewImg = strOldImg.replace("_on","_off");
				$(strCurrentPremiImg).attr("src", strNewImg);
				$(strCurrentPremiImg).attr("bStatus","close");
				
				
				// NASCONDO DESCRIZIONE
				strTempDescr	= "#premiDescription" + $(strCurrentPremiImg).attr("iValue");
				$(strTempDescr).hide();

				// NASCONDO ARROW
				strTempArrow	= "#premiArrow" + $(strCurrentPremiImg).attr("iValue") + " img";
				$(strTempArrow).attr("src","img/stile/vuoto.png");	

				// AGGIORNO FOTO CLICCATA
				this.src = this.src.replace("_off","_on");
				$(this).attr("bStatus","open");

				// MOSTRO DESCRIZIONE
				strTempDescr	= "#premiDescription" + $(this).attr("iValue");
				$(strTempDescr).show();

				// MOSTRO ARROW
				strTempArrow	= "#premiArrow" + $(this).attr("iValue") + " img";
				$(strTempArrow).attr("src","img/stile/arrow.png");			
				

				// RESETTO VALORE strCurrentPremiImg
				strTempImg		= "#premiFoto" + $(this).attr("iValue") + " img";				
				strCurrentPremiImg = strTempImg;
			}
		});
		
	}	
	
	
	// VANTAGGI
	for (i=0; i<3; i++)
	{
		strTempImg		= "#vantaggiFoto" + i + " img";
		strTempDescr	= "#vantaggiDescription" + i;
		strTempArrow	= "#vantaggiArrow" + i + " img";
		
		if(i==0)
		{
			$(strTempImg).attr("bStatus","open");
			strCurrentVantaggiImg = strTempImg;
		}
		else
		{
			$(strTempImg).attr("bStatus","close");
			$(strTempDescr).hide();
			$(strTempArrow).attr("src","img/stile/vuoto.png");	
		}
	
		$(strTempImg).attr("iValue",i);
		
		
		$(strTempImg).hover(
			function()
			{
				if($(this).attr("bStatus") == "close")
				{
					this.src = this.src.replace("_off","_on");
				}
			},
			function()
			{
				if($(this).attr("bStatus") == "close")
				{
					this.src = this.src.replace("_on","_off");
				}
			}
		);	
		
		
		$(strTempImg).click(function () 
		{	
			if($(this).attr("bStatus") == "close")
			{
				// RESETTO FOTO VECCHIA
				strOldImg = $(strCurrentVantaggiImg).attr("src");
				strNewImg = strOldImg.replace("_on","_off");
				$(strCurrentVantaggiImg).attr("src", strNewImg);
				$(strCurrentVantaggiImg).attr("bStatus","close");
				
				
				// NASCONDO DESCRIZIONE
				strTempDescr	= "#vantaggiDescription" + $(strCurrentVantaggiImg).attr("iValue");
				$(strTempDescr).hide();

				// NASCONDO ARROW
				strTempArrow	= "#vantaggiArrow" + $(strCurrentVantaggiImg).attr("iValue") + " img";
				$(strTempArrow).attr("src","img/stile/vuoto.png");	

				// AGGIORNO FOTO CLICCATA
				this.src = this.src.replace("_off","_on");
				$(this).attr("bStatus","open");

				// MOSTRO DESCRIZIONE
				strTempDescr	= "#vantaggiDescription" + $(this).attr("iValue");
				$(strTempDescr).show();

				// MOSTRO ARROW
				strTempArrow	= "#vantaggiArrow" + $(this).attr("iValue") + " img";
				$(strTempArrow).attr("src","img/stile/arrow.png");			
				

				// RESETTO VALORE strCurrentVantaggiImg
				strTempImg		= "#vantaggiFoto" + $(this).attr("iValue") + " img";				
				strCurrentVantaggiImg = strTempImg;
			}
		});
		
	}	
	
	//alert("Fine Javascript");
	
});
