// Skywall home page 9 programmi - jquery

$(document).ready(function(){

	
	var i=1;
	for (i=1;i<=9;i++) {	
		document.getElementById('slide_'+i).className = 'slide_0'+i;
		document.getElementById('slide_'+i).style.opacity = 0;		
		
		//fix per titoli troppo lunghi che vanno a capo.
		var lineheight = jQuery('#caption_'+i).css('line-height');
		lineheight = lineheight.substr(0,lineheight.length-2);//remove the 'px'
	    
		if (jQuery('#caption_'+i).height() > lineheight) {
			jQuery('#caption_'+i).removeClass();
			jQuery('#caption_'+i).addClass("caption2rows");
			
			/*
	      jQuery('#caption_'+i).css('top',(
			jQuery('#caption_'+i).position().top-lineheight)+'px'
		  );
		  */
	    }
		
	}	
	
	$("#slide_1").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top1, left: left1}, "normal", "linear", function () {
			$("#caption_1").animate({opacity: 'show'}, "normal");		
			}		
	);	
	
	$("#slide_2").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top2, left: left2}, "normal", "linear", function () {
			$("#caption_2").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	$("#slide_3").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top3, left: left3}, "normal", "linear", function () {
			$("#caption_3").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	$("#slide_4").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top4, left: left4}, "normal", "linear", function () {
			$("#caption_4").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	$("#slide_5").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top5, left: left5}, "normal", "linear", function () {
			$("#caption_5").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	$("#slide_6").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top6, left: left6}, "normal", "linear", function () {
			$("#caption_6").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	$("#slide_7").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top7, left: left7}, "normal", "linear", function () {
			$("#caption_7").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	$("#slide_8").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top8, left: left8}, "normal", "linear", function () {
			$("#caption_8").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	$("#slide_9").animate({width: smallWidth, height: smallHeight, opacity: 1, top: top9, left: left9}, "normal", "linear", function () {
			$("#caption_9").animate({opacity: 'show'}, "normal");		
			}		
	);
	
	
	$("#butt_1_tvmemoBox").click(function(){skyWallLoop("stop1","1");});
	$("#butt_1_recBox").click(function(){skyWallLoop("stop1","1");});
	$("#butt_1_addBox").click(function(){skyWallLoop("stop1","1");});
	
	
	$("#butt_2_tvmemoBox").click(function(){skyWallLoop("stop1","2");});
	$("#butt_2_recBox").click(function(){skyWallLoop("stop1","2");});
	$("#butt_2_addBox").click(function(){skyWallLoop("stop1","2");});
	
		
	$("#butt_3_tvmemoBox").click(function(){skyWallLoop("stop1","3");});
	$("#butt_3_recBox").click(function(){skyWallLoop("stop1","3");});
	$("#butt_3_addBox").click(function(){skyWallLoop("stop1","3");});
	
	
	$("#butt_4_tvmemoBox").click(function(){skyWallLoop("stop1","4");});
	$("#butt_4_recBox").click(function(){skyWallLoop("stop1","4");});
	$("#butt_4_addBox").click(function(){skyWallLoop("stop1","4");});
	
	
	$("#butt_5_tvmemoBox").click(function(){skyWallLoop("stop1","5");});
	$("#butt_5_recBox").click(function(){skyWallLoop("stop1","5");});
	$("#butt_5_addBox").click(function(){skyWallLoop("stop1","5");});
	
	
	$("#butt_6_tvmemoBox").click(function(){skyWallLoop("stop1","6");});
	$("#butt_6_recBox").click(function(){skyWallLoop("stop1","6");});
	$("#butt_6_addBox").click(function(){skyWallLoop("stop1","6");});
	
	
	$("#butt_7_tvmemoBox").click(function(){skyWallLoop("stop1","7");});
	$("#butt_7_recBox").click(function(){skyWallLoop("stop1","7");});
	$("#butt_7_addBox").click(function(){skyWallLoop("stop1","7");});
	
	
	$("#butt_8_tvmemoBox").click(function(){skyWallLoop("stop1","8");});
	$("#butt_8_recBox").click(function(){skyWallLoop("stop1","8");});
	$("#butt_8_addBox").click(function(){skyWallLoop("stop1","8");});
	
	
	$("#butt_9_tvmemoBox").click(function(){skyWallLoop("stop1","9");});
	$("#butt_9_recBox").click(function(){skyWallLoop("stop1","9");});
	$("#butt_9_addBox").click(function(){skyWallLoop("stop1","9");});
	
	
	$("#close_1").click(function(){skyWallLoop("stop2","1");});	
	$("#close_2").click(function(){skyWallLoop("stop2","2");});	
	$("#close_3").click(function(){skyWallLoop("stop2","3");});	
	$("#close_4").click(function(){skyWallLoop("stop2","4");});	
	$("#close_5").click(function(){skyWallLoop("stop2","5");});	
	$("#close_6").click(function(){skyWallLoop("stop2","6");});	
	$("#close_7").click(function(){skyWallLoop("stop2","7");});	
	$("#close_8").click(function(){skyWallLoop("stop2","8");});	
	$("#close_9").click(function(){skyWallLoop("stop2","9");});	
	
	skyWallLoopStart();
	assegna_click();
});	


