/* ================================================================ 
This copyright notice must be untouched at all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/various/more.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */


clickMenu = function(menu,element,cname) {
	if(document.getElementById(menu))
	{
		var getEls = document.getElementById(menu).getElementsByTagName(element);
	
		for (var i=0; i<getEls.length; i++) {
				getEls[i].onclick=function() {
				if ((this.className.indexOf(cname))!=-1)
				{
				if ((this.className.indexOf('click'))!=-1) {
					this.className=this.className.replace("click", "");;
					}
					else {
					this.className+=" click";
					}
				}
			}
		}
	}
}

/* *********************************************************
* You may use this code for free on any web page provided that 
* these comment lines and the following credit remain in the code.
* Floating Div from http://www.javascript-fx.com
********************************************************  */

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}

function showHideElement(elid) {
	var divSPEls = ['SP-01','SP-02','SP-03','SP-04','SP-05','SP-06','SP-07'];
	var element = document.getElementById(elid);
	
	if(element)
	{
		if(element.style.display == "none")
		{
			element.style.display = "block";
			showNote('spnote');
		}
		else
		{
			element.style.display = "none";
			for(var i=0;i<divSPEls.length;i++)
			{				
				var sprEl = document.getElementById(divSPEls[i]);
				if(sprEl.style.display == "block")
					break;
				else
				{
					//check if this is the last element
					if(i == (divSPEls.length-1))
						hideNote('spnote');
				}
			}
		}
	}
		
}

function showNote(note) {
	var noteEl = document.getElementById(note);
	if(noteEl)
		if(noteEl.style.display == "none")
			noteEl.style.display = "block";
}

function hideNote(note) {
	var noteEl = document.getElementById(note);
	if(noteEl)
		if(noteEl.style.display == "block")
			noteEl.style.display = "none";
}

function showHideDiv(divid) {
	var element = document.getElementById(divid);

	if(element)
	{
		if(element.style.display == "none")
		{
			element.style.display = "block";
		}
		else
		{
			element.style.display = "none";
		}
	}
		
}

function rotateImages(element)
{
	var topEl = document.getElementById(element);
	if(topEl)
	{
		topEl.style.background = "url('" + getHeaderImage() + "')";
		var recur_call = "rotateImages('"+element+"')";
		setTimeout(recur_call, 3000);
	}	
}
var imgIndex = -1;
function getHeaderImage()
{
	var header_images = new Array(3);
	header_images[0] = "images/headers/beach.jpg";
	header_images[1] = "images/headers/hb.jpg";
	header_images[2] = "images/headers/flowers.jpg";
	
	var randomIndex = ++imgIndex;
	if(randomIndex == 2)
		imgIndex = -1;	
	return header_images[randomIndex];	
}

function generate(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}

function openNewWindow(url) {
	window.open(url, 'win',
	'width=500, height=500,menubar=no,scrollbars=yes');
}
