//variables seting
var agt;
var is_ie;
var is_ie5up;
var is_ie5_5up;
var is_ie6;
var is_ie5down;
var is_ns6;
var is_opera;
var is_mac;



function doOnLoad()
{
	getBrowser();
	
	if (!is_ie5up && !is_ns6 && !is_opera && !is_mac)
	{
		window.location.href='upgrade.html';
	}
	else
	{
		setPageWidth();
	}
	
//	loadImages()
}

/*
function setPageWidth()

sets out hte page based on screen resoltuion/browser window size.
if the screen is 800x600 then use the numbers in style.css else use this function

*/
function setPageWidth()
{	
	//get window size
	if (is_ie)
	{
		winHeight = document.body.clientHeight;
		winWidth =document.body.clientWidth;
	}
	else
	{
		winHeight = window.innerHeight;
		winWidth = window.innerWidth;
	}
	
	if (winWidth < 820)
	{
		x = document.getElementById('top').style;
		x.width = winWidth;
		x = document.getElementById('menu').style;
		x.width = winWidth;
		//turn things on
		x = document.getElementById('right').style;
		if ((is_ie)||(is_opera))
		{
			x.left = winWidth-160;
		}
		else
		{
			x.left = winWidth-170;
		}
		x.visibility='visible';
		
		x = document.getElementById('centre').style;
		x.visibility='visible';
		
		
		x = document.getElementById('bottom').style;
		x.width=winWidth;
		x.visibility='visible';
	}
	else
	{
		
		if (pageName != 'receiptPrint')
		{
			x = document.getElementById('top').style;
			x.width = winWidth-2;
			
			x = document.getElementById('right').style;
			if ((is_ie)||(is_opera))
			{
				x.left = winWidth-160;
			}
			else
			{
				x.left = winWidth-170;
			}
			x.height = winHeight-130;
			x.visibility='visible';
			
			x = document.getElementById('menu').style;
			x.width = winWidth;
		}
		
		x = document.getElementById('centre').style;
		x.width = winWidth-215;
		x.height = winHeight-165;
		x.visibility='visible';
		
		x = document.getElementById('bottom').style;
		x.width = winWidth-1;
		x.top = winHeight-42;
		x.visibility='visible';
		
	}
	/*
	now position the menu items
	
	need to get the width of the centre area and space the menu items accordingly
	there are 5 items so take centre are width and devide by 5 to get left position of each menu item
	*/
	//totalWidth = parseInt(document.getElementById('centre').style.width);
	totalWidth = winWidth;
	//left for 'home' is the left for the centre span then space the rest according to above
	document.getElementById('home').style.left = "70px";
	document.getElementById('home').style.visibility = "visible";
	
	space = (totalWidth-300)/6;
	start = 80+space;
	document.getElementById('about').style.left = start;
	document.getElementById('about').style.visibility = "visible";
	
	document.getElementById('news').style.left = (start-5) + space;
	document.getElementById('news').style.visibility = "visible";
	
	document.getElementById('contact').style.left = (start-18) + (2*space);
	document.getElementById('contact').style.visibility = "visible";
	
	document.getElementById('tandc').style.left = (start-33) + (3*space);
	document.getElementById('tandc').style.visibility = "visible";
	
	
	
	//alert("totalWidth = "+totalWidth +"\n\nSpace = " + space);
	
	//set the style and colour of the present page to white and bold - name taken from variable to top of each html page
	if (document.getElementById(pageName))
	{
		document.getElementById(pageName).style.fontWeight = 'bold';
		document.getElementById(pageName).style.color = '#741519';
		
	}
		
}


function getBrowser()
{
	agt=navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3 = (is_ie && (is_major < 4));
	var is_ie4 = (is_ie && (is_major >= 4)&& (agt.indexOf("msie 4")!=-1) );
	var is_ie4up = (is_ie && (is_major >= 4));
	var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	is_ie5up = (is_ie && !is_ie3 && !is_ie4);
	is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0") !=-1));
	is_ie5down = (is_ie && (is_ie3 || is_ie4 || is_ie5) );
	var is_ns = (((agt.indexOf("netscape") != -1) || (agt.indexOf("gecko") != -1)) && (agt.indexOf("opera") == -1));
	is_ns6 = (is_ns && (is_major >= 5));
	is_opera = (agt.indexOf("opera") != -1);
	is_mac = ((agt.indexOf("mac") != -1) && (agt.indexOf("msie 5")!=-1));
	
	//alert("browser: "+agt +"\n\n"+is_major);
	//alert(is_ns6);
}

/*
function loadImages()

loads three random flowers in to the 'images' div layer

arguments: none
returns: none
*/

function loadImages()
{
	if (pageName != 'home')
	{
		//only have one image - so need to pick between techie and people pics
		
		randomPick = Math.floor(Math.random*2);
		if (randomPick == 1)
		{
			imagePath = "/images/thumbnails/people/";
			arrayPick = new Array("bubbles2.jpg", "coffeepaper2.jpg", "eye.jpg", "face2.jpg", "handshake.jpg");
			arrayHeight = new Array(76,76,106,92,82);
			arrayWidths = new Array(76,76,106,92,82);
		}
		else
		{
			imagePath = "/images/thumbnails/techie/";
			arrayPick = new Array("blue_screeen.jpg", "brightcables.jpg", "ipod.jpg", "man_mac.jpg", "mouse.jpg");
			arrayHeight = new Array(105,76,82,76,92);
			arrayWidths = new Array(79,103,123,123,123);
		}
		
		//imagePeopleSrc = new Array("bubbles2.jpg", "coffeepaper2.jpg", "eye.jpg", "face2.jpg", "handshake.jpg");
		//imageTechSrc = new Array("blue_screeen.jpg", "brightcables.jpg", "ipod.jpg", "man_mac.jpg", "mouse.jpg");
		//imagePeopleHeight = new Array(76,76,106,92,82)
		//imagePeopleWidth = new Array(89,114,123,123,123);
		//imageTechHeight = new Array(105,76,82,76,92)
		//imageTechWidth = new Array(79,103,123,123,123);
		
		random1 = Math.floor(Math.random()*5);
		//random2 = Math.floor(Math.random()*5);
		if (!is_ie)
		{
			imageName = document.images.image1;
		}
		else
		{
			imageName = document.image1;
		}
		imageName.src = imagePath + arrayPick[random1];
		imageName.width = arrayWidths[random1];
		imageName.height = arrayHeight[random1]

		/*
		image2 = document.images.image2;
		image2.src = "images/thumbnails/techie/" + imageTechSrc[random2];
		image2.width = imageTechWidth[random2];
		image2.height = imageTechHeight[random2];
		*/
	}

}