
// Create New Element if Exists
function newElement(element) {
	return (document.getElementById(element) ? document.getElementById(element) : false) ;
}


// Preload Images
function sugarPreload(input) { 
  document.imageArray = new Array(input.length);
  for (var i=0; i<input.length; i++) {
	 document.imageArray[i] = new Image;
	 document.imageArray[i].src = "/images/nav-" + input[i] + "-over.gif";
  }
}


// Swap Image States
function sugarImageSwap(element,names) {

	sugarPreload(names);
	
	if (document.getElementById(element)) {
		var theMenu = document.getElementById(element);

		for (var i=0; i<theMenu.getElementsByTagName("A").length; i++) {
			var node = theMenu.getElementsByTagName("A")[i];
			node.onmouseover = function() {
				this.getElementsByTagName("IMG")[0].src=this.getElementsByTagName("IMG")[0].src.replace("up","over");
			}
			node.onfocus = function() {
				this.getElementsByTagName("IMG")[0].src=this.getElementsByTagName("IMG")[0].src.replace("up","over");
			}
			node.onmouseout = function() {
				this.getElementsByTagName("IMG")[0].src=this.getElementsByTagName("IMG")[0].src.replace("over","up");
			}
			node.onblur = function() {
				this.getElementsByTagName("IMG")[0].src=this.getElementsByTagName("IMG")[0].src.replace("over","up");
			}
			node.onclick = function() { window.location.href=this.href; }
		}
	}
}



// Create a New Object
function sugarPacket(element,tag,theClass,onClick) {
	this.element = element;
	this.tag = tag;
	this.theClass = theClass;
	this.onclick = onClick;
}



// Swap Element's Class
function swapClass() {
	with (this) {
		if (document.getElementById(element)) {
			element = document.getElementById(element);
			for (var i=0;i!=element.getElementsByTagName(tag).length;i++) {
				object = element.getElementsByTagName(tag)[i];
				if (object.className == 'skip') continue;
				object.onmouseover = function() { this.className += theClass; }
				object.onmouseout = function() { this.className = this.className.replace(theClass,''); }
				object.onclick = onclick;
			}
		}	
	}
}



sugarPacket.prototype.swapClass = swapClass;



window.onload = function() {
	
	if (!document.getElementById || !document.getElementsByTagName) { return false; }

	document.imageArray = new Array();
	document.imageArray[1] = new Image;
	document.imageArray[1].src = "/images/button_orange_twoline_on.gif";
	document.imageArray[2] = new Image;
	document.imageArray[2].src = "/images/button_orange_twoline_off.gif";

	// Photo Swapper
	var photo_list = newElement("photoList");
	if (photo_list) {
		for (i=0;i<photo_list.getElementsByTagName("LI").length;i++) {
			photo_list.getElementsByTagName("LI")[i].onclick = function() {
				photo_list.style.backgroundImage = "url(/images/bdy-home" + this.firstChild.data.replace(' ','') + ".jpg)";
			}
		}
	}



	// Calendar Popups
	var theForm = newElement("reservations");
	var arrive_calendar = newElement("arrCal");
	var depart_calendar = newElement("depCal");
	
	if (arrive_calendar) {
		arrive_calendar.onclick = function() {
			day = theForm.arrivalDay.value;
			jump = theForm.arrivalMonthYear.selectedIndex;
			theWidth = "210"; theHeight = "180"; theScroll = "no";
			window.open(this.href + "&j=" + jump + "&d=" + day,"popcal","top=" + (screen.availHeight-theHeight)/2 + ",left=" + (screen.availWidth-theWidth)/2 + ",width=" + theWidth + ",height=" + theHeight + ",scrollbars=" + theScroll);
			return false;
		}
	}

	if (depart_calendar) {
		depart_calendar.onclick = function() {
			day = theForm.departureDay.value;
			jump = theForm.departureMonthYear.selectedIndex;
			theWidth = "220"; theHeight = "175"; theScroll = "yes";
			window.open(this.href + "&j=" + jump + "&d=" + day,"popcal","top=" + (screen.availHeight-theHeight)/2 + ",left=" + (screen.availWidth-theWidth)/2 + ",width=" + theWidth + ",height=" + theHeight + ",scrollbars=" + theScroll);
			return false;
		}
	}
	
	return true;
}