
gg_strUrlBase = 'http://www.allaregola.it/';
//gg_strUrlBase = 'http://localhost/laregola/';

jQuery.exists = function(selector) {return ($(selector).length > 0);}


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() {
	
	var ll_strAppo;
	var ll_strNewUrl;
	var ll_strCurrUrl = window.location + '';
	
	if (ll_strCurrUrl.indexOf('#') >= 0)
		ll_strCurrUrl = ll_strCurrUrl.substring(0,ll_strCurrUrl.indexOf('#'));

	if ((ll_strCurrUrl == gg_strUrlBase) || (ll_strCurrUrl == 'http://allaregola.it/'))
		ll_strNewUrl = gg_strUrlBase + 'default.asp';
	else if ((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('menu.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('menu.asp','menu_eng.asp');
	else if (ll_strCurrUrl.indexOf('menu_eng.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('menu_eng.asp','menu.asp');

	else if ((ll_strCurrUrl.indexOf('eventi.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('eventi.asp','events.asp');
	else if (ll_strCurrUrl.indexOf('events.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('events.asp','eventi.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('news.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('news.asp','news_eng.asp');
	else if (ll_strCurrUrl.indexOf('news_eng.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('news_eng.asp','news.asp');

	else if ((ll_strCurrUrl.indexOf('news_dettaglio.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('news_dettaglio.asp','news_detail.asp');
	else if (ll_strCurrUrl.indexOf('news_detail.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('news_detail.asp','news_dettaglio.asp');

	else if ((ll_strCurrUrl.indexOf('diconodinoi.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('diconodinoi.asp','inthemedia.asp');
	else if (ll_strCurrUrl.indexOf('inthemedia.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('inthemedia.asp','diconodinoi.asp');

	else if ((ll_strCurrUrl.indexOf('galleria.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('galleria.asp','gallery.asp');
	else if (ll_strCurrUrl.indexOf('gallery.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('gallery.asp','galleria.asp');


	else if ((ll_strCurrUrl.indexOf('prenotazioni.asp') >= 0))
		ll_strNewUrl = ll_strCurrUrl.replace('prenotazioni.asp','reservations.asp');
	else if (ll_strCurrUrl.indexOf('reservations.asp') >= 0)
			ll_strNewUrl = ll_strCurrUrl.replace('reservations.asp','prenotazioni.asp');
			
	window.location = ll_strNewUrl;			

}

function setImgDimFill(pp_objThis,pp_lngOrigWidth,pp_lngOrigHeight,pp_lngWidth,pp_lngHeight){

	var ll_lngHeightNew;
	var ll_lngWidthNew;
	
	var ll_lngHeight = pp_lngOrigHeight;
	var ll_lngWidth = pp_lngOrigWidth;					
	
	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';
	
	if (ll_lngHeight > pp_lngHeight)
		pp_objThis.style.marginTop = '-' + ((ll_lngHeight - pp_lngHeight)/2) + 'px';
	if (ll_lngWidth > pp_lngWidth)
		pp_objThis.style.marginLeft = '-' + ((ll_lngWidth - pp_lngWidth)/2) + 'px';

}

function setImgDimFillGalleria(pp_objThis,pp_lngOrigWidth,pp_lngOrigHeight,pp_lngWidth,pp_lngHeight){

	var ll_lngHeightNew;
	var ll_lngWidthNew;
	
	var ll_lngHeight = pp_lngOrigHeight;
	var ll_lngWidth = pp_lngOrigWidth;					
	
	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).css({
		'visibility': 'visible',
		'display': 'block'
	});
	
	if (ll_lngHeight > pp_lngHeight)
		$(pp_objThis).css('margin-top','-' + ((ll_lngHeight - pp_lngHeight)/2) + 'px');
	if (ll_lngWidth > pp_lngWidth)
		$(pp_objThis).css('margin-left','-' + ((ll_lngWidth - pp_lngWidth)/2) + 'px');

}
