function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Non è stato possibile impostare un gestore di eventi");
  }
}
addEvent(window,'load',init,false);

function init(){
	if (document.getElementById('fcontatti')){
		go_privacy=document.getElementById('go-privacy');
		go_privacy.onclick=function(){otherInfo(Lang4Privacy,'privacy','500','420','scrollbars');return false;}
		}
	if (document.getElementById('naviga')){
		var lnav=document.getElementById('naviga');
		lnav.onclick=function(){
			cmete_map=document.getElementById('monumenti');
			var raggiungerci = document.getElementById('blocco-raggiungerci');
			if (cmete_map.style.display=='none'||cmete_map.style.display==''){
					manageTglMap();
					cmete_map.style.display="block";
					raggiungerci.style.display = "none";
					//lnav.childNodes[0].firstChild.nodeValue="Chiudi la mappa";
					var sourceImg = lnav.getElementsByTagName('img');
					sourceImg[0].src = pathBtnMapsClose;
					}
				else{
					manageTglMap();
					cmete_map.style.display="none";
					raggiungerci.style.display = "block";
					//lnav.childNodes[0].firstChild.nodeValue="Naviga la mappa";
					var sourceImg = lnav.getElementsByTagName('img');
					sourceImg[0].src = pathBtnMapsNav;
					}
			}
		}
	if (document.getElementById('fjob')){
		go_privacy=document.getElementById('go-privacy');
		go_privacy.onclick=function(){otherInfo(Lang4Privacy,'privacy','500','420','scrollbars');return false;}
		}
	if (document.getElementById('mlist')){
		flist=document.getElementById('mlist');
		flist.onsubmit=function(){
			return checkJC_en('mlist');
			}
		}
	if (document.getElementById('thumbs')){
		FSgallery.setup();
		remoteGallery();
		}
	if (document.getElementById('cdx')){
		initShZmd();
		}
	if (document.getElementById('hnews')){
		toggleNE();
		}
	if (document.getElementById('txt-map')){
		initFsMaps();
		}
	if (document.getElementById("open-booking")){
		document.getElementById("sign-newsl").onfocus=function(){this.value=''};
	}
	if (document.getElementById("btn-info")){
		document.getElementById("btn-info").onclick=function(){toggle('room-info')};
		}
	if (document.getElementById('gmappa')){
		FSmaps();
		}
	if (document.getElementById('btn-info')){
		toggle();
		}
	if (document.getElementById('cbtns-morepics')){
		moreImgs();
		}
	if (document.getElementById('cservices')){
		rServ.init();
		document.getElementById('btn-to-show').onclick=function(){shContSrv()};
		document.getElementById('btn-to-hide').onclick=function(){hdContSrv()};
		}
	/*
	if (document.getElementById('open-booking')){
		document.getElementById('open-booking').onclick=function(){
			otherInfo(this.href,'booking','550','400');
			return false;
			}
		}
	*/
	if (document.getElementById('btn-open-babymenu')){
		document.getElementById('btn-open-babymenu').getElementsByTagName('a')[0].onclick=function(){shBm();return false;};
		document.getElementById('btn-top').getElementsByTagName('a')[0].onclick=function(){hdBm();return false;};
		}
		
		
	if($('#corpo-hp').is('div')){
		//alert(langsito);
		$('.media').media({ 
    width:     900, 
    height:    390, 
    autoplay:  true, 
    src:       '/swf/experience.swf',
    //attrs:     { attr1:  'attrValue1',  attr2:  'attrValue2' },  // object/embed attrs 
    params:    { quality: 'high', wmode: 'transparent', flashVars: 'ls='+langsito+'&serverpath=/' }, // object params/embed attrs 
    caption:   false // supress caption text 
		});
	}
		
		
		
}


function otherInfo(url,nome,w,h,scrollbars){
	currWidth=screen.width;
	currHeight=screen.height;
	wleft=(currWidth/2)-240;
	wtop=(currHeight/2)-240;
	fin=window.open(url,nome,"width="+w+",height="+h+",left="+wleft+",top="+wtop+","+scrollbars);
	}



