var NS4DOM = document.layers ? true:false;
var IEDOM = document.all ? true:false;
var W3CDOM = document.getElementById ? true: false;

function getObject(id) {
   if (NS4DOM) ref = "document."+id;
   else if (IEDOM) ref = id;
   else if (W3CDOM) ref = "document.getElementById('"+id+"')";
   var object = eval(ref);
   return object;
}

function scrambleAds()
{
	return 0.5 - Math.random();
}
	var counter = 1;
	var is_hidden = false; //used for the bgShow() method
	var ad_speed = 10000; //Time in ms that each ad is displayed
	
	ads.sort(scrambleAds); //Scramble the ads
	//script to fade sponsor logos
   function fadeBanner()
   {
		var ad_1 = getObject("ad_1");
		var ad_2 = getObject("ad_2");
		//The ad images are set to hidden in the CSS before we start showing them
		ad_1.style.display = "block";
		ad_2.style.display = "block";
		
		ad_1.src = ads[0];
		ad_2.src = ads[1];
		
		restart();
   }
   function restart()
   {
		setTimeout("opacity(\"ad_1\", 100, 0, 1500)", ad_speed);
   }
   function opacity(id, opacStart, opacEnd, millisec) 
   {
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
		var ad_1 = getObject("ad_1");
		var ad_2 = getObject("ad_2");
		//determine the direction for the blending, if start and end are the same nothing happens
		if (opacStart > opacEnd) //Fade out to second banner image
		{
			for (i = opacStart; i >= opacEnd; i--) 
			{
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
			setTimeout("switchAd1()", timer * speed);
			setTimeout("opacity(\"ad_1\", 0, 100, 1500)", (timer * speed) + ad_speed);
		}
		else if (opacStart < opacEnd) //Fade back into the first banner image
		{
			for (i = opacStart; i <= opacEnd; i++)
			{
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
			setTimeout("switchAd2()", timer * speed);
			setTimeout("restart()", (timer * speed));
		}
	}
	function switchAd1()
	{
		var ad_1 = getObject("ad_1");
		counter++;
		if (counter == ads.length) { counter = 0; }
		ad_1.src = ads[counter];
	}
	function switchAd2()
	{
		var ad_2 = getObject("ad_2");
		counter++;
		if (counter == ads.length) { counter = 0; }
		ad_2.src = ads[counter];
	}
	//Function that hides basically everything except the background image
	//toggled through the var is_hidden
	function showBg()
	{
		var vis_menu = getObject("vis_menu");
		var container = getObject("container");
		if (is_hidden == true) 
		{ 
			container.style.display = "block";
			is_hidden = false; 
			vis_menu.innerHTML = "<span><a href=\"#\" onClick=\"showBg()\">Hide page</a></span>";
		}
		else 
		{ 
			container.style.display = "none";
			is_hidden = true;
			vis_menu.style.zIndex = 20;
			vis_menu.innerHTML = "<span><a href=\"#\" onClick=\"showBg()\">Show page</a></span>";
		}
	}
	//Toggle an element in the hole by hole view
	function toggleMenu(menuID)
	{
		var menu = getObject(menuID);
		if (menu.style.display != "block") 
		{
			menu.style.display = "block";
		}
		else
		{
			menu.style.display = "none";
		}
	}
	//Toggle the front 9 from hole by hole view
	//not that different from toggleMenu
	function toggleHoles(firstHole, lastHole)
	{
		var menu;
		for (i = firstHole; i <= lastHole; i++)
		{
			menu = getObject("hole" + i);
			if (menu.style.display != "block") 
			{
				menu.style.display = "block";
			}
			else
			{
				menu.style.display = "none";
			}
		}
	}
	//change the opacity for different browsers
	function changeOpac(opacity, id) 
	{
		var object = document.getElementById(id).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	} 
	
	var messages = new Array (
		"Check out the latest news and announcements below!", 
		"Check the current weather conditions from a live webcam", 
		"Take a tour of each hole on the course",
		"Find out more about green fees and bookings" );
		
	function setText(index)
	{
		var message = getObject("message");
		message.innerHTML = messages[index];
	}
	