// Show or Hide layer
// Copyright 2006 Bontrager Connection, LLC

var cX = 0; var cY = 0;

function UpdateCursorPosition(e) { 
	cX = e.pageX; 
	cY = e.pageY;
}
function UpdateCursorPositionDocAll(evt) { 
	cX = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	cY = event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}
if(document.all) { 
	
	document.onmousemove = UpdateCursorPositionDocAll; 
	//windows
}
else { 
	document.onmousemove = UpdateCursorPosition; 
	//mac
}
function AssignPosition(d) {
	if((cX-550)<0) { 
		cX = 15; 
		d.style.left = cX + "px";
	} else {
		d.style.left = (cX-550) + "px";
	}
	d.style.top = (cY-75) + "px";
}
function HideContent(d) {
	if(d.length < 1) { 
		return; 
	}
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) {
		return; 
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { 
		return; 
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") { 
		dd.style.display = "block"; 
	} else { 
		dd.style.display = "none"; 
	}
}

// Loading external page in iFrame
function loadExternal(url,layer) {
	if ( window.frames['buffer'] ) {
		window.frames['buffer'].location = url;
		ShowContent('display');
		var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;
		if ( lyr && typeof lyr.innerHTML != "undefined" ) {
			lyr.innerHTML = '<img src="/image/loading.gif" alt="" class="loading">';
		}
		return false;
	} 
	return true; // other browsers follow link
}

// called when documents loaded into iframe (from their body's onload attribute)
function displayExternal() {
	var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;
		if ( window.frames['buffer'] && lyr && typeof lyr.innerHTML != "undefined" ) {
			lyr.innerHTML = window.frames['buffer'].document.body.innerHTML;
		}
}




// Google Maps + custom icons

var map;

function doMap(hotels,center) {
	var icon0 = new GIcon();
	icon0.image = "http://www.go-reservation.com/image/mh.gif";
	icon0.iconSize = new GSize(18, 17);
	icon0.iconAnchor = new GPoint(9, 8);
	icon0.infoWindowAnchor = new GPoint(9, 1);
	
	var icon1 = new GIcon();
	icon1.image = "http://www.go-reservation.com/image/mhactive.gif";
	icon1.iconSize = new GSize(18, 17);
	icon1.iconAnchor = new GPoint(9, 8);
	icon1.infoWindowAnchor = new GPoint(9, 1);
	
	var icon2 = new GIcon();
	icon2.image = "http://www.go-reservation.com/image/ml.gif";
	icon2.iconSize = new GSize(15, 14);
	icon2.iconAnchor = new GPoint(1, 14);
	icon2.infoWindowAnchor = new GPoint(9, 1);
	
	var icon3 = new GIcon();
	icon3.image = "http://www.go-reservation.com/image/mlactive.gif";
	icon3.iconSize = new GSize(15, 14);
	icon3.iconAnchor = new GPoint(1, 14);
	icon3.infoWindowAnchor = new GPoint(9, 1);

	map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng( hotels[center][0] , hotels[center][1] ), 15);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());  
	map.addControl(new GOverviewMapControl()); 
	markersArr = new Array();
	
	var i = 0;
	var ic;
	for(x in hotels) {
		switch (hotels[x][3]) {
			case 0:
				ic = icon0;
				break;
			case 1:
				ic = icon1;
				break;
			case 2:
				ic = icon2;
				break;
			case 3:
				ic = icon3;
				break;
		}
		
		
		
		setMarker(new GLatLng( hotels[x][0] , hotels[x][1]), hotels[x][2], x, ic );
	}
}

function setMarker(point, content, i, icon) {
	var marker = new GMarker(point,icon);
	markersArr[i] = marker;
	map.addOverlay(marker);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(unescape(content));
	});
}

function focusMap(markerId) {
	GEvent.trigger(markersArr[markerId], 'click');
}   








// do layer toggle (show/hide)

function doPictureInit() {
	document.write('<img src="'+thePictures[0]+'" name="picture" class="photo">')
}

function doPictureChange(i,reference) {
	document.images.picture.src = thePictures[i];
	reference.className="image"
}
	
function hideEl(el) {
	if (document.getElementById){
		document.getElementById(el).style.display = 'none';
	}
}

function showEl(el) {
	if (document.getElementById){
		document.getElementById(el).style.display = 'block';
	}
}

if (document.getElementById) {
  document.write("<style type='text/css'>");
  document.write(".blocktoggle {display: none}");
  document.write("</style>");
  var shown = new Array();
}

function blocktoggle(i) {
  if (document.getElementById) {
	shown[i] = (shown[i]) ? false : true;
	currentdisplay = (shown[i]) ? 'block' : 'none';
	document.getElementById('blocktoggle'+i).style.display = currentdisplay;
  }
}
		
	