
function getElementPositionEx(elemID){
var offsetTrail = document.getElementById(elemID);
var offsetLeft = 0;
var offsetTop = 0;
while (offsetTrail){
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
offsetLeft += document.body.leftMargin;
offsetTop += document.body.topMargin;
}
return offsetTop;
}

var last_over_item;
var last_open_item;
var Site = {
	
	showSub: function(el){

		Site.hideSubs(el);
		
		x = el.id.split("_");
		var et = getElementPositionEx(el.id);
		
		var block = document.getElementById('sub_'+x[1]);

		var sz = $('sub_'+x[1]).getSize();
		var sze = $(el).getSize();

			var fx = new Fx.Elements(block, {
				wait: false,
				duration: 550,
				transition: Fx.Transitions.Sine.easeOut,
					onComplete: function() {

        		var sideblocks = $$('div.sItem');
            sideblocks.each(function(kel, i){
              r = kel.id.split("_");
              if(x[1]!=r[1]){
                kel.setStyle('display', 'none');
                kel.setStyle('top', '-400px');
                kel.setStyle('display', 'block');
              }              
            }, this);


					}.bind(this)

			});
			if(et+sz.y > 300){
				et=et-sz.y + sze.y;
			}

      var o = {};      
			o[0] = {'top': [block.getStyle("top").toInt(), et]}
			fx.start(o);
	}
	,
	hideSubs: function(el){
        		var sideblocks = $$('div.sItem');
            sideblocks.each(function(kel, i){
                kel.setStyle('display', 'none');
                kel.setStyle('top', '-400px');
                kel.setStyle('display', 'block');
            }, this);
		
	}
};





window.addEvent('domready', function() {

	$$('a.evento').each(function(el, i){
  	el.addEvents({
			mouseenter: function(){
				Site.showSub(el);
			}
		});
	});
	$$('div.sItem').each(function(el, i){
  	el.addEvents({
			mouseleave: function(){
				 Site.hideSubs(el);
			}
		});
	});









/*IMPOSTAZIONE FOTOGRAFIE PER ESTATE O INVERNO, CONSULTARE LE PARTI REMMATE */

	//var idimg = Math.floor(Math.random()*9);
	/*PER l'inverno la variabile è 23 */
	/*PER l'estate la variabile è 9 */
	//idimg = idimg + 1;
	//if(idimg<10) idimg = '0'+idimg;
	
	
	
	// calcolo l'ora per stabilire i minuti per la variabile che sceglie l'immagine
	var Digital = new Date();
	var minutes = Digital.getMinutes();
	/*PER l'estate la variabile è 3 quindi posso vedere un totale si 20 img ora*/
	/*PER l'estate la variabile è 6 quindi posso vedere un totale si 10 img ora*/
	var idimg = parseInt(minutes / 6);
	if (idimg <= 9) { idimg = "0"+idimg; }

	
	
	szw = $(window.document.body).getSize();
	
	// szw = document.getElementsByName('body')[0].getSize();
	

	if(szw.x<1024){
/*la cartella di destinazione delle immagini estige è 1024_est*/
	  $(document.body).setStyle('background-image','url(/res/inc/img/bg/1024_inv/' + idimg + '.jpg)')
	}
	if(szw.x > 1024 && szw.x < 1280){
/*la cartella di destinazione delle immagini estige è 1280_est*/
	  $(document.body).setStyle('background-image','url(/res/inc/img/bg/1280_inv/' + idimg + '.jpg)')
		if($('gruppo_880')!=undefined){
			var szg = $('gruppo_880').getSize();
			if(szg.y < 300){
				var mdott = (szg.y - 300)*(-1);
				/*alert(mdott);*/
				$('trasp_tappo').setStyles({display: 'block',width: 300,height: mdott});
			}
		}
	}
	if(szw.x>1280){
/*la cartella di destinazione delle immagini estige è 1920_est*/
	  $(document.body).setStyle('background-image','url(/res/inc/img/bg/1920_inv/' + idimg + '.jpg)')
		if($('gruppo_880')!=undefined){
			var szg = $('gruppo_880').getSize();
			if(szg.y < 550){
				var mdott = (szg.y - 550)*(-1);
				/*alert(mdott);*/
				$('trasp_tappo').setStyles({display: 'block',width: 300,height: mdott});
			}
		}
	}
/*attivare per l'inverno la scritta fotografaie dolomitistars*/
/*per l'este remmare le tre righe a seguire*/
	//if([parseInt('04'),parseInt('05'),parseInt('06'),parseInt('07'),parseInt('08'),parseInt('09'),parseInt('10'),parseInt('15')].indexOf(parseInt(idimg)) > -1){
	//		$('arc_dolstars').setStyle('display','block');
	//	}
});





