

/*

	Gerardo Lombardo per Hotel Paradise Ischia
	01/07/2008


*/

var urlSito = "http://www.hotelparadiseischia.com/";
var avvioPresentazione=0;
var numeroFotoSfondo=6;
var sfondox= new Array();
var sfondoy= new Array();
sfondox[1]="1000"; sfondoy[1]="588";
sfondox[2]="1000"; sfondoy[2]="604";
sfondox[3]="1000"; sfondoy[3]="643";
sfondox[4]="1000"; sfondoy[4]="627";
sfondox[5]="1000"; sfondoy[5]="665";
sfondox[6]="1000"; sfondoy[6]="665";

function startLayout() {

	
	var caricamento = document.getElementById('caricamento');
	var gMap = document.getElementById('gMap');
	var intro = document.getElementById('intro1');
	var sfondo = document.getElementById('sfondo');
	var carica = sfondo;

	if ( intro ) { carica = intro }
	if ( caricamento.style.display=="inline" ) new Effect.Fade( caricamento, {duration:0.5,fps:25,queue:{scope:'caricamento'}});
	new Effect.Appear( carica, {duration:2.0,fps:25,queue:{scope:'caricamento',position:'end'},

		afterFinish: function() {

			inizializzaBody();
			initLBwindow();
			if ( gMap ) {
				loadGmap('gMap',true);
			}
		}

	});
		
}

function allineaPagina() {

	var winW;
	var winH;

	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}

	document.body.style.height=winH+"px";
	

}

function inizializzaBody() {

	var body = document.getElementById("body");
	var contenitore = document.getElementById('contenitore');
	var intro = document.getElementById('intro1');

	body.style.top="418px";
	contenitore.style.top="70px";
	body.style.display="inline";
	contenitore.style.display="inline";
	new Effect.Appear( 'trasparenza', {duration:0.5,from:0.0,to:0.4,fps:25,queue:{scope:'sfondo'},
		afterFinish: function() {

			new Effect.Move( 'contenitore', { x: 0, y: 0, mode:'absolute', duration: 0.6, fps: 25, queue:{scope:'contenitore'}, transition: Effect.Transitions.linear,
				afterFinish: function() {

					if ( intro ) animaIntro();
						else ingrandisciPagina();

				}
			});

		}
	});


}

function animaIntro() {

	var intro1 = document.getElementById('intro1');
	var intro2 = document.getElementById('intro2');

	new Effect.Move( intro1, { x: -246, y: 0, mode:'absolute', duration: 15.0, fps: 25, queue:{scope:'intro'}, transition: Effect.Transitions.linear});

	new Effect.Appear( intro2, {duration:7.0,fps:25,queue:{scope:'intro',position:'end'},
		afterFinish: function() {
			intro1.style.displaY="none";
			new Effect.Move( intro2, { x: 0, y: -100, mode:'absolute', duration: 15.0, fps: 25, transition: Effect.Transitions.linear});
		}
	});

}

function spostaBody(h) {

	new Effect.Move( 'body', { x: 0, y: h, mode:'absolute', duration: 1.5, fps: 25, queue: { scope:'animazione', position:'front' }, transition: Effect.Transitions.linear,
		afterFinish: function() {
			if ( avvioPresentazione==0 && h == 250 ) {
				avvioPresentazione=1;
				initSfondo("img/base/",numeroFotoSfondo);
			}
		}
	});

}

function evidenzia(img){

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

}

function riduciPagina() {

	var frecciaSelezionataSu = document.getElementById('frecciaSelezionataSu');
	var frecciaSelezionataGiu = document.getElementById('frecciaSelezionataGiu');
	var menuSelezionato = document.getElementById('menuSelezionato');
	var frecciaSelezionata = document.getElementById('frecciaSelezionata');

	if ( menuSelezionato ) {
		menuSelezionato.href="javascript:;";
		menuSelezionato.onclick = function() { ingrandisciPagina(); }
		frecciaSelezionata.href="javascript:;";
		frecciaSelezionata.onclick = function() { ingrandisciPagina(); }
	}
	if ( frecciaSelezionataSu ) {
		frecciaSelezionataGiu.style.display="none";
		frecciaSelezionataSu.style.display="inline";
	}
	
	spostaBody(453);

}