function assegna_click(){
	$("#butt_1").click(function(){
		skyWallLoop("stop1","1");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);
	});	
	$("#butt_2").click(function(){
		skyWallLoop("stop1","2");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);
	});
	$("#butt_3").click(function(){
		skyWallLoop("stop1","3");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);		
	});	
	$("#butt_4").click(function(){
		skyWallLoop("stop1","4");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);	
	});
	
	$("#butt_5").click(function(){skyWallLoop("stop1","5");});
	
	$("#butt_6").click(function(){
		skyWallLoop("stop1","6");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);	
	});
	$("#butt_7").click(function(){
		skyWallLoop("stop1","7");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);		
	});
	$("#butt_8").click(function(){
		skyWallLoop("stop1","8");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);		
	});
	$("#butt_9").click(function(){
		skyWallLoop("stop1","9");
		var url = "http://guidatv.sky.it/guidatv/HP/carousel/"+this.title;
		nielsenRefresh(url);		
	});
	

}

	var twall;
	var t1o;
	
	var smallWidth 	= "185px";
	var smallHeight = "105px";	
	var bigWidth 	= "560px";
	var bigHeight 	= "320px";
	
	var top1 = "10px";
	var left1 = "22px";
	var top2 = "10px";
	var left2 = "221px";
	var top3 = "10px";
	var left3 = "422px";
	var top4 = "131px";
	var left4 = "22px";
	var top5 = "131px";
	var left5 = "221px";
	var top6 = "131px";
	var left6 = "422px";
	var top7 = "251px";
	var left7 = "22px";
	var top8 = "251px";
	var left8 = "221px";
	var top9 = "251px";
	var left9 = "422px";	   
	   
	
	function skyWallLoop(whichAction, whichSlide){		
		
		if (whichAction == "start"){		
			t1o = setTimeout(function(){openSlide("1");},0);
			t1c = setTimeout(function(){closeSlide("1");},2000);
			
			t2o = setTimeout(function(){openSlide("2");},3000);
			t2c = setTimeout(function(){closeSlide("2");},5000);
			
			t3o = setTimeout(function(){openSlide("3");},6000);
			t3c = setTimeout(function(){closeSlide("3");},8000);
			
			t4o = setTimeout(function(){openSlide("4");},9000);
			t4c = setTimeout(function(){closeSlide("4");},11000);
			
			t5o = setTimeout(function(){openSlide("5");},12000);
			t5c = setTimeout(function(){closeSlide("5");},14000);
			
			t6o = setTimeout(function(){openSlide("6");},15000);
			t6c = setTimeout(function(){closeSlide("6");},17000);
			
			t7o = setTimeout(function(){openSlide("7");},18000);
			t7c = setTimeout(function(){closeSlide("7");},20000);
			
			t8o = setTimeout(function(){openSlide("8");},21000);
			t8c = setTimeout(function(){closeSlide("8");},23000);
			


			t9o = setTimeout(function(){openSlide("9");},24000);
			t9c = setTimeout(function(){closeSlide("9");},26000);		
			
			twall = setTimeout(function(){skyWallLoop("start");},30000);		
		}
		
		if (whichAction == "stop1"){
			if(t1o != undefined){		
			clearTimeout(t1o);
			clearTimeout(t1c);
			clearTimeout(t2o);
			clearTimeout(t2c);
			clearTimeout(t3o);
			clearTimeout(t3c);
			clearTimeout(t4o);
			clearTimeout(t4c);
			clearTimeout(t5o);
			clearTimeout(t5c);
			clearTimeout(t6o);
			clearTimeout(t6c);
			clearTimeout(t7o);
			clearTimeout(t7c);
			clearTimeout(t8o);
			clearTimeout(t8c);
			clearTimeout(t9o);
			clearTimeout(t9c);
			}
			
			clearTimeout(twall);
			if(whichSlide == 0)
			{
				$('#butt_carousel').attr('href','#').unbind('click').click(carouselStart);
				$('#butt_carousel').removeClass('btn_visore_stop');
				$('#butt_carousel').addClass('btn_visore_play');
				$('#butt_carousel').html('&nbsp;&nbsp;&nbsp;Play');
				$('#butt_1,#butt_2,#butt_3,#butt_4,#butt_5,#butt_6,#butt_7,#butt_8,#butt_9').unbind('click');
			}
			else
				openSlide(whichSlide);
		}
		
		if (whichAction == "stop2"){			
			if(t1o != undefined){	
			clearTimeout(t1o);
			clearTimeout(t1c);
			clearTimeout(t2o);
			clearTimeout(t2c);
			clearTimeout(t3o);
			clearTimeout(t3c);
			clearTimeout(t4o);
			clearTimeout(t4c);
			clearTimeout(t5o);
			clearTimeout(t5c);
			clearTimeout(t6o);
			clearTimeout(t6c);
			clearTimeout(t7o);
			clearTimeout(t7c);
			clearTimeout(t8o);
			clearTimeout(t8c);
			clearTimeout(t9o);
			clearTimeout(t9c);
			}
			clearTimeout(twall);
			closeSlide(whichSlide);			
			twall = setTimeout(function(){skyWallLoop("start");},4000);
		}
	}
	
	function skyWallLoopStart(){	
		twall = setTimeout(function(){skyWallLoop("start");},4000);
	}

	/* funzione per aprire lo zoom */	
	function openSlide(whichOne) {		
		var myslideE1 	= "#slide_" + whichOne;		
		var mypanelE1 	= "#panel_" + whichOne;	
		var mybuttlE1 	= "#butt_" + whichOne;
		var slideE1 = $(myslideE1);
		var panelE1 = $(mypanelE1);
		
		copyEl = $(mybuttlE1 + "> span.copy");
		
		slideE1
	 		.css({"z-index":"99"})
      		.animate({width: bigWidth, height: bigHeight, opacity: 1, top: "23px", left: "16px", borderWidth: "3px"}, 500, "linear", function () {
				copyEl.animate({ opacity: 'show' }, 100, "linear");
						
			}		
		);		
	 	panelE1
			.animate({ opacity: 'show' }, 500, "linear");	
    }
	
	/* funzione per chiudere lo zoom */	
	function closeSlide(whichOne) {		
		var myslideE1 	= "#slide_" + whichOne;
		var mypanelE1 	= "#panel_" + whichOne;	
		var mybuttlE1 	= "#butt_" + whichOne;			
		var slideE1 = $(myslideE1);
		var panelE1 = $(mypanelE1);
		copyEl = $(mybuttlE1 + "> span.copy");
		var topE1 		= eval("top" + whichOne);
		var leftE1 		= eval("left" + whichOne);	
		
		slideE1
			.animate({width: smallWidth, height: smallHeight, opacity: 1, top: topE1, left: leftE1, borderWidth: "0px"}, 500, "linear", function () {slideE1.css({ "z-index":"1" });});	
	  	panelE1
			.animate({ opacity: 'hide' }, 500, "linear");
		copyEl
			.hide();	
    }
	
	function carouselStart(){
	  	$('#butt_carousel').attr('href','#').unbind('click').click(function(){skyWallLoop("stop1","0");});
			$('#butt_carousel').removeClass('btn_visore_play');
			$('#butt_carousel').addClass('btn_visore_stop');
			$('#butt_carousel').html('&nbsp;&nbsp;&nbsp;Stop');
			skyWallLoop("start");
			assegna_click();
	  }


