var sezcounter=1;
var newscounter=1;

function resetboxtas() {
	$("#box_tas_01").css("background-image","url(../images/box_home/tas_01_off.png)");
	$("#box_tas_02").css("background-image","url(../images/box_home/tas_02_off.png)");
	$("#box_tas_03").css("background-image","url(../images/box_home/tas_03_off.png)");
	$(".box_tas").css("line-height","40px");
	$(".box_tas").css("color","#FFF");
	$("#box_pul_01").css("display","block");		 
	$("#box_pul_02").css("display","block");		 
	$("#box_pul_03").css("display","block");		 

}
function selectbox(quale) {
		 $("#box_middle").css("background-image","url(../images/box_home/sfondo_box_" + quale + ".png)");
		 $("#box_tas_0" + quale).css("background-image","url(../images/box_home/tas_0" + quale + "_on.png)");
		 $("#box_tas_0" + quale).css("line-height","30px");
		 $("#box_tas_0" + quale).css("color","#1F5069");
		 $(".box_pul").css("background-image","url(../images/box_home/pul_0" + quale + "_off.png)");
		 $("#box_pul_01").css("background-image","url(../images/box_home/pul_0" + quale + "_on.png)");
		 $(".box_pul").addClass("bianco");
		 $("#box_pul_01").removeClass("bianco");
		 newscounter=1;
		 sezcounter=quale;
		 
		 
		 
		 //PULSANTI
		 $("#box_img_1").attr("src",BoxContentImg[sezcounter][1]);
		 $("#box_img_2").attr("src",BoxContentImg[sezcounter][2]);
		 $("#box_img_3").attr("src",BoxContentImg[sezcounter][3]);
		 $("#box_Titolo_1").html(BoxContentTitolo[sezcounter][1]);
		 $("#box_Titolo_2").html(BoxContentTitolo[sezcounter][2]);
		 $("#box_Titolo_3").html(BoxContentTitolo[sezcounter][3]);
		 $("#box_Testo_1").html(BoxContentTesto[sezcounter][1]);
		 $("#box_Testo_2").html(BoxContentTesto[sezcounter][2]);
		 $("#box_Testo_3").html(BoxContentTesto[sezcounter][3]);	 
		 
		 if ($("#box_Titolo_1").html() == "") {
			$("#box_pul_01").css("display","none");		 
		 }
		 if ($("#box_Titolo_2").html() == "") {
			$("#box_pul_02").css("display","none");		 
		 }
		 if ($("#box_Titolo_3").html() == "") {
			$("#box_pul_03").css("display","none");		 
		 }
		 
		 
		 //CONTENUTO
		 $("#news_data").html(BoxContentData[sezcounter][1])
		 $("#news_titolo").html(BoxContentTitolo[sezcounter][1])
		 $("#news_testo").html(BoxContentTesto[sezcounter][1]) 
		 $("#news_titolo").attr('href',BoxContentURL[sezcounter][1]);
		 $("#news_testo").attr('href',BoxContentURL[sezcounter][1]);
		 $("#box_notizia").css("background-image","url(" + BoxContentImg2[sezcounter][1] + ")");

		 
}

function selectnews(sez,news){
		$(".box_pul").css("background-image","url(../images/box_home/pul_0" + sezcounter + "_off.png)");
		$(".box_pul").addClass("bianco");
		$("#box_pul_0" + news).removeClass("bianco");
		
		$("#box_pul_0" + news).css("background-image","url(../images/box_home/pul_0" + sezcounter + "_on.png)");
		 $("#news_data").html(BoxContentData[sezcounter][news])
		 $("#news_titolo").html(BoxContentTitolo[sezcounter][news])
		 $("#news_titolo").attr('href',BoxContentURL[sezcounter][news]);
		 $("#news_testo").attr('href',BoxContentURL[sezcounter][news]);
		 $("#news_testo").html(BoxContentTesto[sezcounter][news]) 
		 $("#box_notizia").css("background-image","url(" + BoxContentImg2[sezcounter][news] + ")");

}


$(document).ready(function() {	   
	$("#box_tas_01").css("cursor","pointer");
	$("#box_tas_02").css("cursor","pointer");
	$("#box_tas_03").css("cursor","pointer");
	$("#box_pul_01").css("cursor","pointer");
	$("#box_pul_02").css("cursor","pointer");
	$("#box_pul_03").css("cursor","pointer");
	
	selectbox('1');
	$("#box_tas_01").click( function() {
		//alert($(this).attr("id"));							 
		 resetboxtas();
		 selectbox('1');
    });
	$("#box_tas_02").click( function() {
		 resetboxtas();
		 selectbox('2');
    });	
		$("#box_tas_03").click( function() {
		 resetboxtas();
		 selectbox('3');
    });	
		
	$("#box_pul_01").click( function() {
		//alert($(this).attr("id"));							 
		 selectnews('0','1');
    });		
	$("#box_pul_02").click( function() {
		//alert($(this).attr("id"));							 
		 selectnews('0','2');
    });		
	$("#box_pul_03").click( function() {
		//alert($(this).attr("id"));							 
		 selectnews('0','3');
    });			
		
		
	$("#box_toggle_button").css("cursor","pointer");	
	$("#box_toggle_button").click( function() {
			if ($("#box_notizia_inside").width() < 200) {					
				$("#box_notizia_inside").animate({width: '+=180px'}, 1000);
				$("#box_toggle_button").attr('src','images/box_home/chiudi.png');
			} else {
				$("#box_notizia_inside").animate({width: '-=180px'}, 1000);	
				$("#box_toggle_button").attr('src','images/box_home/apri.png');
			}
    });	
		
});