function showMenu(){
	var logo_hp=document.getElementById('logo47-hp');
	var menu_hp=document.getElementById('menutop-hp');
	var language=document.getElementById('select-language');
	var hp_header=document.getElementById('header');
	if (document.getElementById('menutop-hp')){
	hp_header.style.borderBottom="solid 1px #4B4845";
	}
	logo_hp.style.visibility="visible";
	menu_hp.style.visibility="visible";
	language.style.visibility="hidden";
	}

function toggle(theclip){
	var btn_info_room=document.getElementById('btn-info');
	var img_info_room=document.getElementById('img-btninfo');
	var txt_info_room=document.getElementById('txt-info');
	btn_info_room.onclick=function(){
		if(txt_info_room.style.display==''||txt_info_room.style.display=='none'){
			txt_info_room.style.display='block';
			img_info_room.src="/img/rooms/btn_info_close.gif";
			}
		else if(txt_info_room.style.display=='block'){
			txt_info_room.style.display='none';
			img_info_room.src="/img/rooms/btn_info_open.gif";
			}
		}
	}

var prevIco=null;
function moreImgs(){
	var cbuttons=document.getElementById('cbtns-morepics');
	var buttons=cbuttons.getElementsByTagName('a');
	var picbig=document.getElementById('big-detail');
	var ico_on='/img/rooms/bg_btn_gorooms_on.gif';
	var ico_off='/img/rooms/bg_btn_gorooms_off.gif';
			if (buttons[0]){
				buttons[0].onclick=function(){
					if (prevIco!=null){
						prevIco.src=ico_off;
						}
					buttons[0].firstChild.src=ico_on;
					picbig.src=otherPics[0];
					prevIco=buttons[0].firstChild;
					}
				}
			if (buttons[1]){
					buttons[1].onclick=function(){
						if (prevIco!=null){
						prevIco.src=ico_off;
						}
						else{buttons[0].firstChild.src=ico_off;}
					buttons[1].firstChild.src=ico_on;
					picbig.src=otherPics[1];
					prevIco=buttons[1].firstChild;
					}
				}
			if (buttons[2]){
					buttons[2].onclick=function(){
						if (prevIco!=null){
						prevIco.src=ico_off;
						}
						else{buttons[0].firstChild.src=ico_off;}
					buttons[2].firstChild.src=ico_on;
					picbig.src=otherPics[2];
					prevIco=buttons[2].firstChild;
					}
				}
}

function remoteGallery(){
	var tasti=document.getElementById('remote').getElementsByTagName('a');
	var download=document.getElementById('dwnld');
	//setta il default su apertura pagina
	download.target="_blank";
	download.href="/img/press/press_47Hotel_1.zip";
	for (i=0;i<tasti.length;i++){
		if (tasti[i].id=='btn-serie1') {
			tasti[i].onclick=function(){
				tasti[0].firstChild.src="/img/rooms/bg_btn_gorooms_on.gif";
				tasti[1].firstChild.src="/img/rooms/bg_btn_gorooms_off.gif";
				document.getElementById('prima-serie').style.display='block';
				document.getElementById('seconda-serie').style.display='none';
				download.target="_blank";
				download.href="/img/press/press_47Hotel_1.zip";
				}
			}
		if (tasti[i].id=='btn-serie2') {
			tasti[i].onclick=function(){
				tasti[0].firstChild.src="/img/rooms/bg_btn_gorooms_off.gif";
				tasti[1].firstChild.src="/img/rooms/bg_btn_gorooms_on.gif";
				document.getElementById('prima-serie').style.display='none';
				document.getElementById('seconda-serie').style.display='block';
				download.target="_blank";
				download.href="/img/press/press_47Hotel_2.zip";
				}
			}
		}

}
var FSgallery = {
	arrThumbs : [],
	path : "/img/press/zoom/",
	fext : ".jpg",
	counter : 0,
	setup : function(){
		var thumbs=document.getElementById('thumbs').getElementsByTagName('img');

		for(i=0;i<thumbs.length;i++) {

			var srcImg=thumbs[i].src;
			var nomeThumb=srcImg.substring(srcImg.lastIndexOf("/")+1,srcImg.length);

			this.arrThumbs.push(nomeThumb);
			thumbs[i].onclick=new Function( "FSgallery.showPics('" + nomeThumb + "');" );
		}
	},
	showPics : function(nomeThumb){
			var zoom=document.getElementById('zoomed');
			zoom.src=this.path+nomeThumb;
		}
};