var http_request = false;
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
			try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
  }
      http_request.onreadystatechange = onReadyState;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
   function onReadyState() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
          var rx=http_request.responseText;
          
          if(rx.slice(0,4)=="{JS}"){
						eval(rx.substring(4));
					}
					else {
          if(rx.slice(0,7)=="{ERROR}"){
						$('results').innerHTML="";
						alert(rx.substring(7));
          }
					else {
						$('results').innerHTML=rx;
					}
					}

          if(rx.slice(0,10)=="{INSERTOK}"){
          }
          if(rx.slice(0,10)=="{DETAILOK}"){
          }
          if(rx.slice(0,10)=="{DELETEOK}"){
          }
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
	function submitPage(hideprogress) {
		if(document.getElementsByTagName) {
			var poststr = "";
			var inputs = new Array("input","textarea","select");

//			var objs = document.getElementsByTagName("input");
//			for(i=0; i < objs.length; i++){
//				if(poststr!="")poststr+="&";
//				poststr += objs.item(i).getAttribute("id") + "=" + escape(encodeURI(document.getElementById(objs.item(i).getAttribute("id")).value));
//			}
    var objs = document.getElementsByTagName("input");
    for(i=0; i < objs.length; i++){
      if(objs.item(i).getAttribute("type")=="checkbox"){
				var chk = document.getElementById(objs.item(i).getAttribute("id")).checked
        if(chk) {
	  if(poststr!="")poststr+="&";
	  poststr += objs.item(i).getAttribute("id") + "=" + escape(encodeURI(objs.item(i).value));
	}
      }
      else{
        if(poststr!="")poststr+="&";
         poststr += objs.item(i).getAttribute("id") + "=" + escape(encodeURI(objs.item(i).value));	
      }
    }


			var objs = document.getElementsByTagName("select");
			for(i=0; i < objs.length; i++){
				if(poststr!="")poststr+="&";
				var iix = document.getElementById(objs.item(i).getAttribute("id")).selectedIndex;
        poststr += objs.item(i).getAttribute("id") + "=" + escape(encodeURI(document.getElementById(objs.item(i).getAttribute("id")).options[iix].value));
			}
		}
		// if(hideprogress)alert(poststr);
		if(!hideprogress)$('results').innerHTML='<p align="center" style="margin:100px;"><img src="/res/js/mootools/modalwin/ajax-loader.gif" /></p>';
		makePOSTRequest('/background.htm', poststr);
  }
	function getPage(id) {
		if(id!=undefined){
			document.getElementById("pos").value = id;
		}

		if(document.getElementsByTagName) {
			var poststr = "";
			var inputs = new Array("input","select");

			var objs = document.getElementsByTagName("input");
			for(i=0; i < objs.length; i++){
				if(poststr!="")poststr+="&";
				poststr += objs.item(i).getAttribute("id") + "=" + escape(encodeURI(document.getElementById(objs.item(i).getAttribute("id")).value));
			}
			var objs = document.getElementsByTagName("select");
			for(i=0; i < objs.length; i++){
				if(poststr!="")poststr+="&";
				var iix = document.getElementById(objs.item(i).getAttribute("id")).selectedIndex;
        poststr += objs.item(i).getAttribute("id") + "=" + escape(encodeURI(document.getElementById(objs.item(i).getAttribute("id")).options[iix].value));
			}
		}
		$('results').innerHTML='<p align="center" style="margin:100px;"><img src="/res/js/mootools/modalwin/ajax-loader.gif" /></p>';
		window.location.href='guida_alloggi.htm?'+poststr;
  }