function ingrandisciPagina() {

	var frecciaSelezionataSu = document.getElementById('frecciaSelezionataSu');
	var frecciaSelezionataGiu = document.getElementById('frecciaSelezionataGiu');
	var menuSelezionato = document.getElementById('menuSelezionato');
	var frecciaSelezionata = document.getElementById('frecciaSelezionata');

	if ( menuSelezionato ) {
		menuSelezionato.href="javascript:;";
		menuSelezionato.onclick = function() { riduciPagina(); }
		frecciaSelezionata.href="javascript:;";
		frecciaSelezionata.onclick = function() { riduciPagina(); }
	}
	if ( frecciaSelezionataGiu ) {
		frecciaSelezionataSu.style.display="none";
		frecciaSelezionataGiu.style.display="inline";
	}
	spostaBody(250);

}

function initSfondo(percorso,numeroFoto) {

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

	if ( !objContenitore ) return;

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

			var objDiv = document.createElement("div");
			objDiv.setAttribute('id','sfondo'+n);
			objDiv.style.zIndex=n+1;
			objDiv.className="sfondo";
			objDiv.style.width=sfondox[n]+"px";
			objDiv.style.height=sfondoy[n]+"px";
			objDiv.style.display ='none';

			var objImg = document.createElement("img");
			objImg.setAttribute('name','foto_'+n);
			objImg.setAttribute('alt','foto');
			objImg.style.border = 'none';
			objImg.src = urlSito+percorso+n+".jpg";
			objImg.style.width=sfondox[n]+"px";
			objImg.style.height=sfondoy[n]+"px";

			if ( !document.getElementById('sfondo'+n) ) {
				objDiv.appendChild(objImg);
				objContenitore.appendChild(objDiv);
			} else {

				if ( n+1 > numeroFoto ) idStartPresentazione=1;
					else idStartPresentazione=n+1;

			}

			if ( n == numeroFoto ) objImg.onload = new function() { animaSfondo(idStartPresentazione,numeroFotoSfondo); }

	}

	if ( navigator.userAgent.toLowerCase().indexOf('msie 5') > 0 || navigator.userAgent.toLowerCase().indexOf('msie 6') > 0 ) animaSfondo(idStartPresentazione,numeroFotoSfondo);

}


function animaSfondo(id,tot) {

	var precedenteId = id - 1;
	var prossimoId = id + 1;

	if ( prossimoId > tot ) prossimoId=1;
	if ( precedenteId < 1 ) precedenteId=tot;

	var sfondo = document.getElementById('sfondo'+id);
	var sfondoPrecedente = document.getElementById('sfondo'+precedenteId);

	sfondo.style.left="0px";
	sfondo.style.top="0px";

	new Effect.Parallel([
		new Effect.Appear( sfondo, { sync:true, from:0.0, to:1.0, fps: 25 }),
		new Effect.Move( sfondo, { sync:true, x: 1000-sfondox[id], y: 488-sfondoy[id] , mode:'absolute', fps: 25, transition: Effect.Transitions.linear})
	], { 
		duration: 15.0,
		delay: 5.0,
		queue: { scope:'animazione', position:'front' },
		beforeStart: function() {
			sfondoPrecedente.style.zIndex='0';
		},
		afterFinish: function() {
			sfondoPrecedente.style.zIndex=precedenteId;
			sfondoPrecedente.style.display="none";
			if ( avvioPresentazione==1 ) animaSfondo(prossimoId,tot);
		}
	});

}


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(idDiv,min) {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(idDiv));
	map.enableContinuousZoom();
	map.enableDoubleClickZoom();

	if ( min != true ) {
	        map.enableScrollWheelZoom();
	        map.addControl(new GSmallMapControl());
		map.addControl(new GOverviewMapControl());
	        map.addControl(new GMapTypeControl());
		map.openInfoWindowHtml(new GLatLng(40.7464, 13.9016),"<div align='left'><span class='testoIntestazione'><b>Hotel Paradise</b></span><br /><span class='testoNormale'>Via Grande Sentinella, 32<br />80074 Casamicciola Terme (NA) 83<br /><br /><b>tel.:</b> +39 081 996263</span></div>");
	}
	new GKeyboardHandler(map);
        map.setCenter(new GLatLng(40.7500, 13.9300), 13);

	var markerParadiseIschia = new GMarker(new GLatLng(40.7464, 13.9016));
	GEvent.addListener(markerParadiseIschia, "click", function() {
		  markerParadiseIschia.openInfoWindowHtml("<div align='left'><span class='testoIntestazione'><b>Hotel Paradise</b></span><br /><span class='testoNormale'>Via Grande Sentinella, 32<br />80074 Casamicciola Terme (NA) 83<br /><br /><b>tel.:</b> +39 081 996263</span></div>");
	});

	map.addOverlay(markerParadiseIschia);
      }
}

