$(document).ready(function() {
	
	/*
		var selWH = $(window).height();
		var selWW = $(window).width();
		var selDH = $(document).height();
		var selDW = $(document).width();
		
		var EmbedCode = $("#selVideo").html();
		
		$("#selVideo").html("");
	
		$("#mask_bg").css({ width : selWW + "px", height : selDH + "px" }).fadeIn(250).fadeTo(250, 0.90);
		$("#mask_win")
			.css({
				width : '10px', 
				height : '10px',
				left : selWW/2 + 'px',
				top : selWH/2 + 'px'
				
			})
			.animate({
				width : '680px', 
				height : '500px',
				left : ((selWW/2) - 340) + 'px',
				top : ((selWH/2) - 250) + 'px'
				
			}, { easing : 'easeOutBounce', duration : 1000 , complete: function() {
				$("#mask_win_msg").fadeIn(500);
				}
			});
	
		$("#mask_bg").click(function() {
			$(this).fadeOut(100);
			$("#mask_win").fadeOut(100);
			$("#selVideo").html(EmbedCode);
		});
	*/
	
	

	/* COMUNICATI STAMPA */
	$("#cs_btn_territoriali").css({background: '#fff', color: '#333'});
	$("#cs_btn_nazionali").css({background: '#333', color: '#fff'});

	$("#cs_btn_nazionali").click(function() {
		$("#com_stampa_scroller").animate({ left : '0'}, 500);
		$("#cs_btn_territoriali").css({background: '#fff', color: '#333'});
		$("#cs_btn_nazionali").css({background: '#333', color: '#fff'});
	});

	$("#cs_btn_territoriali").click(function() {
		$("#com_stampa_scroller").animate({ left : '-210px'}, 500);
		$("#cs_btn_nazionali").css({background: '#fff', color: '#333'});
		$("#cs_btn_territoriali").css({background: '#333', color: '#fff'});
	});

	$(".cs_naz_btns span").click(function() {
		var pag = $(this).attr("cs_scroll");
		$(".cs_naz_btns span").css({ background : '#fff', color : '#333'});
		$(this).css({ background : '#b00', color : '#fff'});
		$("#cs_naz_vert_scroller").animate( {top : '-'+ (304*(pag-1)) + 'px'} ,500)
	});

	$(".cs_ter_btns span").click(function() {
		var pag = $(this).attr("cs_scroll");
		$(".cs_ter_btns span").css({ background : '#fff', color : '#333'});
		$(this).css({ background : '#b00', color : '#fff'});
		$("#cs_ter_vert_scroller").animate( {top : '-'+ (304*(pag-1)) + 'px'} ,500)
	});

/* ***********************
 Documenti territoriali
*********************** */

	$(".docterr_footer span").click(function() {
		var pag = $(this).attr("dt_scroll");
		$(".docterr_footer span").css({ background : '#fff', color : '#333'});
		$(this).css({ background : '#b00', color : '#fff'});
		$("#dt_vert_scroller").animate( {top : '-'+ (305*(pag-1)) + 'px'} ,500);
	});

	$(".docterr_footer span").click(function() {
		var pag = $(this).attr("dt_scroll");
		$(".docterr_footer span").css({ background : '#fff', color : '#333'});
		$(this).css({ background : '#b00', color : '#fff'});
		$("#dt_vert_scroller").animate( {top : '-'+ (305*(pag-1)) + 'px'} ,500);
	});





	/* NICHI VENDOLA FEED BOX*/
	
   
	$(".nv_feed_btn").click(function() {
		$(".nv_feed_btn").removeClass("nv_f_sel").addClass("nv_f_unsel");
		$(this).removeClass("nv_f_unsel").addClass("nv_f_sel");
		var nextTop = $(this).attr("n_feed");
		$("#nv_feed_scroller").animate({top: '-' + (nextTop * 195) + 'px'}, 500);
	});

	$(".nv_feed_btn").mouseover(function() {
		$(".nv_feed_btn").removeClass("nv_f_sel").addClass("nv_f_unsel");
		$(this).removeClass("nv_f_unsel").addClass("nv_f_sel");
	});
	


	$(".btn0").css({background: '#b00'});
	
	/*$(".appuntamenti").accordion({ animated: 'easeOutBounce' });	*/
	
	/*
	$("#sel_midbar .hMenu ul li").ahover({moveSpeed: 250, hoverEffect: function() {
        $(this).queue(arguments.callee);
    }});	
	*/
	var terScrollerCurTop = 0;
	
	var terBlockCount = $("#ter_scroller > .ter_cont_block").size();
	var terScrollerMaxTop = 190 * ( terBlockCount - 1 );
	var terScrollerMinTop = 0;
	
	$("#ter_btn_down").click(function() {
		if( terScrollerCurTop < terScrollerMaxTop ) {
			terScrollerCurTop += 280;
			$("#ter_scroller").animate({top: '-' + terScrollerCurTop + 'px'}, 1000);
		}
	});
	$("#ter_btn_up").click(function() {
		if( terScrollerCurTop > terScrollerMinTop ) {
			terScrollerCurTop -= 280;
			$("#ter_scroller").animate({top: '-' + terScrollerCurTop + 'px'}, 1000);
		}
	});

	var nobdayScrollerCurLeft = 0;
	
	var nobdayBlockCount = $("#spec_nobday_scroll > .spec_nobday_b").size();
	var nobdayScrollerMaxLeft = -1 * (220 * ( nobdayBlockCount - 1 ));
	var nobdayScrollerMinLeft = 0;
	
	$("#spec_nobday_right").click(function() {
		if( nobdayScrollerCurLeft > nobdayScrollerMaxLeft ) {
			nobdayScrollerCurLeft -= 220;
			$("#spec_nobday_scroll").animate({left: nobdayScrollerCurLeft + 'px'}, 1000);
		}
	});
	$("#spec_nobday_left").click(function() {
		if( nobdayScrollerCurLeft < nobdayScrollerMinLeft ) {
			nobdayScrollerCurLeft += 220;
			$("#spec_nobday_scroll").animate({left:  nobdayScrollerCurLeft + 'px'}, 1000);
		}
	});


	/*
	$("#doc_terr_header").click(function() {
		var curDocTerrBoxStatus = $("#doc_terr_box").attr("opened");
		if(curDocTerrBoxStatus == "open") {
			$("#doc_terr_box").hide(500);
			$("#doc_terr_footer").css({height: '1px'});
			$("#doc_terr_box").attr("opened","closed");
		} else {
			$("#doc_terr_box").show(500);
			$("#doc_terr_footer").css({height: '10px'});
			$("#doc_terr_box").attr("opened","open");
		}
	});
	*/
	var docterScrollerCurTop = 0;
	
	var docterBlockCount = $("#doc_terr_scroller > .doc_terr_item").size();
	var docterScrollerMaxTop = 32 * ( docterBlockCount - 5 );
	var docterScrollerMinTop = 0;
	
	$("#doc_terr_bott").click(function() {
		if( docterScrollerCurTop < docterScrollerMaxTop ) {
			docterScrollerCurTop += 32;
			$("#doc_terr_scroller").animate({top: '-' + docterScrollerCurTop + 'px'}, 500);
		}
	});
	$("#doc_terr_top").click(function() {
		if( docterScrollerCurTop > docterScrollerMinTop ) {
			docterScrollerCurTop -= 32;
			$("#doc_terr_scroller").animate({top: '-' + docterScrollerCurTop + 'px'}, 500);
		}
	});



	   $('.9aprile_2011').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.amm_2011').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );


	   $('.simbolo_button').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.doc_terr_button').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.materiali_button').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.photogallery_button').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.sltv_button').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.slforum_button').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.ter_btn').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );
	
	   $('.contattaci').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.aderisci').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.btn_kit_regionali').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );

	   $('.btn_kit_spot_vendola_regionali').hover(
            function() {
                this.src = this.src.replace( '_out', '_over' );
            },
            function() {
                this.src = this.src.replace( '_over', '_out' );
            }
        );


	/* BUTTONS_BANNER */
	$("#buttons_banner_box .button").mouseover(function() {
		$("#buttons_banner_box .button").animate({ opacity : 0.20 }, 500).dequeue();;
		$(this).animate({ opacity : 1.00 }, 500).dequeue();
	});

	$("#buttons_banner_box .button").mouseout(function() {
		$("#buttons_banner_box .button").stop().animate({ opacity : 1.00 }, 500).dequeue();
	});



	/* ************************************************
	   CODICE DEDICATO AGLI AUTOMATISMI DELLA VETRINA	
	 ************************************************ */
	var pause = true;
	var interval;
	var delay = 6000;

	function start() {
  		interval = setInterval( vetrinaScroll , delay );
	}

	function pauseResume() {
  		if(pause) {
    		clearInterval( interval );
    		pause = false;
  		} else {
    		interval = setInterval( vetrinaScroll , delay );
    		pause = true;
  		}
	}

	start();
	
	$(".vetrina").mouseover(function() {
		pauseResume();
	});
	
	$(".vetrina").mouseout(function() {
		pauseResume();
	});

	var vetrinaCount = 1;

	function vetrinaScroll() { 
	
		$(".vetrinaBox").animate({top: "-"+(vetrinaCount*240)+"px"}, {easing: 'easeOutBounce', duration: 1500});
		$("#titleScroller").animate({left: "-"+(vetrinaCount*603)+"px"}, {easing: 'easeOutBounce', duration: 1500});
		$(".button").css({background: '#444'});
		$(".btn" + vetrinaCount).css({background: '#db1e26'});
		vetrinaCount<2?vetrinaCount++:vetrinaCount=0;

	}

	$(".button").click(function() {
		var vetrinaTop = "-" + ($(this).attr("btn") * 240) + "px";
		var articleScrollerLeft = "-" + ($(this).attr("btn") * 603) + "px";
		$(".vetrinaBox").animate({top: vetrinaTop }, {easing: 'easeOutBounce', duration: 1500});
		$("#titleScroller").animate({left: articleScrollerLeft }, {easing: 'easeOutBounce', duration: 1500});
		
		$(".button").css({background: '#444'});
		$(this).css({background: '#b00'});
	});
	
	/* ****************************************************
	  FINE CODICE DEDICATO AGLI AUTOMATISMI DELLA VETRINA	
	 **************************************************** */


	/* ****************************************************
	***
	***   REGIONALI 2010 - BANNER INTERATTIVO
	***
	****************************************************** */
	
	var reg2010_t1 = setTimeout(function() {
		$("#reg2010_simbolo").animate( { top : '2px' } ,{ easing : 'easeOutBounce' , duration : 1000 },500);
	}, 1500);
	var reg2010_t2 = setTimeout(function() {
		$("#reg2010_txt1").animate( { top : '70px' } ,{ easing : 'easeOutBounce' , duration : 1000 },500);
	}, 2500);
	
	var reg2010_t3 = setTimeout(function() {
		$("#reg2010_txt2").animate( { top : '114px' } ,{ easing : 'easeOutBounce' , duration : 1000 },500);
	}, 3500);

	var reg2010_t4 = setTimeout(function() {
		$("#reg2010_secbtn").animate( { top : '12px' } ,{ easing : 'easeOutBounce' , duration : 1000 },500);
	}, 4500);
	

	
	
});