function otherInfo(url,nome,w,h,scrollbars){
	currWidth=screen.width;
	currHeight=screen.height;
	wleft=(currWidth/2)-240;
	wtop=(currHeight/2)-240;
	fin=window.open(url,nome,"width="+w+",height="+h+",left="+wleft+",top="+wtop+","+scrollbars);
	}


var rServ = {
	gestEvent:function (obj, evType, fn, useCapture){
			  if (obj.addEventListener){
				obj.addEventListener(evType, fn, useCapture);
				return true;
			  } else if (obj.attachEvent){
				var r = obj.attachEvent("on"+evType, fn);
				return r;
			  } else {
				alert("Non è stato possibile impostare un gestore di eventi");
			  }
			},

	init:function(){
		var m=document.getElementById('menu-services');
		rServ.mlinks=m.getElementsByTagName('a');
		for (i=0;i<rServ.mlinks.length;i++){
			rServ.gestEvent(rServ.mlinks[i],'click',rServ.swap,false);
			rServ.lastVoice=null;
			}
	},
	swap:function(e){
		var theLink;
		if (e&&e.target) theLink=e.target;
		if (window.event&&window.event.srcElement) theLink=window.event.srcElement;
		if (!theLink) alert('Attenzione: il link non è stato individuato');
		//primo click che nasconde il testo di default e setta lastVoice non a null
		if (rServ.lastVoice==null){
			document.getElementById('servizi-m0').style.display="none";
			}

		rServ.currVoice=theLink.parentNode;
		rServ.currTxt='servizi-'+theLink.id;
		if (rServ.lastVoice!=null)	rServ.lastTxt='servizi-'+rServ.lastVoice.firstChild.id;

		if (rServ.currVoice==rServ.lastVoice) return;
		else {
			if (rServ.lastVoice!=null) {
					rServ.lastVoice.className="";
					document.getElementById(rServ.lastTxt).style.display="none";
					}
				rServ.currVoice.className="selected";
				document.getElementById(rServ.currTxt).style.display="block";
		rServ.lastVoice=rServ.currVoice;
			 }
		}
}

clipSpacer=[315,850,615,0]
var spacerTimerID;
function shBm(){
	//alert(clipSpacer)
var spacer=document.getElementById('cmenu-baby');
	if (clipSpacer[0]>=0) {
	spacer.style.display='block';
			clipSpacer[0]-=45;
			spacer.style.clip='rect('+clipSpacer.join('px ')+'px)';
			spacerTimerID=window.setTimeout("shBm()",30);
			return;
			}
			if (spacerTimerID){
			clearTimeout(spacerTimerID);
			}
		clipSpacer=[315,850,615,0]
}
var clipSpacerHd=[0,850,315,0]
var spTmrHd;
function hdBm(){
var spacer=document.getElementById('cmenu-baby');
	if (clipSpacerHd[0]<=315) {
	spacer.style.display='block';
			clipSpacerHd[0]+=55;
			spacer.style.clip='rect('+clipSpacerHd.join('px ')+'px)';
			spTmrHd=window.setTimeout("hdBm()",30);
			return;
			}
			if (spTmrHd){
			clearTimeout(spTmrHd);
			}
			clipSpacerHd=[0,850,350,0]
}

