var loaded = false;

function setActiveStyleSheet(title,status) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  
  if (loaded==true && document.cookie.indexOf('style=') > -1) {
	showSwitcher();  
  }
}


function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	var OpenLiNode = null;
	loaded = true;
	setActiveStyleSheet(title);

  	// fires the tree navigation
  	var ul = document.getElementById('primaryMenu').firstChild;
	while (ul.nodeName != 'UL') { ul = ul.nextSibling; }
	ul.id = 'nav1';
	
	
//	if (location.href.indexOf("event.asp?id=215") != -1) {
//	GetCount();
//	}
	
	
	var lis = ul.childNodes;
	var addr = window.location.href;
	//alert(addr);
	for (i=0; i<lis.length; i++) { //loops through array of LI's inside outer UL
		if (lis[i].nodeType!=3) {
			var el = lis[i].childNodes;
			for (x=0; x<el.length; x++) { //loops through any children that each LI may have!
				//alert(el[x].nodeName);
				if (el[x].nodeType!=3 && el[x].nodeName == 'UL') { //If the LI has a UL child node then we want to start another loop
					var childLi = el[x].childNodes; // gets the LI's inside the INNER UL
					for (z=0; z<childLi.length; z++) { //Loop through thr INNER LI's and gets the A HREF attribute (Assuming the firstChild is NOT null)
						var a = childLi[z].firstChild;
						if (a!=null) {
							if (addr==a.href){ 
							//we know now which element we want to keep open, as the href value inside the a tag is the same as in the browser window!
								OpenLiNode = lis[i];
							}
						}
					}
				}
			}
		}
	}
	if (addr.indexOf("how_to_book.asp")> -1) {
		OpenLiNode = document.getElementById("howtobook");
	}
	
	//amended to keep particular nav levels open!
    new TreeMenu("nav1", OpenLiNode);
	
	// fires the crossfader
	try {
		if (document.getElementById('xfader')) {
		Crossfade.setup({autoLoad:false});
		var cf1 = new Crossfade('xfader');
		}
	}
	catch(err) {
	}
	
	 
}

window.onunload = function(e) {
	
  var title = getActiveStyleSheet();
 createCookie("style", title, 365);

}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function showSwitcher() {
	
 var thisStyle = getActiveStyleSheet();
  if (thisStyle==null) {
	  thisStyle = "styles"
  }
	if (thisStyle == 'styles') {
	document.getElementById("textonly").style.display = '';
	document.getElementById("reverse1").style.display = 'none';
	document.getElementById("graphic1").style.display = 'none';
	document.getElementById("reverse2").style.display = 'none';
	document.getElementById("graphic2").style.display = 'none';
	//var embeds = document.getElementsByTagName("embed");
		//for (i=0;i<embeds.length;i++) {
			//embeds[i].style.display = '';
		//}
	}
	else if (thisStyle == 'text') {
	document.getElementById("textonly").style.display = 'none';
	document.getElementById("reverse1").style.display = '';
	document.getElementById("graphic1").style.display = '';
	document.getElementById("reverse2").style.display = 'none';
	document.getElementById("graphic2").style.display = 'none';
	
	}
	else if (thisStyle == 'reverse') {
	document.getElementById("textonly").style.display = 'none';
	document.getElementById("reverse1").style.display = 'none';
	document.getElementById("graphic1").style.display = 'none';
	document.getElementById("reverse2").style.display = '';
	document.getElementById("graphic2").style.display = '';
	}
	
	
}


//////////////// TREE MENU //////////////////////

/*
 * DO NOT REMOVE THIS NOTICE
 *
 * PROJECT:   mygosuMenu
 * VERSION:   1.2.0
 * COPYRIGHT: (c) 2003,2004 Cezary Tomczak
 * LINK:      http://gosu.pl/dhtml/mygosumenu.html
 * LICENSE:   BSD (revised)
 */

