/*-- * FORM: form_map_show.js * --*/

/* Global variables. */
var blinkflag, blinkhandle, otmp, popup, show_hotels, hide_hotels;

/* |*********************|
   | function hotelblink |
   |*********************| */

/*  Declaration about the function that, testing the variable */
/*  'blinkflag', give us the way to make the points blinking. */
function hotelblink() {
	if (blinkflag) otmp.style.backgroundImage = "url(cmn/img/form/maps/left-layer-bkg.gif)";
	else otmp.style.backgroundImage = "url(cmn/img/form/maps/left-layer-bkg-roll.gif)";
	blinkflag = !blinkflag;
}

/* |*******************|
   | function puntiagg |
   |*******************| */

/* Declaration about the function that, at the load end of   */
/* the page, allow us to set the position of a single hotel  */
/* (in the popup view) or of all hotels' positions (in the   */
/* not-popup view). In case of popup view it also check that */
/* hotel description remain inside the popup.                */
function puntiagg() {
	var ob = document.getElementById('img_container');
	var padding = 0;
	var onom, otog, tog_width;
	var overwright = 5;
	
	if(popup){
		var width = parseInt(ob.getAttribute("width"),10);
		var height = parseInt(ob.getAttribute("height"),10);
		ob.style.width = width + "px";
		ob.style.height = height + "px";
		otmp = document.getElementById('punto_unique');
		otmp.style.left =  otmp.offsetLeft +  ob.offsetLeft + 'px';
		otmp.style.top  =  otmp.offsetTop  +  ob.offsetTop + 'px';
		otmp.style.zIndex = 10;
		onom = document.getElementById('pnome_unique');
		padding = onom.offsetHeight / 2 - otmp.offsetHeight / 2;
		onom.style.left =  onom.offsetLeft +  ob.offsetLeft +  otmp.offsetWidth - overwright + 'px';
		onom.style.top  =  onom.offsetTop  +  ob.offsetTop - padding  + 'px';
		onom.style.zIndex = 1;
		
		if(document.all)window.resizeTo((width + 30), (height + 150));
		else window.resizeTo((width + 30), (height + 115));
			
		if ((otmp.offsetLeft + (otmp.offsetWidth - overwright) + onom.offsetWidth) > getWidth()) {
		    	Xoffset = overwright -(onom.offsetWidth); 
		} 
		else {
			Xoffset = otmp.offsetWidth - overwright;
		}
		
		if((onom.offsetTop + onom.offsetHeight) > (ob.offsetTop + ob.height)){
			Yoffset = -(onom.offsetHeight / 2);
		}
		else{
			Yoffset = 0;
		}
		
		onom.style.left = otmp.offsetLeft + Xoffset + 'px';
		onom.style.top = otmp.offsetTop - padding + Yoffset + 'px';
		
		if (navigator.appName.indexOf("Microsoft")!=-1){
	 		window_width = parseInt(parent.document.body.offsetWidth,10);
  			window_height = parseInt(parent.document.body.offsetHeight,10);
 		}
		else{
			window_width = parseInt(parent.window.innerWidth,10);
  			window_height = parseInt(parent.window.innerHeight,10);
		}
		
		window.document.title = title;
		if(opener.getHeight) positionY = Math.floor((parseInt(opener.getHeight(),10) - height)/2);
		else positionY = 500;
		if(opener.getWidth) positionX = Math.floor((parseInt(opener.getWidth(),10) - width)/2);
		else positionX = 500;
		window.moveTo(positionX,positionY);
		blinkflag = 0;
		blinkhandle = window.setInterval("hotelblink()",250);
	}
	else{
		var i, s;
		ob = document.getElementById('mappazona');
		for (i = 1; otmp = document.getElementById('punto_' + i); i++) {
			otmp.style.left = otmp.offsetLeft + ob.offsetLeft + 'px';
			otmp.style.top  = otmp.offsetTop + ob.offsetTop + 'px';
			otmp.style.visibility = 'visible';
			onom = document.getElementById('pnome_' + i);
			padding = onom.offsetHeight / 2 - otmp.offsetHeight / 2;
			onom.style.left = onom.offsetLeft + ob.offsetLeft + otmp.offsetWidth - overwright + 'px';
			onom.style.top  = onom.offsetTop + ob.offsetTop - padding  + 'px';
			otog = document.getElementById('map_toggle');
		}
		if(all_hotels){
			otog.value = show_hotels;
			tog_width = otog.offsetWidth + 'px';
			otog.value = hide_hotels;
			otog.style.width = tog_width;
			otog.style.visibility = 'visible';
		}
		else{
			otog.value = hide_hotels;
			tog_width = otog.offsetWidth + 'px';
			otog.style.width = tog_width;
			otog.style.visibility = 'visible';
		}
	}
}