function loadDiv(idName) {

	var contenitore = document.getElementById("LBcontent");
	var contenuto = document.getElementById(idName);
	contenitore.innerHTML=contenuto.innerHTML;

}

function apriLBwindow(func) {

	var LBoverlay = document.getElementById('LBoverlay');
	var LBwindow = document.getElementById('LBwindow');
	var LBcontent = document.getElementById('LBcontent');

	LBcontent.innerHTML="";
	LBoverlay.style.height="100%";

	if ( LBwindow ) {

		new Effect.Parallel([
			new Effect.Appear(LBoverlay,{from:0.0,to:0.8}),
			new Effect.Appear(LBwindow)
		], { 
			duration: 0.5,
			queue: { scope:'apriLBwindow' },
			beforeStart: function() {
	
			},
			afterFinish: func
		});

	}

}

function chiudiLBwindow() {

	var LBoverlay = document.getElementById('LBoverlay');
	var LBwindow = document.getElementById('LBwindow');

	new Effect.Parallel([
		new Effect.Fade(LBoverlay),
		new Effect.Fade(LBwindow)
	], { 
		duration: 0.2,
		queue: { scope:'chiudiLBwindow' },
		beforeStart: function() {

		},
		afterFinish: function() {

		}
	});


}

function initLBwindow() {

	var objContenitore = document.body;

	if ( !objContenitore ) return;

	var objDivLBoverlay = document.createElement('div');
	objDivLBoverlay.setAttribute('id','LBoverlay');
	objDivLBoverlay.style.display="none";
	objDivLBoverlay.onclick = function() { chiudiLBwindow(); };

	var objDiv = document.createElement("div");
	objDiv.setAttribute('id','LBwindow');
	objDiv.style.display='none';
	objDiv.style.width="640px";
	objDiv.style.height="480px";
	objDiv.style.position="absolute";
	objDiv.style.left="50%";
	objDiv.style.top="50%";
	objDiv.style.marginTop="-240px";
	objDiv.style.marginLeft="-320px";
	objDiv.style.background="#FFFFFF";
	objDiv.style.zIndex="100";

	var objDivContent = document.createElement("div");
	objDivContent.setAttribute('id','LBcontent');

	var objALBclose = document.createElement("a");
	objALBclose.setAttribute('id','LBclose');
	objALBclose.setAttribute('title', 'chiudi');
	objALBclose.href="javascript:;";
	objALBclose.onclick = function() { chiudiLBwindow(); };
/**	objALBclose.observe('click', (function(event) { event.stop(); chiudiLBwindow(); }).bind(this));*/

	var objImgLBclose = document.createElement("img");
	objImgLBclose.setAttribute('alt', 'chiudi');
	objImgLBclose.style.border="0px";
	objImgLBclose.src=urlSito+"img/lightbox/closelabel.gif";

	objALBclose.appendChild(objImgLBclose);
	objDiv.appendChild(objALBclose);

	objContenitore.appendChild(objDivLBoverlay);
	objDiv.appendChild(objDivContent);
	objContenitore.appendChild(objDiv);

}

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));
}

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

}

addLoadEvent(startLayout);