function iotbs() {
	switcher = new switchManager();
};

var switcher;

//setup initialisation function
//.. gecko, safari, konqueror and generic
if(typeof window.addEventListener != 'undefined') {
	window.addEventListener('load', iotbs, false);
}
//.. opera 7
else if(typeof document.addEventListener != 'undefined') {
	document.addEventListener('load', iotbs, false);
}
//.. win/ie
else if(typeof window.attachEvent != 'undefined') {
	window.attachEvent('onload', iotbs);
}


//preferences manager
function switchManager() {
	//string for storing the overall custom classname
	//I was originally storing it in the body class name directly
	//but 1.7+ mozilla builds were not honouring the trailing whitespace we need
	this.string  = '';

	//store reference to body element
	this.body = document.getElementsByTagName('body')[0];

	//store the initial classname
	this.initial = this.body.className;

	//if the default classname is empty, add "iotbs"
	//because we need there to be at least one classname already -
	//the leading and trailing space in each custom classname is required,
	//but you can't set the body classname as " something" (beginning with a leading space)
	//because that may not work in Opera 7
	if(this.initial == '') {
		this.initial = 'itobs';
	}

	//look for a stored cookie
	this.cookie = this.read();

	//if it exists
	if(this.cookie != null) {
		//store cookie value to string
		this.string = this.cookie;

		//set new body class name
		this.body.className = this.initial + ' ' + this.string;
	}

	//*** dev
	//document.title = '<' + this.body.className.replace(/ /g,'+') + '>   [' + this.string.replace(/ /g,'+') + ']';
};

//set a cookie method
switchManager.prototype.set = function(days) {
	//format expiry date
	this.date = new Date();
	this.date.setTime(this.date.getTime() + ( days *24*60*60*1000));

	//store the string, replacing spaces with '#' so that leading spaces are preserved
	this.info = this.string.replace(/ /g,'#');

	//if the value is empty, set its expiry in the past to delete the cookie
	if(this.info == '') { this.date.setTime(0); }

	//create the cookie
	document.cookie = 'bodySwitcher=' + this.info
		+ '; expires=' + this.date.toGMTString()
		+ '; path=/';
};


//read a cookie method
switchManager.prototype.read = function() {
	//set null reference so we always have something to return
	this.cookie = null;

	//if a cookie exists
	if(document.cookie) {
		//if it's our cookie
		if(document.cookie.indexOf('bodySwitcher')!=-1) {
			//extract and store relevant information (turning '#' back into spaces)
			this.cookie = document.cookie.split('bodySwitcher=');
			this.cookie = this.cookie[1].split(';');
			this.cookie = this.cookie[0].replace(/#/g,' ');
		}
	}
	return this.cookie;
};


function changetoDefault() {
	switcher.string = 'default'
	switcher.body.className = " iotbs  ";
	switcher.set(365);
}

function changetoMedium() {
	switcher.string = 'medium';
	switcher.body.className = " iotbs  " + switcher.string +' ';
	switcher.set(365);
}

function changetoLarge() {
	switcher.string = 'large';
	switcher.body.className = " iotbs  " + switcher.string +' ';
	switcher.set(365);
}


function popup(URL, popWidth, popHeight, popLeft, popTop, autoCenter) {
	day = new Date();
	id = day.getTime();
	if (autoCenter == 1) {
		var popLeft = (screen.width - popWidth) / 2;
		var popTop = (screen.height - popHeight) / 2;
	}
	eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+popWidth+",height="+popHeight+",left="+popLeft+",top="+popTop+"');");
}


function checkEmail(thisForm) {
	missinginfo = "";

	if ((thisForm.email.value <= 0) ||
	(thisForm.email.value.indexOf('@') == -1) ||
	(thisForm.email.value.indexOf('.') == -1)) {
	missinginfo += "Please enter a valid email address";
		}

	if (missinginfo != "") {
	alert(missinginfo);
	return false;
		}
	else return true;
}

function extendBox(boxID)
{
	var thisAppVersion = navigator.appVersion;
	if(document.all && !window.opera && document.getElementById("frmSimpleSearch"))
	{
		var sbox = document.getElementById(boxID);
		sbox.onfocus = function() {this.className='jsfocus'; selectClicked = true;ie6ExtendCheck()};
		sbox.onblur = function() {this.className='jsblur'; selectClicked = false;ie6ExtendCheck()};
		sbox.onmouseover = function() {selectClicked = false; this.className='jsfocus';ie6ExtendCheck()};
		sbox.onmouseout = function() {if(!selectClicked){this.className='jsblur';}ie6ExtendCheck()};
		sbox.onchange = function() {this.className='jsblur'; selectClicked = false;ie6ExtendCheck()};
		sbox.onclick = function() {selectClicked = true;};
	}
	
	var today = new Date();
	var y=today.getFullYear();
	var m=today.getMonth()+1;
	var d=today.getDate();
	var h=today.getHours();
	if(d == "6" && m == "12" && y == "2008" && h >= 10 && h < 14 && document.getElementById("c_form_padding"))
	{
		document.getElementById("c_form_padding").innerHTML = "The Folio Hotels online booking facility is temporarily unavailable. <br />Please call 0844 855 9141 and our Reservations Team will be happy to help you and confirm your booking.";
		document.getElementById("c_form_padding").className = "alertBox";
	}

	
	//bookingformselect();
}


