function $(id) { return document.getElementById(id); }

// set global variables

var isFox;
var isSafari;
var isIE;
var browserWindowHeight;
var mainDivHeight;
var mainDivBiggerThanWindow;
var borderStyles = [ "dashed", "solid", "dotted" ];
var possibleBackgrounds = [ "bg3.jpg", "bg8.jpg", "bg10.gif", "bg11.jpg" ];

window.onload = init;
window.onresize = resizeInit;

function init()
{
	determineBrowser();
	determineContentHeight();
	createRandomPage();
	setButtonEvents();
}
function resizeInit()
{
	if(mainDivBiggerThanWindow)
	{
		for( a = 0; a < 5; a++ )
		{
			var borderID = "border" + a;
			$(borderID).style.height = getMainDivHeight();
		}
		
		$("mainDiv").style.height = getMainDivHeight();
	}
	else
	{
		for( a = 0; a < 5; a++ )
		{
			var borderID = "border" + a;
			$(borderID).style.height = getWindowHeight();
		}
		
		$("mainDiv").style.height = getWindowHeight();
	}
}
function setButtonEvents()
{	
	(isIE) ? $("changePageAesthetics").attachEvent("onmousedown", updatePage) : $("changePageAesthetics").addEventListener("mousedown", updatePage, false);
	
	(isIE) ? $("changePageAesthetics").attachEvent( "onmouseover", function(){ $("changePageAesthetics").style.borderBottom = "1px dashed #fff"; } ) : $("changePageAesthetics").addEventListener("mouseover", function(){ $("changePageAesthetics").style.borderBottom = "1px dashed #fff"; }, false);
	
	(isIE) ? $("changePageAesthetics").attachEvent( "onmouseout", function(){ $("changePageAesthetics").style.borderBottom = "0px dashed #fff"; } ) : $("changePageAesthetics").addEventListener("mouseout", function(){ $("changePageAesthetics").style.borderBottom = "0px dashed #fff"; }, false);	
}

function determineContentHeight()
{
	if( getMainDivHeight() > getWindowHeight() )
	{
		mainDivBiggerThanWindow = true;
	}
	else
	{
		mainDivBiggerThanWindow	 = false;
	}
}

function getMainDivHeight()
{
	return $("mainDiv").offsetHeight;	
}

function getWindowHeight()
{
	if (window.innerHeight) // Firefox, Netscape, Mozilla
	{
		browserWindowHeight = window.innerHeight;
	}
	else if (document.documentElement.clientHeight) //IE6 and 7
	{
		browserWindowHeight = document.documentElement.clientHeight;
	}	
	else if (document.body.clientHeight) //IE past
	{
		browserWindowHeight = document.body.clientHeight;	
	}
	return browserWindowHeight;
}

function createRandomPage()
{
	for( a = 0; a < 5; a++ )
	{
		var newBorder = document.createElement("div");
		
		var borderID = "border" + a;
		
		newBorder.setAttribute("id", borderID);
		
		( isIE ) ? newBorder.setAttribute("className", "border") : newBorder.setAttribute("class", "border");
		
		newBorder.style.borderColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
		
		( isIE ) ? newBorder.style.borderStyle = borderStyles[ Math.floor( Math.random()*2 ) ] : newBorder.style.borderStyle = borderStyles[ Math.floor( Math.random()*3 ) ];

		( mainDivBiggerThanWindow == true ) ? newBorder.style.height = getMainDivHeight() + "px" : newBorder.style.height = getWindowHeight() + "px";
		
		$("coloredBorders").appendChild(newBorder);	
		
	} // end for loop
	
	$("coloredBorders").style.backgroundColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
	
	$("logoDiv").style.backgroundColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
	
	$("navDiv").style.backgroundColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
	
	( mainDivBiggerThanWindow == false ) ? $("mainDiv").style.height = getWindowHeight() + "px" : 0;
	
	$("mainDiv").style.borderColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
	
	$("mainDiv").style.backgroundImage = "url(../images/experimental/" + possibleBackgrounds[ Math.floor( Math.random()*possibleBackgrounds.length ) ] + ")";
	
}

function updatePage()
{
	for( a = 0; a < 5; a++ )
	{		
		var borderID = "border" + a;
		
		$(borderID).style.borderColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
		
		(isIE) ? $(borderID).style.borderStyle = borderStyles[ Math.floor( Math.random()*2 ) ] : $(borderID).style.borderStyle = borderStyles[ Math.floor( Math.random()*3 ) ];
		
	} // end for loop
	
	$("logoDiv").style.backgroundColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
	$("navDiv").style.backgroundColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
	$("mainDiv").style.borderColor = "rgb(" + getRandomRGBValue() + "," + getRandomRGBValue() + "," + getRandomRGBValue() + ")";
	$("mainDiv").style.backgroundImage = "url(../images/experimental/" + possibleBackgrounds[ Math.floor( Math.random()*possibleBackgrounds.length ) ] + ")";	
}

function getRandomRGBValue()
{
	var myDate = new Date().getTime();
	
	var newNum1 = (myDate * Math.random()).toString();
	newNum1 = newNum1.substring( (newNum1.indexOf(".")), newNum1.length ); 
	var rNum1 = Math.floor( parseFloat(newNum1) * 256 );
	
	return rNum1;	
}

function determineBrowser()
{
	if(window.event)
	{
		if(navigator.userAgent.lastIndexOf("Apple") != -1 )
		{
			isSafari = true;
		}
		else
		{
			isIE = true;
		}	
	}
	else
	{
		isFox = true;	
	}
}