function initShZmd(){
var lth=document.getElementById('cdx').getElementsByTagName('a');
	for(i=0;i<lth.length;i++){
		if (lth[i].parentNode.className=='th-services'){
			var srcImg=lth[i].firstChild.src;
			var nomeThumb=srcImg.substring(srcImg.lastIndexOf("_"),srcImg.length);
			lth[i].onclick=new Function( "shZmd('" + nomeThumb + "');" );
			}
		}

	}
function shZmd(nmTh){
	var pathZmd="/img/services/"
	var cserv=document.getElementById('cservices');
	cserv.style.backgroundImage="url("+pathZmd+"zmd"+nmTh+")";
	}


//controlla tendina servizi
arrSh=[0,636,0,0]
var TmrSh;
function shContSrv(){
var btntsh=document.getElementById('btn-to-show');
var btnthd=document.getElementById('btn-to-hide');
var area=document.getElementById('content-services');
	if (arrSh[2]<=350) {
	area.style.display='block';
			arrSh[2]+=45;
			area.style.clip='rect('+arrSh.join('px ')+'px)';
			TmrSh=window.setTimeout("shContSrv()",30);
			return;
			}
			if (TmrSh){
			clearTimeout(TmrSh);
			btnthd.style.display='block';
			}
		arrSh=[0,636,0,0]
}
var arrHd=[0,636,350,0]
var TmrHd;
function hdContSrv(){
var btnthd=document.getElementById('btn-to-hide');
var area=document.getElementById('content-services');
	if (arrHd[2]>=0) {
	area.style.display='block';
	btnthd.style.display='none';
			arrHd[2]-=55;
			area.style.clip='rect('+arrHd.join('px ')+'px)';
			TmrHd=window.setTimeout("hdContSrv()",30);
			return;
			}
			if (TmrHd){
			clearTimeout(TmrHd);
			}
			arrHd=[0,636,350,0]
}

function manageTglMap(){
	if (statoMappa==null||statoMappa=='nascosta'){
		 shMap();
		}
	else {
		 hdMap();
		}

	}