function ie6ExtendCheck()
{
	var thisAppVersion = navigator.appVersion;
	var appNumber = thisAppVersion.substring(thisAppVersion.indexOf("MSIE ")+5,thisAppVersion.indexOf("MSIE ")+6);
	
	
	if(appNumber < 7)
	{
		var extended = document.getElementById('selPropertyID');
		if(extended.className == 'jsfocus')
		{
			extended.style.height = '500px';
		}
		else
		{
			extended.style.height = 'auto';
		}
	}
}

document.write('<style type="text/css">.folio_table { display:none; }</style>');

function dropmenu(menuItem) {
	var clickedLI = menuItem.parentNode.parentNode;
	var nextClass = "over"
	if(clickedLI.className.indexOf("over") >= 0) { nextClass="down"; }
	var parentUL = menuItem.parentNode.parentNode.parentNode;
	for(i=0;i<parentUL.childNodes.length;i++)
	{
		if(parentUL.childNodes[i].nodeName == "LI")
		{
			parentUL.childNodes[i].className = parentUL.childNodes[i].className.replace("over", '');
			if(parentUL.childNodes[i].className.indexOf("down") < 0)
				parentUL.childNodes[i].className += " down";
			for(j=0;j<parentUL.childNodes[i].childNodes.length;j++)
			{
				if(parentUL.childNodes[i].childNodes[j].nodeName == "DIV" && parentUL.childNodes[i].childNodes[j].className == "folio_table")
				{
					if(parentUL.childNodes[i].childNodes[j].style.display == "block")
					{
						hiding = true;
						hidingDiv = parentUL.childNodes[i].childNodes[j];
						hidetargetHeight = hidingDiv.offsetHeight;
						parentUL.childNodes[i].childNodes[j].style.height = hidetargetHeight + "px"
						parentUL.childNodes[i].childNodes[j].style.overflow = "hidden"; 
						hideDiv(hidingDiv, hidetargetHeight, 5);
					}
				}
			}
		}
	}
	if(nextClass == "over" && clickedLI.className.indexOf("down") < 0)
		clickedLI.className = clickedLI.className.replace(" down", '');
	else
		clickedLI.className = clickedLI.className.replace(" over", '');
	clickedLI.className += " " + nextClass;
	if(clickedLI.className.indexOf("over") >= 0)
	{
		for(i=0;i<clickedLI.childNodes.length;i++)
		{
			if(clickedLI.childNodes[i].nodeName == "DIV" && clickedLI.childNodes[i].className == "folio_table")
			{
				activeDiv = clickedLI.childNodes[i];
				clickedLI.childNodes[i].style.display = "block";
				showtargetHeight = clickedLI.childNodes[i].offsetHeight - 14;
				clickedLI.childNodes[i].style.overflow = "hidden";
				clickedLI.childNodes[i].style.height = "0px";
				revealDiv(activeDiv, showtargetHeight, 5);
			}
		}
	}
}

var activeDiv;
function revealDiv(myDiv, myHeight, timer)
{
	if(!hiding)
	{
		myDiv.style.display = "block";
		if(myDiv.offsetHeight < myHeight)
		{
			var currentHeight = myDiv.style.height;
			currentHeight = currentHeight.substring(currentHeight, (currentHeight.length-2));
			nextHeight = parseInt(currentHeight) + (myHeight / 8);
			if(nextHeight > myHeight)
			{
				myDiv.style.height = "100%";
				myDiv.style.overflow = "visible";
			}
			else
			{
				myDiv.style.height = nextHeight + "px";
				setTimeout("revealDiv(activeDiv, "+myHeight+", "+timer+")", timer);
			}
		}
		else
		{
			myDiv.style.height = "100%";
			myDiv.style.overflow = "visible";
		}
	}
	else
	{
		myDiv.style.display = "none";
		setTimeout("revealDiv(activeDiv, "+myHeight+", "+timer+")", timer);
	}
}

var hidingDiv;
var hiding = false;
function hideDiv(myDiv, hideHeight, timer)
{
	if(myDiv.offsetHeight > 0)
	{
		var currentHeight = myDiv.style.height;
		currentHeight = currentHeight.substring(currentHeight, (currentHeight.length-2));
		nextHeight = parseInt(currentHeight) - (parseInt(hideHeight) / 8);
		if(nextHeight < 0)
		{
			myDiv.style.display = "none";
			myDiv.style.height = "auto";
			hiding = false;
		}
		else
		{
			myDiv.style.height = nextHeight + "px";
			setTimeout("hideDiv(hidingDiv, "+hideHeight+", "+timer+")", timer);
		}
	}
	else
	{
		myDiv.style.display = "none";
		myDiv.style.height = "auto";
		hiding = false;
	}
}

function randomise(elementArray) {
	var randNum = Math.floor(Math.random() * elementArray.length);
	
	
	for(i=0;i<elementArray.length;i++)
	{
		if(i != randNum)
		{
			document.getElementById(elementArray[i]).style.display = 'none';
		}
	}

}