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

// inizializzo dimensione del font
jQuery.noConflict();
jQuery(document).ready(function(){

	/* credits Window - START */
	if(jQuery('a.credits_link[rel]').length>0) {
		jQuery('a.credits_link[rel]').click(function(){
			link_ajax=jQuery(this).attr('rel').replace(/____/g,'/');
			var link_top=jQuery(this).offset().top-0;
			var link_left=jQuery(this).offset().left-0;
			var link_width=jQuery(this).width();
			var win_h=jQuery('body').height()-0;
			var win_w=jQuery('body').width()-0;
			jQuery('body').append('<div class="window_credits_layer" style="position: absolute; top: 0; left: 0; width: '+win_w+'px; height: '+win_h+'px;">&nbsp;</div><div class="window_credits visibility_hidden"><div class="window_credits_padding"><div class="window_credits_border"><div class="window_credits_header"><a href="#" class="close_credits"><span class="accesskey">chiudi</span></a><div class="credits_title"><h2 class="accesskey">Credits</h2></div><div class="clear">&nbsp;</div></div><div class="clear">&nbsp;</div><div class="credits_ajax"></div><div class="clear">&nbsp;</div></div></div></div>');
			jQuery('.credits_ajax').load(link_ajax, function(response,status,xhr){
				n=0
				waitingForResult = setInterval(function(){
					if(status=='success'){
						clearInterval(waitingForResult);
						var mgl=0;
						var mgt=0;
						var mg_w=jQuery('.window_credits').width()-0;
						var mg_h=jQuery('.window_credits').height()-0;
						/* mgl=win_w-mg_w-10; */
						mgl=Math.floor(link_left+(link_width/2)-(mg_w/2));
						if ((mgl+mg_w)>win_w){mgl=win_w-mg_w-5;}
						if (mgl<0){mgl=5;}
						/*if (mgl>link_left) { mgl=link_left;}*/
						mgt=win_h-mg_h-0;
						if (link_top<mg_h){mgt=link_top;}
						else {mgt=link_top-mg_h;}
						jQuery('.window_credits').css({'top': mgt+'px','left': mgl+'px' });
						jQuery('.window_credits').toggleClass('visibility_hidden');
						/* modifica target blank */
						jQuery('a.nuovafinestra').click(function(){
								jQuery(this).attr('target','_blank');
						});
						jQuery('a.nuovafinestra_inline').click(function(){
								jQuery(this).attr('target','_blank');
						});
						/* fine target blank */
						if (jQuery('.window_credits').length>0)
						{
							jQuery(window).resize(function(){
								jQuery('.window_credits').remove();
								jQuery('.window_credits_layer').remove();
							});
							jQuery('.close_credits, .window_credits_layer').click(function(){
								jQuery('.window_credits').remove();
								jQuery('.window_credits_layer').remove();
								return false;
							});
						}
					}
				}, 500);
			});
			return false;
		});
	}
	/* credits Window - END */
	
	
	// Dimensione Testo
	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'});
		}
		
	});

	//TIP country
	jQuery('a.no_href').click(function(){
			return false;
	});

	
	jQuery('.tipancor').each(function(){
		jQuery(this).wrap('<div></div>');
		jQuery(this).bt({
		  positions: 'top',
		  trigger: ['mouseover', 'click'],
		 contentSelector: "jQuery('#text_'+jQuery(this).attr('id')+':eq(0)').html()",
		 closeWhenOthersOpen: true,
		  width: 220,
		  centerPointX: .9,
		  spikeLength: 15,
		  spikeGirth: 40,
		  padding: 15,
		  cornerRadius: 5,
		  fill: '#efefef',
		  strokeStyle: '#ABABAB',
		  strokeWidth: 1
		  
		});
	});

	// ricerca interna folder_search_text
	jQuery('.project_search form').submit(function(){
		var searchtext=jQuery(this).find('input[name=SearchText]:eq(0)').attr('value');
		var url=jQuery(this).find('input[name=folder_search_text_url]:eq(0)').attr('value');
		if (jQuery.trim(searchtext)!='')
		{
			url=url+'/(search)/'+escape(jQuery.trim(searchtext));
		}
		
		jQuery(this).find('select.selecttag').each(function(){
			if (jQuery(this).attr('value')!='NULL')
			{
				url=url+'/('+escape(jQuery(this).attr('name'))+')/'+escape(jQuery(this).attr('value'));				
			}
		});
		window.location.href=url;
		
		return false;
	});

	jQuery('.project_search .searchtext_go').click(function(){
		jQuery(this).removeAttr('value');
	});
	
	//jQuery('.selecttag').css({visibility:'hidden'});
	jQuery('.selecttag').jListbox();
	
	var initialZ = 1000;
	jQuery('.a_jlb_working').each(function(){
		jQuery(this).css('zIndex', initialZ--);
	});
	
	//rotazione_news
	jQuery('.rotazione_news .block-content li').addClass('hide');
	jQuery('.rotazione_news .block-content li:eq(0)').addClass('current');
	jQuery('.rotazione_news .block-content li.current').removeClass('hide');
	
	
	// FULSIZE
	jQuery('img.popup').fullsize({
									shadow: false, 
									iconOffset: 2, 
									extraTrigger: ".myClass", 
									parentSteps: 2,
									showIcon: false
								});  
	
	jQuery('img.popup_h').fullsize({
								shadow: false, 
								iconOffset: 2, 
								extraTrigger: ".myClass", 
								parentSteps: 2,
								showIcon: false
	});  

	
	
	
	// History Gallery
	jQuery('.history_foto .foto_caption').css({display:'none'});
	jQuery('.history_foto a').mouseover(function(){
		jQuery(this).next('.foto_caption').css({display:'block'});
	});
	jQuery('.history_foto a').mouseout(function(){
		jQuery(this).next('.foto_caption').css({display:'none'});
	});
	jQuery('.foto_caption').mouseover(function(){
		jQuery(this).css({display:'block'});
		jQuery(this).prev('a').addClass('selected');	
	});
	jQuery('.foto_caption').mouseout(function(){
		jQuery(this).css({display:'none'});
		jQuery(this).prev('a').removeClass('selected');	
	});
	
	jQuery('.history_foto a').click(function(){
		return false;
	});
	
	
	
	
});	


// SLIDE HOME
var timeslide=5000;
setTimeout ( "slide()", timeslide );






function slide ()
{
	curra=jQuery('.rotazione_news .block-content li.current');
	if(curra.next('li').attr('class'))
	{
		nexta=curra.next('li');	
	}
	else if (jQuery('.rotazione_news .block-content li:eq(0)').attr('class'))
	{
		nexta=jQuery('.rotazione_news .block-content li:eq(0)');		
	}
	else
	{
		return false;
	}

	
	curra.addClass('hide');
	curra.removeClass('current');
	nexta.removeClass('hide');
	nexta.addClass('current');
	
	setTimeout ( "slide()", timeslide );
} 	

// Dimensione testo
function textsize(incremento)
{
	var minTextSize=60;
	var maxTextSize=120;
	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+"";
}

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

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

