function setComp(){

	if(Modernizr.borderradius == false){
	}
		
}

function setCookie(){
	//$('<div class="controllo" style="color:#fff;"> > xxx</div>').prependTo('body');
	
	$('.vm_btn').click(function() {
		
				alternaStile();
				//('.vm_btn').toggleClass(className, addOrRemove);
			
	});
		
		var count = 0;
		
		if($.cookie("versione")==false){
			$.cookie("versione", "video", { expires: 1 });
			count = 0;
		}else if($.cookie("versione")=='video'){
			count = 0;
			$('.vm_btn a').text('Mobile')
			$('head').append('<link rel="stylesheet" href="/skin/meeting11/css/vv.css" type="text/css" />');
			
		}else if($.cookie("versione")=='mobile'){
			count = 1;
			$('.vm_btn a').text('Verisione standard')
			$('head').append('<link rel="stylesheet" href="/skin/meeting11/css/vm.css" type="text/css" />');
			$('.galleria_fade').addClass('nuovo_blocco_fade').removeClass('galleria_fade');
			$('.galleria_outer').addClass('nuovo_blocco_linea').removeClass('galleria_outer');
			
		}
		
		
		function alternaStile(){
				
			count++;
			
			if(count==2){
			
				count = 0;	
			
			}
			
				if(count == 1){
				
					$.cookie("versione", "mobile", { expires: 1 });	
					$('.vm_btn a').text('Verisione standard')
					$('head').append('<link rel="stylesheet" href="/skin/meeting11/css/vm.css" type="text/css" />');	
					$('.galleria_fade').addClass('nuovo_blocco_fade').removeClass('galleria_fade');
				}
				else{
					$.cookie("versione", "video", { expires: 1 });
					$('.vm_btn a').text('Mobile')
					$('head').append('<link rel="stylesheet" href="/skin/meeting11/css/vv.css" type="text/css" />');
					$('.galleria_fade').addClass('galleria_fade').removeClass('nuovo_blocco_fade');
				}
			
			location.reload();	
		
		}
		
}

function linkBlocco(){

	$('#visual_interna h2 a').clone().prependTo('#visual_interna').css({
		'position':'absolute',
		'z-index':'100',
		'top':'0px',
		'left':'0px',
		'height':'100%',
		'width':'100%',
		'overflow':'hidden',
		'text-indent':'-99999px'
	});
}



function setStage(dove){
	
	$('.menu_orizzontale li ul li:last-child').css({'border':'none'});
		
	var contentHeight = $('#content').height();
	
	//Colonna Banner Laterali
	
	if(dove == 'home'){
		
		var bannerH = 167; //Comprensivo di border 1 px top 1px bottom
		$('#banner_circuito div').css('margin-bottom', spazioBanner(6, bannerH)+'px');
		$('#banner_circuito div:last').css({'margin-top':'-3px'});
		
		function spazioBanner(numBanner, altezza){
			return Math.ceil((contentHeight - (altezza * numBanner))/(numBanner-1))	
		}
		
	}
}

function leggiFeedContenuto(){
	
	  $.ajax({ type: "GET", url: "/skin/meeting11/sussidiario.xml", dataType: "xml",
	  
     
    success: function(xml) {
       
      $(xml).find('item').each(function() {
         
        var titolo = $(this).find('title').text();
        var link = $(this).find('link').text();
		var desc = $(this).find('description').text()
        
		var unisci = '<h5 class="pls ptl db clrr pbs fsm fwb fcb"><a href="'+link+'" title="'+titolo+'">'+titolo+'</a></h5><p class="pls fsm"><a href="'+link+'">'+desc+'</a></p>'
		 
        $(unisci).appendTo('.cont_rss_outer');
         
      });  leggiFeed();//AVVIA ANIMAZIONE QUANDO TUTTI I FEED SONO CARICATI!!!!   
    },
    error: function(request, error, tipo_errore) { alert(error+': '+ tipo_errore); }
  
  });	
 
}

function leggiFeed(){

		var altezzaRSS = $('.cont_rss_outer').height();
		var posINIT = 0;
		var finY = -altezzaRSS;
		var newY = 0;
		var a = 0;
		
		$('.cont_rss').clone().insertAfter($('.cont_rss'));
		
		function intervallo(){
			
			int = window.setInterval(function () {
					muovi_rss();
			},50);
		
		}
		
		intervallo()
		
		$('.cont_rss_outer').mouseover(function() {
  			clearInterval(int)
  		}).mouseout(function() {
  			intervallo()
  		});
		
		//var int = setInterval(muovi_rss,50)
		
		function muovi_rss() {
			
			if(newY == finY){
				newY = posINIT;
			}else{
			newY -= 1;
			}
			
		$('.cont_rss_outer').css('top',newY+'px');

		}	
}


function muoviNews(){

		var altezzaNews = $('.blocco_muovi').height();
		
		var posINIT = 0;
		var finY = -altezzaNews;
		var newY = 0;
		var a = 0;
		
		$('.cont_news').clone().insertAfter($('.cont_news'));
		
		function intervallo2(){
			
			int2 = window.setInterval(function () {
					muoviNEWsinterval();
			},50);
		
		}
		
		intervallo2()
		
		$('.blocco_muovi').mouseover(function() {
  			clearInterval(int2)
  		}).mouseout(function() {
  			intervallo2()
  		});
		
		//var int = setInterval(muovi_rss,50)
		
		function muoviNEWsinterval() {
			
			if(newY == finY){
				newY = posINIT;
			}else{
			newY -= 1;
			}
			
			$('.blocco_muovi').css('top',newY+'px');

		}	
}

function esiste(idPassato){
		if ($(idPassato).length)return true;
}

$(document).ready(function(){
			
	//ALTO CONTRASTO VERSIONE MOBILE
	setCookie();	
	
	setComp();
	leggiFeedContenuto();
	muoviNews();
	linkBlocco();
	banner_siti_esterni();
		if(esiste('#home')){
			setStage('home');
			
		}else{
			setStage('');
		} 
		
})

$(window).load( 

	function (){
		//menuNavigazione();
	/*	leggiFeedContenuto();
		
		if(esiste('#home')){
			setStage('home');
		}else{
			setStage('');
			
	} */
	//ELIMINA GALLERIA ANIMATA
});

$(window).resize(function() {
	//	spostaMenu();

});

function banner_siti_esterni() {
	$('div.txtarbn').each(function(index) {
		$(this).html($(this).html() + '<div class="txtarbntxt">Copia il codice riportato qui sotto</div><textarea rows="5" cols="50">'+ $(this).html() +'</textarea></div>');
		});
	}
