var tmp=get_cookie ("bodytextsize");
if (tmp)
{
	var bodytextsize=tmp-0;
}
else
{
	var bodytextsize=70;
}

//function

function closePopupMappa(){
	jQuery('.popupmappa').remove();
}

jQuery.noConflict();

jQuery(document).ready(function(){

/* Layer Energia - Start */
var imgLayerEnergiaTimeout=10000;
var imgLayerEnergiaCookieTimeout=60*60*1000;	
imgLayerEnergiaCookie= readCookie("imgLayerEnergiaCookieName");
if 	((imgLayerEnergiaCookie!='on') && imgLayerEnergia!=''){
	var dateExpire = new Date();
	dateExpire.setTime(dateExpire.getTime()+(imgLayerEnergiaCookieTimeout));
	var expires = "; expires="+dateExpire.toGMTString();
	document.cookie = "imgLayerEnergiaCookieName"+"="+"on"+expires+"; path=/";
	var imgLayerEnergiaHeight=jQuery('body').height();
	var imgLayerEnergiaWidth=jQuery('body').width();
	jQuery('body').append('<div id="imgLayerEnergiaBk" style=" height: '+imgLayerEnergiaHeight+'px; width: '+imgLayerEnergiaWidth+'px; text-align: center; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 998; background-color: #ffffff; display: none;  "></div><div id="imgLayerEnergia" style=" height: '+imgLayerEnergiaHeight+'px; width: '+imgLayerEnergiaWidth+'px; text-align: center; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 999; background-color: transparent; display: none;  "><img src="'+imgLayerEnergia+'" style="display: block;margin: 129px auto 0 auto;" /></div>');
	if (jQuery('#imgLayerEnergia').length>0){
		jQuery('#imgLayerEnergiaBk').show();
		jQuery('#imgLayerEnergia img').css({'cursor':'pointer'});
		jQuery('#imgLayerEnergia').fadeIn(1000);
		jQuery('#imgLayerEnergia').click(function(){
			jQuery('#imgLayerEnergia').fadeOut(1000);
			if (jQuery('#imgLayerEnergia').length>0){
				jQuery('#imgLayerEnergiaBk').hide();
				jQuery('#imgLayerEnergia').fadeOut(1000);
				setTimeout(function(){
					if (jQuery('#imgLayerEnergia').length>0){			
						jQuery('#imgLayerEnergia').remove();
					}
					if (jQuery('#imgLayerEnergiaBk').length>0){			
						jQuery('#imgLayerEnergiaBk').remove();
					}
				}, 1000);
			}
		});
	}
	setTimeout(function(){
		if (jQuery('#imgLayerEnergia').length>0){
			jQuery('#imgLayerEnergiaBk').hide();
			jQuery('#imgLayerEnergia').fadeOut(1000);
			setTimeout(function(){
				if (jQuery('#imgLayerEnergia').length>0){			
					jQuery('#imgLayerEnergia').remove();
				}
				if (jQuery('#imgLayerEnergiaBk').length>0){			
					jQuery('#imgLayerEnergiaBk').remove();
				}
			}, 1000);
		}
	}, imgLayerEnergiaTimeout);
	
}
/* Layer Energia - End */

/* box_banner_rotazione */
	if(jQuery('.box_banner_rotazione').length>0)
	{
		if (jQuery('.box_banner_rotazione .banner img:eq(0)').height())
		{
			jQuery('.box_banner_rotazione').height(jQuery('.box_banner_rotazione .banner img:eq(0)').height());
		}
	}
/* Tracking download files */	
	jQuery('.content-view-embed .class-file a').click(function(){
		/*		_gaq.push(['_trackPageview','/home'+jQuery(this).attr('href')]);  Tracking Pageview*/
				_gaq.push(['_trackEvent','Download Files',jQuery(this).attr('href')]); /* Tracking eventi Eventi */ 
				_gaq.push(['_link',jQuery(this).attr('href')]); /* Tracking Link */
				return true;
			});
	
/* Tracking click in home page */	
	jQuery('.current_node_id_2 #wrapper2 a').click(function(){
/*		_gaq.push(['_trackPageview','/home'+jQuery(this).attr('href')]);  Tracking Pageview*/
		_gaq.push(['_trackEvent','Click in home',jQuery(this).attr('href')]); /* Tracking eventi Eventi */ 
/*		_gaq.push(['_link','/home'+jQuery(this).attr('href')]); Tracking Link */
		return true;
	});
	
	
/* Gestione collocazioni - START */
	/* jQuery('.admin_collocazioni strong').replaceWith('<a  class="toggle_tendina" href="#"><strong>Collocazioni</strong></a>');
	jQuery('.admin_collocazioni ul').addClass('nascosto');
	jQuery('.admin_collocazioni a.toggle_tendina').click(function(){
		if (jQuery('.admin_collocazioni ul').hasClass('nascosto'))
			jQuery('.admin_collocazioni ul').removeClass('nascosto');
		else
			jQuery('.admin_collocazioni ul').addClass('nascosto');
		return false;
	});
	*/
	if (jQuery('.window_collocazioni').length>0)
	{
		jQuery('#odwt-icon-collocazioni').click(function(){
			if (jQuery('.window_collocazioni').hasClass('nascosto'))
				jQuery('.window_collocazioni').removeClass('nascosto');
			else
				jQuery('.window_collocazioni').addClass('nascosto');
			return false;
		});
	}
	else
	{
		jQuery('#odwt-icon-collocazioni').hide();
	}
/* Gestione collocazioni - END */
	
	// datepicker
	jQuery('.datepicker').datepicker();
	
	// Ricerca interna folder_search_text
	jQuery('.folder_news_search form').submit(function(){
		var searchword=jQuery(this).find('input[name=Word]:eq(0)').attr('value');
		var searchmonth=jQuery(this).find('select[name=Month]:eq(0)').attr('value');
		var searchyear=jQuery(this).find('select[name=Year]:eq(0)').attr('value');
		var url=jQuery(this).find('input[name=folder_search_url]:eq(0)').attr('value')+'/(word)/'+escape(jQuery.trim(searchword))+'/(month)/'+escape(jQuery.trim(searchmonth))+'/(year)/'+escape(jQuery.trim(searchyear));
		window.location.href=url;
		return false;
	});

	// streaming
 	jQuery('.streaming a').click(function(){
 		jQuery('meta[http-equiv=refresh]').remove();
 		_gaq.push(['_trackPageview',jQuery(this).attr('href')]);
		_gaq.push(['_trackEvent','Click on streaming',jQuery(this).attr('href')]); /* Tracking eventi Eventi */ 
		/*		_gaq.push(['_link','/home'+jQuery(this).attr('href')]); Tracking Link */
		if ((jQuery.browser.msie && jQuery.browser.version<'8.0') || jQuery.browser.opera)
		{
			var topVideo=Math.floor(jQuery(this).offset().top)-10;
		}
		else
		{
			var topVideo=Math.floor(jQuery(this).position().top)-100;
		}
 		var params=jQuery(this).next('.str_param');
 		var str_PLAYER=params.children('.str_PLAYER').text();
 		var str_PLAYERSWF=params.children('.str_PLAYERSWF').text();
 		var str_URL=params.children('.str_URL').html();
 		var str_IMGURL=params.children('.str_IMGURL').html();
 		var str_height=params.children('.str_height').html();
 		var str_width=params.children('.str_width').html(); 
 		var str_AUTOPLAY=params.children('.str_AUTOPLAY').text();
 		var str_MOSTRAIMG=params.children('.str_MOSTRAIMG').text()-0;
 		
 		/*var str_width=640;
 		var str_height=550;*/
 		var str_title=params.children('.str_title').html();
 		var str_intro=params.children('.str_intro').html();
 		var box_width=parseInt(str_width)+20;
 		var box_height=parseInt(str_height)+85;
 		var win_width=jQuery(window).width();
 		var win_height=jQuery(document).height();
 		var win_margin=(jQuery(window).height()-box_height)/2;
 		 		
 		var code='';

 		code+='<div class="zooming_dlg"  style="width: '+win_width+'px; height: '+win_height+'px; position: absolute; top: 0px; left: 0px; z-index: 995; overflow: hidden;" >';
 		code+=' <div class="zooming_bgi"  style="width: '+win_width+'px; height: '+win_height+'px; position: absolute; top: 0px; left: 0px; z-index: 996; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5; background-color: #000000; ">&nbsp;</div>';
 		/* code+=' <div class="zooming_img"  style="width: '+win_width+'px; height: '+win_height+'px; position: absolute; top:'+win_margin+'px; left:0px; z-index: 9999991; display: block; background-color: transparent; text-align:center;" >'; */
 		code+=' <div class="zooming_img"  style="width: '+win_width+'px; height: '+win_height+'px; position: absolute; top:'+topVideo+'px; left:0px; z-index: 997; display: block; background-color: transparent; text-align:center;" >';
 		code+='  <div class="zoomed_image" style="width: '+box_width+'px; height: '+box_height+'px; position: relative; background: none repeat scroll 0% 0% rgb(255, 255, 255); border: 1px solid rgb(102, 102, 102); margin:0 auto; text-align:left;">';			
 		code+='   <div class="close_win" style="z-index: 999;position: absolute; top: -15px; right: -15px; width:32px;height:32px;cursor:pointer;">&nbsp;</div>';			
 		code+='   <div style="padding: 10px 10px 50px;">';	
 		code+='    <div class="broadcast">';
 		code+='     <div class="broadcast_header" style="height:65px;padding-left:55px;">';
 		code+='      <div class="broadcast_title" style="font-size:1.5em;font-weight:bold;text-align:left;margin-bottom:2px;">'+str_title+'</div>';
 		code+='      <div class="broadcast_intro" style="font-size:1.3em;font-weight:bold;text-align:left;">'+str_intro+'</div>';
 		code+='     </div>';

 		code+='     <div style="width:'+str_width+'px; height:'+str_height+'px; overflow: hidden;';
 		if(str_MOSTRAIMG && str_IMGURL){
 			code+='     background-image:url('+str_IMGURL+'); background-repeat: no-repeat; background-position: center;';	
 		}
 		code+='">';
 		
 		if(str_PLAYER=='jwplayer'){
 			code+='<div width="'+str_width+'" height="'+str_height+'" id="'+str_PLAYER+'_911"></div>';
 		}
 		else if(str_PLAYER=='flowplayer'){
 		/* flowplayer - START */
 		code+='     <object width="'+str_width+'" height="'+str_height+'" id="_player" name="_player"';
 		code+='     data="http://releases.flowplayer.org/swf/flowplayer-3.2.5.swf"';
 		code+='     type="application/x-shockwave-flash"><param name="movie"';			 		
 		code+='     value="http://releases.flowplayer.org/swf/flowplayer-3.2.5.swf" />';			 		
 		code+='     <param name="allowfullscreen" value="true" />';			 		
 		code+='     <param name="allowscriptaccess" value="always" />';			 		
 		code+='     <param name="wmode" value="transparent" />';
		code+='     <param name="flashvars" value=\'config={"playlist":[';
 		if(str_MOSTRAIMG && str_IMGURL){
 			code+='     {"url":"'+str_IMGURL+'","scaling":"orig"},';
 		}
		code+='     {"url":"'+str_URL+'","autoPlay":'+str_AUTOPLAY+',"autobuffering":true}]}\' />';				
/*		code+='     <param name="flashvars" value=\'config={"clip":{"autoPlay":false,"url":"'+str_URL+'"},"playlist":[{"url":"'+str_URL+'"}]}\' />';*/				
 		code+='     </object>';
		
		/* flowplayer - END */
 		}
 		else{
 		/* WMV Loro Codice - START */
 		code+='     <object id="WinMediaPlayer" style="" codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" type="application/x-oleobject" standby="Loading Microsoft Windows Media Player components..." width="'+str_width+'" height="'+str_height+'" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" viewastext>';
 		code+='     <param name="URL" value="'+str_URL+'" />';
 		code+='     <param name="stretchToFit" value="true" />';
 		code+='     <param name="captioningID" value="caption" />';
 		code+='     <param name="uiMode" value="none" />';
 		code+='     <param name="EnableFullScreenControls" value="false" />';
		code+='     <embed id="WinMediaEmbed" ';
		code+='     type="application/x-ms-wmp"'; 
		code+='     pluginspage="http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx/"'; 
		code+='     filename="'+str_URL+'" ';
		code+='     src="'+str_URL+'" ';
		code+='     uiMode="none" ';
		code+='     stretchToFit="true"'; 
		code+='     Name="WinMedia" ';
		code+='     ShowControls="0"'; 
		code+='     EnableFullScreenControls="false"'; 
		code+='     width="'+str_width+'" ';
		code+='     height="'+str_height+'" >';
		code+='     </embed> ';
		code+='     </object>'; 		
 		/* Loro Codice - END */
 		}
 		code+='    </div>';

		code+='    </div>';
 		code+='   </div>';
 		code+='  </div>';
 		code+=' </div>';
 		code+='</div>';
 	 	jQuery('body').append(code);
 	 	if(str_PLAYER=='jwplayer'){
 	 		if(str_MOSTRAIMG && str_IMGURL){
 	 			jwplayer(str_PLAYER+'_911').setup({ 
 	 												'image':str_IMGURL,
 	 												'flashplayer': str_PLAYERSWF, 
 	 												'autostart':str_AUTOPLAY, 
 	 												'file': 'live', 
 	 												'streamer': str_URL, 
 	 												'height': str_height, 
 	 												'width': str_width 
 	 											});
 	 		}
 	 		else{
 	 			jwplayer(str_PLAYER+'_911').setup({ 'flashplayer': str_PLAYERSWF, 'autostart':str_AUTOPLAY, 'file': 'live', 'streamer': str_URL, 'height': str_height, 'width': str_width });
 	 		}
 	 	}
	 	jQuery('.close_win').click(function(){
	 		jQuery('.zooming_dlg').remove();
	 	});
 	 	return false;
 	});
	
	jQuery('.jclock').jclock();
	
//   	if (jQuery('.folder_select').length>0) {
		jQuery('.folder_select').styleSelect({styleClass:'selectDark',speed:'slow'});
		jQuery('.jfolder .defaultbutton').hide();
		jQuery('.jfolder li').each(function(){
			jQuery(this).click(function(){
				jQuery(this).parents('.jfolder').find('.defaultbutton').trigger('click');				
				return false;
			});
		});
//	}
	
	//tendina province folder
	if (jQuery('.cambia_provincia').length>0) {
		jQuery('.cambia_provincia a').click(function(){
			jQuery.cookie('provincia_cna_scelta', null, { path: '/', expires: 10 });
		});
	}
	
	if (jQuery('#lista_province').length>0) {
		jQuery('#lista_province').styleSelect({styleClass:'selectDark',speed:'slow'});
		
		if (jQuery('.reset_provincia_cna_scelta').html()!='1')
		{
			var biscottino = jQuery.cookie('provincia_cna_scelta');
			if (biscottino) 
			{
				jQuery('.corpo_ricerca_province').hide();
				var selezionato = jQuery(".jprovincia li[id$='/"+biscottino+"']");
				if (selezionato.length > 0) 
				{
					selezionato.trigger('click');
					jQuery('.jprovincia .defaultbutton').trigger('click');
				}
			}
		}
		
		jQuery('.jprovincia .defaultbutton').hide();
		
		jQuery('.jprovincia li').each(function(){
			jQuery(this).click(function(){
				//location.href = jQuery(this).attr('id');
				var date = new Date();
				date.setTime(date.getTime() + (60 * 24 * 60 * 60 * 1000));
				var arrtmp=jQuery(this).attr('id').split('/');
				var prov_node_id=arrtmp.pop()
				// jQuery.cookie('provincia_cna_scelta', jQuery(this).attr('id'), { path: '/', expires: date });
				jQuery.cookie('provincia_cna_scelta', prov_node_id, { path: '/', expires: date });
				jQuery('.jprovincia .defaultbutton').trigger('click');				
				return false;
			});
		});
	}
	
	if (jQuery('.provincia_bottom_right>img').length>0) {
		jQuery('.provincia_bottom_right>img').show();
		var imgmap = jQuery('.provincia_bottom_right>img');
		imgmap.css({cursor:'pointer'});
		imgmap.click(function(){
			var wid = jQuery(window).width();
			var hei = jQuery(document).height();
			jQuery('body').append('<div class="popupmappa" id="back_cover" style="z-index:9996;background:black;opacity:0.3;filter:alpha(opacity=30);position:absolute;top:0;left:0;width:'+wid+'px;height:'+hei+'px;"></div>');
			
			var left = (wid-550)/2;
			jQuery('body').append('<div class="popupmappa" id="popup_map" style="z-index:9997;position:absolute;top:200px;left:'+left+'px;width:550px;height:505px;"><img src="/extension/ext_cna/design/des_cna/images/popup_mappa.png" /></div>');
			
			jQuery('body').append('<div class="popupmappa" id="popup_map_text" style="z-index:9998;position:absolute;top:240px;left:'+(left+40)+'px;width:470px;height:425px;text-align:left;"></div>');
			jQuery('#popup_map_text').append(jQuery('.contenitore_provincia_gmap').clone(true));
			jQuery('#popup_map_text .mappa_popup').attr('id','mappa_popup_id');
						
			jQuery('body').append('<div class="popupmappa" id="popup_map_close" style="z-index:9999;position:absolute;top:219px;left:'+(left+504)+'px;width:25px;height:25px;background:white;opacity:0.01;filter:alpha(opacity=1);cursor:pointer;"></div>');
			var mapcoords = ''+jQuery('#mappa_popup_id').html();
			var coords = mapcoords.split(',');
			if (GBrowserIsCompatible()) {
		        var map = new GMap2(document.getElementById("mappa_popup_id"));
                map.setCenter(new GLatLng(coords[0],coords[1]), 13);
                var marker = new GMarker(new GLatLng(coords[0],coords[1]));
                map.addOverlay(marker);
		    }
			
			// il fix PNG per IE6 va qui, o dopo il caricamento immagini... (fixare la img in #back_cover)
			//jQuery('#back_cover img').pngFix();
			// fix PNG per IE6
			if (jQuery.browser.msie && jQuery.browser.version=='6.0') {
				jQuery("img[src$=png]").pngfix();
				//jQuery(".jq_box_selezionato").pngfix({sizingMethod:'scale'});
			}
			// fix PNG per IE6 [end]
			
			jQuery('#popup_map_close').click(function(){
				jQuery(window).unbind('resize',closePopupMappa);
				if (jQuery.browser.msie) {
					jQuery(window).unbind('scroll',closePopupMappa);
				}
				else {
					jQuery(document).unbind('scroll',closePopupMappa);
				}
				closePopupMappa();					
			});
		});
	}
	
	/* popup galleria */
	/* folder_gallery Window - START */
	if(jQuery('.class-folder_gallery').length>0) {
		jQuery('a.ja_gall_init').click(function(){
			if (jQuery(this).hasClass('ja_gall_init')){
				var wid = jQuery(window).width();
				var hei = jQuery(document).height();
				if(jQuery('.jq_bk_gallery').length>0){
					jQuery('.jq_bk_gallery').css({'display': 'block'});
				}
				else{			
					jQuery('body').append('<div class="jq_bk_gallery" style="z-index:9996;background-color:#777;opacity:0.7;filter:alpha(opacity=70);position:absolute;top:0;left:0;width:'+wid+'px;height:'+hei+'px;"></div>');
				}
				jQuery('.jq_bk_gallery').css({'background-position': 'center '+Math.floor(jQuery(this).position().top)+'px ','width':wid+'px','height':hei+'px'});
				link_ajax=jQuery(this).attr('rel').replace(/____/g,'/');
				if (jQuery(this).parents('.class-gallery').length>0){
					curElem=jQuery(this).parents('.class-gallery');
					if(curElem.find('.jq_gall_array').length>0){
						curElem.find('.jq_gall_array').load(link_ajax, function(response,status,xhr){
							waitingForResult = setInterval(function(){
								if(status=='success'){ 
									clearInterval(waitingForResult);
									urlFirstImg=curElem.find('.jq_gall_array a:eq(0)').attr('href');
									relFirstImg=curElem.find('.jq_gall_array a:eq(0)').attr('rel');
									curElem.find('.jq_gall_array a:eq(0)').remove();
									curElem.find('a.ja_gall_init').each(function(){
										jQuery(this).attr('href',urlFirstImg);
										jQuery(this).attr('rel',relFirstImg);
										jQuery(this).removeClass('ja_gall_init').addClass('ajax_popup');
									});

									curElem.find('a.ajax_popup').fancybox({
										'titlePosition'	:	'over',
										'cyclic'	:	true,
										'titleFormat'		: formatTitle
									});	
									setTimeout(function(){									
										if(jQuery('.jq_bk_gallery').length>0){jQuery('.jq_bk_gallery').css({'display':'none'});}
										curElem.find('a.ajax_popup:eq(0)').trigger('click');
									},50);
									
								}
							}, 500);
						});
						return false;
					}
				}
			}
			return false;
		});
	}
	/* folder_gallery Window - END */

	jQuery('a.popup').fancybox({
		'titlePosition'	:	'over',
		'cyclic'	:	true,
		'titleFormat'		: formatTitle
	});	

	// Dimensione Testo START
	jQuery('body:eq(0)').css({fontSize:''+bodytextsize+'%'});
	document.cookie = "bodytextsize="+bodytextsize+"";
	jQuery('.voce_top_languages a:eq(0)').click(function(){
		if (jQuery('#languages:eq(0)').css('display')=='block')
		{
			jQuery('#languages:eq(0)').css({display:'none'});
		}
		else
		{
			jQuery('#languages:eq(0)').css({display:'block'});
		}
		
	});

	jQuery('#textup').click(function(){
		textsize(1); 
		return false;
	});

	jQuery('#textdown').click(function(){
		textsize(-1); 
		return false;
	});
	
	// HEADER MENU DINAMICO
	
	jQuery('.header_menu .submenu-design').css({'display':'none'});
	jQuery('.header_menu .submenu-design ul').css({'display':'none'});
	jQuery('.header_menu .submenu-design ul.current').css({'display':'block'});
	jQuery('.header_menu .submenu-design ul.current').closest('.submenu-design').css({'display':'block'});

	
	
	//jQuery('.header_menu .submenu-design ul').css({display:'none'});
	//jQuery('.header_menu .submenu-design ul.current').css({display:'block'});
	
	jQuery('.topmenu-design a.nofollow').click(function(){
		select_header_menu (jQuery(this));
		return false;
	});
/*	
	jQuery('.topmenu-design a.nofollow').focus(function(){
		select_header_menu (jQuery(this));
		return false;
	});
*/
	/* TAB NEWS CORRELATE/COMMENTI DINAMICO Start*/
	jQuery('.tab-correlated a').click(function(){
		select_tab('correlated');
		return false;
		
	});
	jQuery('.tab-comments a').click(function(){
		select_tab('comments');
		return false;
	});
	
	function select_tab(current){
		var tabs=['correlated','comments'];
		for (var i=0;i<tabs.length;i++){
			jQuery('.tab-'+tabs[i]).removeClass('current');
			jQuery('.tab-'+tabs[i]+' span').removeClass('hide');
			jQuery('.content-view-'+tabs[i]).addClass('hide');
		}
		jQuery('.tab-'+current).addClass('current');
		jQuery('.tab-'+current+' span').addClass('hide');
		jQuery('.content-view-'+current).removeClass('hide');
	};
	/* TAB NEWS CORRELATE/COMMENTI DINAMICO End*/
	
	
	// Ricerca interna folder_search_text
	jQuery('.folder_search_text form').submit(function(){
		var searchtext=jQuery(this).find('input[name=SearchText]:eq(0)').attr('value');
		if (jQuery.trim(searchtext)!='')
		{
			var url=jQuery(this).find('input[name=folder_search_text_url]:eq(0)').attr('value')+'/(search)/'+escape(jQuery.trim(searchtext));
			window.location.href=url;
		}
		return false;
	}); //

	
	//Nasconde l'editoriale se vuoto
	jQuery('.no-edit').each(function(){
		jQuery(this).closest('.leftcol-position').addClass('width-0');
		jQuery(this).closest('.block-col').children('.rightcol-position').addClass('width-100');
	});
	
	// Chiusura voci Mappa del sito
	jQuery('.content-view-sitemap td h2').each(function(){
		if(jQuery(this).next().is('ul')){
			jQuery(this).css('cursor','pointer');
			jQuery(this).children('a').click();
			jQuery(this).next().hide();
			jQuery(this).toggle(function(){
				jQuery(this).next().show();
			},function(){
				jQuery(this).next().hide();
			});
		}
	});


	jQuery('a.nuovafinestra').each(function(){
        var title=jQuery(this).attr('title');
        if (title!='') {title=title+' - ';}
        jQuery(this).attr('title',title+'Il link si apre in una nuova finestra');
	});
	
	
});	