/* |**********************|
   | function hotelselect |
   |**********************| */

/* Declaration about the function that has the task to       */
/* managing the blinking of all hotels in the not-popup view.*/

function hotelselect(i, f) {
	otmp = document.getElementById('punto_' + i);
	ohri = document.getElementById('hriga_' + i);
	onom = document.getElementById('pnome_' + i);
	
	var width, height, Xoffset, Yoffset;
	var padding = 0;
	var overwright = 5;
	
	if (f) {
		otmp.style.zIndex = 11;
		width = otmp.offsetWidth;
		height = otmp.offsetHeight;
		
		otmp.style.backgroundImage = "url(cmn/img/form/maps/left-layer-bkg-roll.gif)";
		ohri.style.backgroundColor = '#f2ebe3';
		ohri.style.color = 'white';
	
		if ((otmp.offsetLeft < (getWidth()+getScrollLeft())) &&
		    ((otmp.offsetLeft + (otmp.offsetWidth - overwright) + onom.offsetWidth) >= (getWidth()+getScrollLeft()))) {
			Xoffset = overwright -(onom.offsetWidth); 
		} 
		else {
			if ((otmp.offsetLeft + otmp.offsetWidth) < getScrollLeft()){
				Xoffset = -((width + 1) + onom.offsetWidth + 1); 
			} 
			else {
				Xoffset = width - overwright;
			}
		}
		
		padding = onom.offsetHeight / 2 - otmp.offsetHeight / 2;
		
		if ((onom.offsetTop < getScrollTop()) && (otmp.offsetTop+height > getScrollTop())){
			Yoffset =  height + padding;
		}
		else {
			if(onom.offsetTop < getScrollTop()){
				Yoffset = -(onom.offsetHeight);
			}
			else{
				Yoffset = 0;
			}
		}
		
		onom.style.left = otmp.offsetLeft + Xoffset + 'px';
		onom.style.top = otmp.offsetTop - padding + Yoffset + 'px';
		
		onom.style.visibility = 'visible';
		onom.style.zIndex = 10;
		blinkflag = 1;
		blinkhandle = window.setInterval(hotelblink, 250);
	} else {
		window.clearInterval(blinkhandle);
		otmp.style.zIndex = 1;
		width = otmp.offsetWidth;
		height = otmp.offsetHeight;
		
		padding = onom.offsetHeight / 2 - otmp.offsetHeight / 2;
		otmp.style.backgroundImage = "url(cmn/img/form/maps/left-layer-bkg.gif)";
		ohri.style.backgroundColor = 'white';
		ohri.style.color = 'black';
		
		onom.style.left = otmp.offsetLeft + width + 'px';
		onom.style.top = otmp.offsetTop - padding  + 'px';
		onom.style.visibility = 'hidden';
		onom.style.zIndex = 0;
	}
}

/* |***********************|
   | function toggle_hotel |
   |***********************| */

/* Declaration about the function that has the task to hide   */
/* or show all the hotels' positions and hotels' informations.*/

function toggle_hotel() {
	var oimg = document.getElementById('mappazona');
	var oimgtxt = document.getElementById('map_toggle');
	if (oimg.style.zIndex == 5){ 
		oimg.style.zIndex = 0;
		oimgtxt.value = hide_hotels;
	}
	else {
		oimg.style.zIndex = 5;
		oimgtxt.value = show_hotels;
	}
}

/* This piece of code allow us to execute the function 'puntiagg' */
/* with each type of browser. 					  */
if (typeof window.addEventListener != 'undefined') window.addEventListener('load', puntiagg, false);// gecko, safari, konqueror and standard
else if (typeof document.addEventListener != 'undefined') document.addEventListener('load', puntiagg, false);// opera 7
else if (typeof window.attachEvent != 'undefined') window.attachEvent('onload', puntiagg);// win/ie