function TreeMenu(id, nodeToKeepOpen) {

    this.init = function() {
        if (!document.getElementById(this.id)) {
            alert("Element '"+this.id+"' does not exist in this document. TreeMenu cannot be initialized");
            return;
        }
        this.parse(document.getElementById(this.id).childNodes, this.tree, this.id);
    }

    this.parse = function(nodes, tree, id) {
        for (var i = 0; i < nodes.length; i++) {
			if (nodes[i]!=nodeToKeepOpen) { //dont run function if the current Li is the one we want to keep open!
				if (nodes[i].nodeType != 1) {
					continue;
				}
			
				if (nodes[i].tagName.toLowerCase() == "li") {
					nodes[i].id = id + "-" + tree.length;
					tree[tree.length] = new Array();
					if (nodes[i].childNodes && this.hasUl(nodes[i].childNodes)) {
						nodes[i].className = "section";
						var a;
						if (a = this.getA(nodes[i].childNodes)) {
							a.id = nodes[i].id + "-a";
							eval("document.getElementById('"+a.id+"').onclick = function() {"+
								"self.click('"+nodes[i].id+"');"+
							"}");
						}
					} else {
						nodes[i].className = "box";
					}
				}
			
				if (nodes[i].tagName.toLowerCase() == "ul") {
					nodes[i].style.display = "none";
					id = id + "-" + (tree.length - 1);
					nodes[i].id = id + "-section";
					tree = tree[tree.length - 1];
				}
				if (nodes[i].childNodes) {
					this.parse(nodes[i].childNodes, tree, id);
				}
			} 
        }
    }

    this.hasUl = function(nodes) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1) {
                continue;
            }
            if (nodes[i].tagName.toLowerCase() == "ul") {
                return true;
            }
            if (nodes[i].childNodes) {
                if (this.hasUl(nodes[i].childNodes)) {
                    return true;
                }
            }
        }
        return false;
    }

    this.getA = function(nodes) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType == 1) {
                if (nodes[i].tagName.toLowerCase() == "a") {
                    return nodes[i];
                }
                return false;
            }
        }
    }

    this.click = function(id) {
        e1 = document.getElementById(id + "-section");
        e2 = document.getElementById(id);
        if (e1.style.display == "none") {
            e1.style.display = "";
            e2.className = "section-open";
        } else {
            e1.style.display = "none";
            e2.className = "section";
        }
    }

    var self = this;
    this.id = id;
    this.tree = new Array();
    this.init();
}


//######################################################################################
// Author: ricocheting.com
// For: public release (freeware)
// Date: 4/24/2003 (update: 5/24/2006)
// Description: displays the amount of time until the "dateFuture" entered below.


// NOTE: the month entered must be one less than current month. ie; 0=January, 11=December
// NOTE: the hour is in 24 hour format. 0=12am, 15=3pm etc
// format: dateFuture = new Date(year,month-1,day,hour,min,sec)
// example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm

dateFuture = new Date(2007,11,15,14,30,0);

// TESTING: comment out the line below to print out the "dateFuture" for testing purposes
//document.write(dateFuture +"<br />");


//###################################
//nothing beyond this point
function GetCount(){

	dateNow = new Date();									//grab current date
	amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
	delete dateNow;

	// time is already past
	if(amount < 0){
		document.getElementById('countbox').innerHTML="Now!";
	}
	// date is still good
	else{
		days=0;hours=0;mins=0;secs=0;out="";

		amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

		days=Math.floor(amount/86400);//days
		amount=amount%86400;

		hours=Math.floor(amount/3600);//hours
		amount=amount%3600;

		mins=Math.floor(amount/60);//minutes
		amount=amount%60;

		secs=Math.floor(amount);//seconds

		if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
		if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
		if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
		out += secs +" seconds";
		document.getElementById('countdown').innerHTML=out;

		setTimeout("GetCount()", 1000);
	}
}