/* SELECT header menu*/

function select_header_menu (current)
{
	if (current)
	{
		if(current.attr('rel'))
		{
			current.attr('href','#'+current.attr('rel'));
			var header_menu_rel=current.attr('rel');
			if (!current.parents('li').hasClass('selected')){
				jQuery('.topmenu-design li.selected').removeClass('selected');
				current.parents('li').addClass('selected');
				jQuery('.header_menu .submenu-design ul').css({'display':'none'});
				jQuery('.header_menu .submenu-design').css({'display':'block'});
				jQuery('ul.'+header_menu_rel).css({'display':'block'});
			} else {
				jQuery('.topmenu-design li.selected').removeClass('selected');
				jQuery('.header_menu .submenu-design').css({'display':'none'});
			}
		}
		
	}

}

// dimensione testo
function textsize(incremento)
{
	var minTextSize=60;
	var maxTextSize=100;
	bodytextsize=bodytextsize-0+((incremento-0)*10);
	if (bodytextsize<minTextSize)
	{
		bodytextsize=minTextSize;
	}
	if (bodytextsize>maxTextSize)
	{
		bodytextsize=maxTextSize;
	}
	jQuery('body:eq(0)').css({fontSize:''+bodytextsize+'%'});
	document.cookie = "bodytextsize="+bodytextsize+"";
}

