

/*

	Gerardo Lombardo per Hotel Bagnitiello
	11/05/2008


*/

var urlSito = "http://www.bagnitiello.it/";

function startLayout() {

	var loadingLogo = document.getElementById('loadingLogo');
	var header1 = document.getElementById('header1');
	var sfondoFasciaFoto1 = document.getElementById('sfondoFasciaFoto1');
	var gMap = document.getElementById('gMap');

	if ( loadingLogo ) new Effect.Fade( 'loadingLogo', {duration:1.0});
	if ( gMap ) loadGmap();

	new Effect.Appear( 'header0', {delay:1.0,duration:2.0,queue:{scope:'testata',position:'end'},
		afterFinish: function() {
			if ( sfondoFasciaFoto1 ) apriFasciaFoto();
			initTestata("img/headers/",3);
		}
	});

	
}

function initTestata(percorso,numeroFoto) {

	var objContenitore = document.getElementById('layerSuperiore');

	if ( !objContenitore ) return;

	for ( var n=1; n <= numeroFoto; n++ ) {

			var objDiv = document.createElement("div");
			objDiv.setAttribute('id','header'+n);
			objDiv.style.zIndex=n+1;
			objDiv.className="fotoHeader";
			objDiv.style.display ='none';

			var objImg = document.createElement("img");
			objImg.setAttribute('name','foto_'+n);
			objImg.setAttribute('alt','Hotel Bagnitiello');
			objImg.style.border = 'none';
			objImg.src = urlSito+percorso+n+".jpg";
			if ( n == numeroFoto ) objImg.onload = function() { avviaTestata(1,n); }

			objDiv.appendChild(objImg);
			objContenitore.appendChild(objDiv);

	}

	if ( navigator.userAgent.toLowerCase().indexOf('msie 5') > 0 || navigator.userAgent.toLowerCase().indexOf('msie 6') > 0 ) avviaTestata(1,n);

}

function avviaTestata(n,numeroMax) {

	if ( n > numeroMax-1 ) n = 0;
	var nPrecedente = n - 1;
	if ( nPrecedente < 0 ) nPrecedente = numeroMax-1;


	var fotoPrecedente = document.getElementById('header'+nPrecedente);
	var foto = document.getElementById('header'+n);

	new Effect.Appear(foto, {delay:5.0,duration:3.0,queue:{scope:'testata',position:'end'},
		afterFinish: function() {
			new Effect.Fade(fotoPrecedente, {duration:0.5,queue:{scope:'testata',position:'end'},
				afterFinish: function() {
					if ( n==numeroMax-1 ) foto.style.zIndex=0;
						else if ( n==0 ) fotoPrecedente.style.zIndex=numeroMax;
					avviaTestata(n+1,numeroMax);
				}
			});
		}
	});
	
}

function apriFasciaFoto() {


	var sfondoFasciaFoto1 = document.getElementById('sfondoFasciaFoto1');
	var sfondoFasciaFoto2 = document.getElementById('sfondoFasciaFoto2');
	var contentFasciaFoto = document.getElementById('contentFasciaFoto');

	$('sfondoFasciaFoto1').setStyle({opacity:0.1});
	$('sfondoFasciaFoto2').setStyle({opacity:0.1});
	sfondoFasciaFoto1.style.display="inline";
	sfondoFasciaFoto2.style.display="inline";


	new Effect.Opacity( 'sfondoFasciaFoto1', {duration:1.0,from:0.1,to:0.5});
	new Effect.Opacity( 'sfondoFasciaFoto2', {duration:1.0,from:0.1,to:0.5,
		afterFinish: function() {

			contentFasciaFoto.style.display = "inline";

			for ( n=1;n<=4; n++ ) new Effect.Appear( 'foto'+n, {duration:0.5,queue:{scope:'foto', position:'end'}});

			new Effect.Appear( 'altreFoto', {duration:0.5,queue:{scope:'foto', position:'end'}}); 

		}
	});


}

function cambiaFoto() {

	var altreFoto = document.getElementById('altreFoto');

	altreFoto.style.display="none";

	for ( n=1;n<=4;n++) {

		var img = document.getElementById('foto'+n);

		if ( img.style.display=="none" ) {

			var appear = document.getElementById('foto'+n);
			var fade = document.getElementById('foto'+(n+4));

		} else {

			var appear = document.getElementById('foto'+(n+4));
			var fade = document.getElementById('foto'+n);

		}

		new Effect.Appear( appear, {duration:0.3,queue:{scope:'foto', position:'end'}});
		new Effect.Fade( fade, {duration:0.3,queue:{scope:'foto2', position:'end'}});

			
	}

	new Effect.Appear( 'altreFoto', {duration:0.5,queue:{scope:'foto2', position:'end'}}); 



}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

function evidenzia(img){

	new Effect.Opacity( img, {duration:0.2,from:0.7,to:1.0,queue:{scope:'evidenzia',position:'end'}});

}

function displayMail(Server, Login, Display, Stile) {

	if ((Display.length == 0) || (Display.indexOf('@')+1)) {
		document.write("<a title='mail' class='"+Stile+"' href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Login + "@" + Server + "</a>");
	} else {
		document.write("<a title='mail' class='"+Stile+"' href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Display + "</a>");
	}
}

function loadGmap() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("gMap"));
	map.enableContinuousZoom();
	map.enableDoubleClickZoom();
        map.enableScrollWheelZoom();
        map.addControl(new GSmallMapControl());
	map.addControl(new GOverviewMapControl());
        map.addControl(new GMapTypeControl());
	new GKeyboardHandler(map);
        map.setCenter(new GLatLng(40.7490, 13.9231), 13);

	map.openInfoWindowHtml(new GLatLng(40.7497, 13.9231),"<div align='center'><img border='0' alt='Hotel Bagnitiello' src='"+urlSito+"img/logo.png'></img></div>");

	var markerBagnitiello = new GMarker(new GLatLng(40.7497, 13.9231));
	GEvent.addListener(markerBagnitiello, "click", function() {
		  markerBagnitiello.openInfoWindowHtml("<div align='center'><img border='0' alt='Hotel Bagnitiello' src='"+urlSito+"img/logo.png'></img></div>");
	});

	map.addOverlay(markerBagnitiello);
      }
}

function cambiaScheda(scheda,numeroMax) {

	for ( n=1;n<=numeroMax;n++) {

		if ( n != scheda ) if ( document.getElementById('linkScheda'+n).className=="sottoMenuSelezionato" ) {
			new Effect.BlindUp( 'scheda'+n, {duration:0.5,queue:{scope:'scheda',position:'end'}});
			document.getElementById('linkScheda'+n).className="sottoMenu";
		}

	}

	new Effect.BlindDown( 'scheda'+scheda, {duration:0.5,queue:{scope:'scheda',position:'end'}});
	document.getElementById('linkScheda'+scheda).className="sottoMenuSelezionato";

}


function LTrim(str) {
 for (var i=0; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i++);
 return str.substring(i,str.length);
}
function RTrim(str) {
 for (var i=str.length-1; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i--);
 return str.substring(0,i+1);
}

function Trim(str) {
 return LTrim(RTrim(str));
}

addLoadEvent(startLayout);