//controlla toggle su mappa
statoMappa=null;
arrShMap=[0,593,353,0]
var TmrShMap;
function shMap(){
	//alert('open')
var area=document.getElementById('static-map');
	if (arrShMap[1]>=0) {
	area.style.display='block';
			arrShMap[1]-=45;
			area.style.clip='rect('+arrShMap.join('px ')+'px)';
			TmrShMap=window.setTimeout("shMap()",30);
			return;
			}
			if (TmrShMap){
			clearTimeout(TmrShMap);
			statoMappa='visibile';
			}
		arrShMap=[0,593,353,0]
}
var arrHdMap=[0,0,353,0]
var TmrHdMap;
function hdMap(){
var area=document.getElementById('static-map');
	if (arrHdMap[1]<=593) {
	area.style.display='block';
			arrHdMap[1]+=55;
			area.style.clip='rect('+arrHdMap.join('px ')+'px)';
			TmrHdMap=window.setTimeout("hdMap()",30);
			return;
			}
			if (TmrHdMap){
			clearTimeout(TmrHdMap);
			statoMappa='nascosta';
			}
			arrHdMap=[0,0,353,0]
}


  function checkJC_it(nomeForm) {
  var continua=true;
  var els=document.getElementById(nomeForm);
  var els = els.elements;
  for (i=0;i<els.length;i++) {
          if (els[i].type=='checkbox'&&els[i].checked!=true) {
                  alert("Attenzione: per proseguire è necessario fornire l'autorizzazione al trattamento dei dati");
                  continua=false;
                  break;
                  }
          if (els[i].value==""&&els[i].type!='checkbox') {
                  if (els[i].name=='indirizzo') continue;
                  if (els[i].type=='textarea'){
                          alert("Attenzione: il campo "+els[i].className +" è richiesto");
                          continua=false;
                          break;
                          }
                  alert("Attenzione: il campo "+els[i].alt +" è richiesto");
                  els[i].focus();
                  els[i].value="";
                  continua=false;
                  break;
                          }
                  if (els[i].value!=''&&els[i].id=='email'||els[i].id=='sign-newsl') {
                  var see = els[i].value.indexOf("@");
                  var see1 = els[i].value.lastIndexOf("@");
                  var see2 = els[i].value.lastIndexOf(".")
                          if ((see!=-1&&see1!=-1)&&(see==see1)&&see>1&&(see2>see1&&see)) {
                  }
                  else {
                  alert("Attenzione:si prega di inserire un indirizzo email valido!");
                  els[i].focus();
                  els[i].value="";
                  continua=false;
                  break;
                     }
            }
          }//chiude ciclo principale
  return continua;
  }
  function checkJC_en(nomeForm) {
  var continua=true;
  var els=document.getElementById(nomeForm);
  var els = els.elements;
  for (i=0;i<els.length;i++) {
          if (els[i].type=='checkbox'&&els[i].checked!=true) {
          alert('Please, give your consensus to privacy info to continue');
                  continua=false;
                  break;
                  }
          if (els[i].value==""&&els[i].type!='checkbox') {
                  if (els[i].name=='indirizzo') continue;
                  if (els[i].type=='textarea'){
                  alert('Please fill in all required fields');
                        //  alert("Attenzione: il campo "+els[i].className +" è richiesto");
                          continua=false;
                          break;
                          }
                    alert('Please fill in all required fields');
//                  alert("Attenzione: il campo "+els[i].alt +" è richiesto");
                  els[i].focus();
                  els[i].value="";
                  continua=false;
                  break;
                          }
                  if (els[i].value!=''&&els[i].id=='email'||els[i].id=='sign-newsl') {
                  var see = els[i].value.indexOf("@");
                  var see1 = els[i].value.lastIndexOf("@");
                  var see2 = els[i].value.lastIndexOf(".")
                          if ((see!=-1&&see1!=-1)&&(see==see1)&&see>1&&(see2>see1&&see)) {
                  }
                  else {
                  alert("Please insert a valid address email");
                  els[i].focus();
                  els[i].value="";
                  continua=false;
                  break;
                     }
            }
          }//chiude ciclo principale
  return continua;
  }
 function checkJC_ja(nomeForm) {
  var continua=true;
  var els=document.getElementById(nomeForm);
  var els = els.elements;
  for (i=0;i<els.length;i++) {
          if (els[i].type=='checkbox'&&els[i].checked!=true) {
          alert('Please, give your consensus to privacy info to continue');
                  continua=false;
                  break;
                  }
          if (els[i].value==""&&els[i].type!='checkbox') {
                  if (els[i].name=='indirizzo') continue;
                  if (els[i].type=='textarea'){
                  alert('Please fill in all required fields');
                        //  alert("Attenzione: il campo "+els[i].className +" è richiesto");
                          continua=false;
                          break;
                          }
                    alert('Please fill in all required fields');
//                  alert("Attenzione: il campo "+els[i].alt +" è richiesto");
                  els[i].focus();
                  els[i].value="";
                  continua=false;
                  break;
                          }
                  if (els[i].value!=''&&els[i].id=='email'||els[i].id=='sign-newsl') {
                  var see = els[i].value.indexOf("@");
                  var see1 = els[i].value.lastIndexOf("@");
                  var see2 = els[i].value.lastIndexOf(".")
                          if ((see!=-1&&see1!=-1)&&(see==see1)&&see>1&&(see2>see1&&see)) {
                  }
                  else {
                  alert("Please insert a valid address email");
                  els[i].focus();
                  els[i].value="";
                  continua=false;
                  break;
                     }
            }
          }//chiude ciclo principale
  return continua;
  }


/*
			alert('Please fill in all required fields');
                        alert('Please, give your consensus to privacy info to register');

*/

function zoomMorePicture(el){
	var containerZoom=document.getElementById('czoomed-roof');
	containerZoom.src="/img/statiche/"+el+".jpg"

	}
