jQuery.exists = function(selector) {return ($(selector).length > 0);}

$(document).bind('ready',
	
	function()
	{

	if( $.browser.msie && $.browser.version < 7 ){
		$('h1').pngfix();
		$('#newsticker dl').pngfix();
		$('#hometicker span').pngfix();
	}
	var zIndexNumber = 10000;
	$('div,h1,h1 a,ul,ul li').each(function() {
		if (($(this).attr('id') != 'background-container') && ($(this).attr('id') != 'background')) {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		}
	});
	
	$('#pagecell').css('zIndex', '9000');
	$('h1').css('zIndex', '10001');
	$('#breadcrumb').css('zIndex', parseInt($('#mainnav').css('zIndex'))-1);
//	$('#breadcrumb').css('zIndex', '9001');
	
	
	var gg_bolEventsMenuDown = false;

	if( $.browser.msie && $.browser.version < 7 ) {
	
		$('#events').bind('mouseover',function(){
	  	$('#events>ul').show();			    	
		});
		$('#events').bind('mouseout',function(){
	  	$('#events>ul').hide();			  
		});
	
		$('#morespecials').bind('mouseover',function(){
	  	$('#morespecials>ul').show();			    	
		});
		$('#morespecials').bind('mouseout',function(){
	  	$('#morespecials>ul').hide();			  
		});
	}


	$('#events>ul').bind('mouseover',function(){
  	$('#events>a').removeClass(' over').addClass(' over');			    	
	});
	$('#events>ul').bind('mouseout',function(){
  	$('#events>a').removeClass(' over');			  
	});
	
	$('#morespecials>ul').bind('mouseover',function(){		
  	$('#morespecials>a').removeClass(' over').addClass(' over');			  
	});
	$('#morespecials>ul').bind('mouseout',function(){
  	$('#morespecials>a').removeClass(' over');			  
	});
	
	
});

var ie4 = false; if(document.all) { ie4 = true; }
function getObject(id) { if (ie4) { return document.all[id]; } else { return document.getElementById(id); } }

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
 	for (var i=0; i<anchors.length; i++) {
  	var anchor = anchors[i];
   	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

function setLanguage(pp_strLang) {
	var ll_strAppo;
	var ll_strCurrUrl = window.location + '';
	var ll_strNewUrl	= ll_strCurrUrl;
	
	if (ll_strCurrUrl.indexOf('asp') == -1)
		ll_strNewUrl = ll_strCurrUrl + 'default.asp';
	else if ((ll_strCurrUrl.indexOf('asp') == -1) || (ll_strCurrUrl.indexOf('index.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('index.asp','default.asp');
	else if (ll_strCurrUrl.indexOf('default.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('default.asp','index.asp');
	else if (ll_strCurrUrl.indexOf('chisiamo.asp') >= 0)
		ll_strNewUrl = ll_strCurrUrl.replace('chisiamo.asp','about.asp');
	else if (ll_strCurrUrl.indexOf('about.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('about.asp','chisiamo.asp');
	else if (ll_strCurrUrl.indexOf('archivio.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('archivio.asp','archive.asp');
	else if (ll_strCurrUrl.indexOf('archive.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('archive.asp','archivio.asp');
	else if (ll_strCurrUrl.indexOf('archivio_dettaglio.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('archivio_dettaglio.asp','archive_detail.asp');
	else if (ll_strCurrUrl.indexOf('archive_detail.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('archive_detail.asp','archivio_dettaglio.asp');
	else if (ll_strCurrUrl.indexOf('contatti.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('contatti.asp','contacts.asp');
	else if (ll_strCurrUrl.indexOf('contacts.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('contacts.asp','contatti.asp');
	else if (ll_strCurrUrl.indexOf('novita.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('novita.asp','news.asp');
	else if (ll_strCurrUrl.indexOf('news.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('news.asp','novita.asp');
	else if (ll_strCurrUrl.indexOf('novita_dettaglio.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('novita_dettaglio.asp','news_detail.asp');
	else if (ll_strCurrUrl.indexOf('news_detail.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('news_detail.asp','novita_dettaglio.asp');
		
	window.location = ll_strNewUrl;					
	
}

function setImgDim(pp_objThis,pp_lngWidth,pp_lngHeight){

	var ll_lngHeightNew;
	var ll_lngWidthNew;
	var ll_lngHeight = pp_objThis.height;
	var ll_lngWidth = pp_objThis.width;					
	if (ll_lngWidth > pp_lngWidth){
		ll_lngHeight 	= Math.floor(ll_lngHeight * (pp_lngWidth / ll_lngWidth));		
		ll_lngWidth 	= pp_lngWidth;
	}
	if (ll_lngHeight > pp_lngHeight){
		ll_lngWidth 	= Math.floor(ll_lngWidth * (pp_lngHeight / ll_lngHeight));		
		ll_lngHeight 	= pp_lngHeight;
	}
	pp_objThis.height = ll_lngHeight;
	pp_objThis.width = ll_lngWidth;	
	pp_objThis.style.visibility = 'visible';
	pp_objThis.style.display = 'block';
//		$(document).pngFix(); 
	

}
function setImgDimHeight(pp_objThis,pp_lngWidth,pp_lngHeight){

	var ll_lngHeightNew;
	var ll_lngWidthNew;
	var ll_lngHeight = pp_objThis.height;
	var ll_lngWidth = pp_objThis.width;					
	if (ll_lngHeight > pp_lngHeight){
		ll_lngWidth 	= Math.floor(ll_lngWidth * (pp_lngHeight / ll_lngHeight));		
		ll_lngHeight 	= pp_lngHeight;
	}
	pp_objThis.height = ll_lngHeight;
	pp_objThis.width = ll_lngWidth;	
	pp_objThis.style.visibility = 'visible';
	pp_objThis.style.display = 'block';
//		$(document).pngFix(); 
	

}

function MsgboxYesNo(pp_strText)	{
	return confirm(pp_strText);
}
function setCurrPage(pp_lngPage){
	$('#elem_pagina').val(pp_lngPage); 
	$('#elem_search').submit(); 
}
