/**************************************************************************************************/
/***
/***	ZIONCAMP.COM JAVASCRIPT DOCUMENT
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2006-2008 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	All Rights Reserved. Any use of these functions & scripts without written consent is prohibited.
/***
/**************************************************************************************************/

/*                                   **************************                                   */
/************************************   INITIALIZE VARIABLES   ************************************/
/*                                   **************************                                   */
var directory = "http://www.zioncamp.com";
var images_for_preload_array = new Array('rvresort','qualityinn','montclairvillas','reservations','amenities','rates','faqs','rvpark_gallery','qualityinn_gallery','montclair_gallery','zion_gallery');
var preloaded_images_array = new Array();
var mouse_over_images_array = new Array("navigation1");
var mouse_over_div_array = new Array("gallery1","gallery2","gallery3","gallery4");
var browser = getBrowserType();
var platform = getPlatformType();
var body_minimum_height = 382;
var elements_for_resize = new Array(new Array("border_shadow_left","height"),new Array("border_shadow_right","height"),
									 new Array("gallery","height"),new Array("quote","top"),new Array("footer","top"),
									 new Array("body_background","height"));
/*                                   **************************                                   */
/************************************     TERNSTYLE LOGIN      ************************************/
/*                                   **************************                                   */
function goToLogin()
{
	var this_loc = location.href;
	this_loc = this_loc.substr(this_loc.indexOf("http://")+8);
	this_loc = this_loc.substr(this_loc.indexOf("/")+1);
	this_loc = this_loc.length == 0 ? "index.html" : this_loc;
	location.replace("http://www.zioncamp.com/TERNSTYLE_SL/login.php?directory="+this_loc);
}
/*                                   **************************                                   */
/************************************    BROWSER FUNCTIONS     ************************************/
/*                                   **************************                                   */
function getBrowserType()
{
	var browser_array = new Array("MSIE","NETSCAPE","FIREFOX","SAFARI");
	for(i=0;i<browser_array.length;i++)
	{
		var browserReg = new RegExp(browser_array[i],"");
		if(browserReg.test(navigator.userAgent.toUpperCase()))
		{
			var browser = browser_array[i];
			break;
		}
		else
		{
			var browser  = "other";
		}
	}
	return browser;
}
function getPlatformType()
{
	var platform_array = new Array("WINDOWS","MAC");
	for(i=0;i<platform_array.length;i++)
	{
		var platformReg = new RegExp(platform_array[i],"");
		if(platformReg.test(navigator.userAgent.toUpperCase()))
		{
			var platform = platform_array[i];
			break;
		}
		else
		{
			var platform  = "other";
		}
	}
	return platform;
}
/*                                   **************************                                   */
/************************************     WINDOW FUNCTIONS     ************************************/
/*                                   **************************                                   */
function openWindow(thisUrl,thisName,width,height)
{
	var thisFeatures = 'width='+width+',height='+height+'scrollbars=yes,resizeable=yes';
	if(winName = window.open(thisUrl,thisName,thisFeatures))
	{
		winName.moveTo((screen.availWidth-width)/2,0);
	}
	else
	{
		alert('There has been an error opening this window. Is your browser blocking pop-ups?');
	}
}
/*                                   **************************                                   */
/************************************    TEMPLATE FUNCTIONS    ************************************/
/*                                   **************************                                   */
function resizePage()
{
	var page_body_height = getElementSize(document.getElementById("page_body"))[1];
	if(body_minimum_height < page_body_height)
	{
		var resize_height = (page_body_height - body_minimum_height);
		document.getElementById("page_body").style.height = page_body_height;
		var style_sheet = getStyleSheet(0);
		var style_rules = getStyleRules(style_sheet);
		for(var i=0;i<style_rules.length;i++)
		{
			var this_rule = cleanSelectorText(style_sheet,style_rules[i].selectorText);
			for(var a=0;a<elements_for_resize.length;a++)
			{
				if(this_rule == elements_for_resize[a][0] ||
				   (this_rule.indexOf("HTML > BODY") != -1 && this_rule.replace("HTML > BODY ","") == elements_for_resize[a][0] && browser != "MSIE"))
				{
					eval("var rule_style = style_rules[i].style."+elements_for_resize[a][1]);
					eval("document.getElementById('"+elements_for_resize[a][0]+"').style."+elements_for_resize[a][1]+" = (parseInt(rule_style) + resize_height) + 'px';");
				}
			}
		}
	}
}
/*                                   **************************                                   */
/************************************         PRELOADER        ************************************/
/*                                   **************************                                   */
function preloadImages()
{
	for(var i=0;i<images_for_preload_array.length;i++)
	{
		var preloaded_length = preloaded_images_array.length;
		preloaded_images_array[preloaded_length] = new Image;
		preloaded_images_array[preloaded_length].src = "/IMAGES/" + images_for_preload_array[i] + "_over.jpg";
	}
}
/*                                   **************************                                   */
/************************************      EVENT LISTENING     ************************************/
/*                                   **************************                                   */
function openMouseOverListening()
{
	//image mouse overs and tooltips
	var images_array = document.getElementsByTagName("img");
	for(var i=0;i<mouse_over_images_array.length;i++)
	{
		for(var a=0;a<images_array.length;a++)
		{
			if(isInNode(images_array[a],mouse_over_images_array[i]))
			{
				var this_image = images_array[a];
				if(images_array[a].title.length > 0)
				{
					images_array[a].onmouseover = rollAndShowTooltip;
					images_array[a].onmouseout = rollAndHideTooltip;
				}
				else
				{
					images_array[a].onmouseover = doRollover;
					images_array[a].onmouseout = doRollover;
				}
			}
		}
	}
	//link and div tooltips
	var titles_array = mergeArrays(document.getElementsByTagName("div"),document.getElementsByTagName("a"));
	for(var i=0;i<titles_array.length;i++)
	{
		if(titles_array[i].title.length > 0)
		{
			titles_array[i].onmouseover = showTooltip;
			titles_array[i].onmouseout = hideTooltip;
		}
	}
}
function setEvent(e)
{
	this_event = !(e) ? window.event : e;
	return this_event;
}
function determineEventSource(e)
{
	if(browser == "MSIE")
	{
		var this_element = e.srcElement;
	}
	else
	{
		var this_element = e.target;
	}
	if(this_element.nodeType == 3)
	{
		this_element = this_element.parentNode;
	}
	return this_element;
}
/*                                   **************************                                   */
/************************************    MOUSEOVER FUNCTIONS   ************************************/
/*                                   **************************                                   */
function rollAndShowTooltip(e)
{
	e = setEvent(e);
	doRollover(e);
	showTooltip(e);
}
function rollAndHideTooltip(e)
{
	e = setEvent(e);
	doRollover(e);
	hideTooltip(e);
}
function doRollover(e)
{
	e = setEvent(e);
	var this_image = determineEventSource(e);
	if(this_image.src.indexOf("_over") == -1)
	{
		var source = this_image.src.replace(".jpg","_over.jpg");
	}
	else
	{
		var source = this_image.src.replace("_over.jpg",".jpg");
	}
	this_image.setAttribute("src",source);
}
/*                                   **************************                                   */
/************************************     CLASS FUNCTIONS      ************************************/
/*                                   **************************                                   */
function changeClass(whichElement,classname)
{
	if(typeof(whichElement) == "string")
	{
		if(classname.type == 'select-one')
		{
			classname = classname.options[classname.selectedIndex].value;
		}
		if(document.getElementById(whichElement).className = classname)
		{
			document.getElementById(whichElement).className = classname;
		}
		else
		{
			document.getElementById(whichElement).setAttribute('class',classname);
		}
	}
	else
	{
		if(classname.type == 'select-one')
		{
			classname = classname.options[classname.selectedIndex].value;
		}
		if(whichElement.className)
		{
			whichElement.className = classname;
		}
		else
		{
			whichElement.setAttribute('class',classname);
		}
	}
}
function hideElement(whichElement)
{
	if(document.getElementById)
	{
		document.getElementById(whichElement).style.visibility = 'hidden';
	}
	else
	{
		if(document.layers)
		{
			document.whichElement.visibility = 'hidden';
		}
		else
		{
			document.all.whichElement.style.visibility = 'hidden';
		}
	}
}
function showElement(whichElement)
{
	if(document.getElementById)
	{
		document.getElementById(whichElement).style.visibility = 'visible';
	}
	else
	{
		if(document.layers)
		{
			document.whichElement.visibility = 'visible';
		}
		else
		{
			document.all.whichElement.style.visibility = 'visible';
		}
	}
}
function changeOpacity(which_element,opacity)
{
	var this_element = document.getElementById(which_element);
	if(browser == "MSIE")
	{
		this_element.filters.alpha.opacity = opacity;
	}
	else
	{
		this_element.style.opacity = opacity/100;
	}
}
function setStyle(whichElement,style_property,style_value)
{
	if(style_property == "align")
	{
		whichElement.setAttribute("align",style_value);
	}
	else
	{
		if(whichElement.style[style_property])
		{
			whichElement.style[style_property] = style_value;
		}
		else if(browser == "MSIE")
		{
			eval("whichElement.style."+style_property+"='"+style_value+"'");
		}
		else if(whichElement.style.setProperty(style_property,style_value,null))
		{
			whichElement.style.setProperty(style_property,style_value,null);
		}
	}
}
function getStyle(whichElement,style_property)
{
	var this_value = false;
	//
	if(style_property == "align")
	{
		this_value = whichElement.getAttribute("align");
	}
	else
	{
		if(browser == "MSIE")
		{
			this_value = eval("whichElement.style."+style_property);
		}
		else if(whichElement.style[style_property])
		{
			this_value = whichElement.style[style_property];
		}
		else if(whichElement.style.getPropertyValue(style_property))
		{
			this_value = whichElement.style.getPropertyValue(style_property);
		}
	}
	//
	return this_value;
}
function getStyleSheet(index)
{
	if(document.styleSheets)
	{
		if(document.styleSheets[index].imports)
		{
			var style_sheet = document.styleSheets[index].imports[0];
		}
		else
		{
			var style_sheet = document.styleSheets[index].cssRules[0].styleSheet;
		}
	}
	else
	{
		var style_sheet = false;
	}
	return style_sheet;
}
function getStyleRules(style_sheet)
{
	if(style_sheet)
	{
		if(style_sheet.owningElement)
		{
			var style_rules = style_sheet.rules;
		}
		else
		{
			var style_rules = style_sheet.cssRules;
		}
	}
	else
	{
		var style_rules = false;
	}
	return style_rules;
}
function cleanSelectorText(style_sheet,selector_text)
{
	if(style_sheet.owningElement)
	{
		var this_text = selector_text.replace("#","");
	}
	else
	{
		var this_text = selector_text.replace('*[ID"',"").replace('"]',"").replace("#","").replace(".","");
	}
	return this_text;
}
/*                                   **************************                                   */
/************************************   NODE QUERY FUNCTIONS   ************************************/
/*                                   **************************                                   */
function isInNode(which_element,parent_node)
{
	var this_return = false;
	var this_node = document.getElementById(parent_node);
	if(which_element && which_element.parentNode != document.body)
	{
		if(which_element.parentNode == this_node)
		{
			this_return = true;
		}
		else
		{
			this_return = isInNode(which_element.parentNode,parent_node);
		}
	}
	return this_return;
}
function getChildIndex(child_node)
{
	var index = null;
	for(var i=0;i<child_node.parentNode.childNodes.length;i++)
	{
		if(child_node == child_node.parentNode.childNodes[i])
		{
			index = i;
			break
		}
	}
	return index;
}
function getElementSize(which_element)
{
	var this_size = new Array();
	if(which_element.innerWidth)
	{
		this_size[0] = which_element.innerWidth;
		this_size[1] = which_element.innerHeight;
	}
	else if(which_element.clientWidth)
	{
		this_size[0] = which_element.clientWidth;
		this_size[1] = which_element.clientHeight;
	}
	else if(which_element.offsetWidth)
	{
		this_size[0] = which_element.offsetWidth;
		this_size[1] = which_element.offsetHeight;
	}
	return this_size;
}
/*                                   **************************                                   */
/************************************      NODE FUNCTIONS      ************************************/
/*                                   **************************                                   */
function removeChildren(whichElement)
{
	if(typeof(whichElement) == "string")
	{
		whichElement = document.getElementById(whichElement);
	}
	if(whichElement.hasChildNodes)
	{
		var length = whichElement.childNodes.length;
		for(i=0;i<length;i++)
		{
			whichElement.removeChild(whichElement.childNodes[0]);
		}
	}
}
/*                                   **************************                                   */
/************************************     ARRAY FUNCTIONS      ************************************/
/*                                   **************************                                   */
function mergeArrays(array1,array2)
{
	var this_array = new Array();
	for(var i=0;i<array1.length;i++)
	{
		var array_length = this_array.length;
		this_array[array_length] = array1[i];
	}
	for(var i=0;i<array2.length;i++)
	{
		var array_length = this_array.length;
		this_array[array_length] = array2[i];
	}
	return this_array;
}
/*                                   **************************                                   */
/************************************     MOUSE FUNCTIONS      ************************************/
/*                                   **************************                                   */
function determineMousePosition(this_event)
{
	var mouse_position = new Array();
	if(this_event.pageX)
	{
		mouse_position[0] = this_event.pageX;
		mouse_position[1] = this_event.pageY;
	}
	else if (this_event.clientX)
	{
		mouse_position[0] = event.clientX + document.body.scrollLeft;
		mouse_position[1] = event.clientY + document.body.scrollTop;
	}
	else
	{
		mouse_position = false;
	}
	return mouse_position;
}