// cookie
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function slide_top_news()
{
	if (jQuery('.ultime_news_top ul li:eq(0)'))
	{
		last=jQuery('.ultime_news_top ul li:visible')
		if (last.next('li').is(":hidden"))
		{
			last.slideUp();
			last.next('li').show("slow");
		}
		else
		{
			last.slideUp();
			jQuery('.ultime_news_top  ul li:eq(0)').show("slow");		
		}
	}
}

function banner_rotazione_fade()
{
	if (jQuery('.box_banner_rotazione .banner'))
	{
		last=jQuery('.box_banner_rotazione .banner:visible')
		if (last.next('.banner').is(":hidden"))
		{
			last.fadeOut("slow");
			last.next('.banner').fadeIn("slow");
		}
		else
		{
			last.fadeOut("slow");
			jQuery('.box_banner_rotazione .banner:eq(0)').fadeIn("slow");		
		}
	}
}

/*  function image_layer*/
function image_layer(img_url,img_width,img_height,img_alt)
{
	if (img_url)
	{
		var topPosition=150;
 		var box_width=parseInt(img_width)+20;
 		var box_height=parseInt(img_height)+25;
 		var win_width=jQuery(window).width();
 		var win_height=jQuery(document).height();
 		var win_margin=(jQuery(window).height()-box_height)/2;

 		var code='';
 		code+='<div class="zooming_dlg"  style="width: '+win_width+'px; height: '+win_height+'px; position: absolute; top: 0px; left: 0px; z-index: 995; overflow: hidden;" >';
 		code+=' <div class="zooming_bgi"  style="width: '+win_width+'px; height: '+win_height+'px; position: absolute; top: 0px; left: 0px; z-index: 996; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5;  ">&nbsp;</div>';
 		code+=' <div class="zooming_img"  style="width: '+win_width+'px; height: '+win_height+'px; position: absolute; top:'+topPosition+'px; left:0px; z-index: 997; display: block; background-color: transparent; text-align:center;" >';
 		code+='  <div class="zoomed_image" style="width: '+box_width+'px; height: '+box_height+'px; position: relative; background: none repeat scroll 0% 0% rgb(255, 255, 255); border: 1px solid rgb(102, 102, 102); margin:0 auto; text-align:left;">';			
 		code+='   <div class="close_win" style="z-index: 999;position: absolute; top: -15px; right: -15px; width:32px;height:32px;cursor:pointer;">&nbsp;</div>';			
 		code+='   <div style="padding: 10px 10px;">';	
 		code+='    <div class="broadcast">';
 		code+='     <div style="width:'+img_width+'px; height:'+img_height+'px; overflow: hidden;">';
 		
		code+='     <img width="'+img_width+'" height="'+img_height+'" src="'+img_url+'" alt="'+img_alt+'" />';
		
 		code+='    </div>';

		code+='    </div>';
 		code+='   </div>';
 		code+='  </div>';
 		code+=' </div>';
 		code+='</div>';
		
 	 	jQuery('#page').append(code);
	 	jQuery('.close_win').click(function(){
	 		jQuery('.zooming_dlg').remove();
	 	});
	 	jQuery('div').click(function(){
	 		jQuery('.zooming_dlg').remove();
	 	});
	 	setTimeout ( "jQuery('.zooming_dlg').remove()", 6000 );
	}
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
/* formatta il titolo del popup fancybox */
function formatTitle(title, currentArray, currentIndex, currentOpts) {
	var currUrl=currentArray[currentIndex].href;
	currUrl=currUrl.replace('_popup','');
    return '<div id="fancybox-title-over">' + '<span class="label_offset" style="float:right; margin:px 0 0 5px">' + 'Immagine ' + (currentIndex + 1) + ' di ' + currentArray.length + '</span>' + '<span class="label_title">' + (title && title.length ? '<span class="bold">' + title + '</span>' : '' ) + '</span>' + '<div class="clear">&nbsp;</div><a class="fancy_title_fullimage" href="'+currUrl+'" target="_blank">Scarica l\'immagine nelle sue dimensioni originali</a><div class="clear">&nbsp;</div>' + '</div>';
}

/* rotazione ticker home page */
function slide_top_news()
{
	if (jQuery('.feed_reader  ul li:eq(0)'))
	{
		last=jQuery('.feed_reader  ul li:visible')
		if (last.next('li').is(":hidden"))
		{
			last.slideUp();
			last.next('li').show("slow");
		}
		else
		{
			last.slideUp();
			jQuery('.feed_reader ul li:eq(0)').show("slow");		
		}
	}
}



