
//----------------------------------------------------------------- Browser detection ------------------------------------------------------


//Detects browser, version and OS.
//use by accessing the strings:
//BrowserDetect.browser displays the browser name
//BrowserDetect.version displays the version number
//BrowserDetect.os displays the computer platform


var BrowserDetect = {
	init: 
	function () 
		{
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},


	searchString: function (data) 
		{
			for (var i=0;i<data.length;i++)	
				{
					var dataString = data[i].string;
					var dataProp = data[i].prop;
					this.versionSearchString = data[i].versionSearch || data[i].identity;
					if (dataString) 
						{
							if (dataString.indexOf(data[i].subString) != -1) return data[i].identity;
						}
					else if (dataProp) return data[i].identity;
				}
		},


	searchVersion: function (dataString) 
			{
				var index = dataString.indexOf(this.versionSearchString);
				if (index == -1) return;
				return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
			},


	dataBrowser: 	[


			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},


			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari"
			},


			{
				prop: window.opera,
				identity: "Opera"
			},


			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},


			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},


			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},


			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},


			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},


			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},


			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},


			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}


		],


	dataOS : 	[
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},


			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},


			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}


		]


};


BrowserDetect.init();

var widthofpage = 0;
var widthfactor = 0;

var heightofpage = 0;
var heightfactor = 0;

var span = new Array(0,345,465,610,745);


//--------------------------------------------------------------------- perform onPageLoad setup functions ---------------------------------------------------


function startupStuff(pgwidth,pgheight) {
	widthofpage = pgwidth;
	widthfactor = widthofpage / 800;
	heightofpage = pgheight;
	heightfactor = heightofpage / 600;

	//nextFrame("pagebottom.php","bottomcontent");
	//nextFrame("page.php","content");

	arrowRight();
}


//------------------------------------------------------------- code to move nav arrow over to nav bar on page startup --------------------------------------


var rpos = 0;
var rightPos = 0;


function arrowRight() {
	rpos = setInterval("moveRight();",20);
}


function moveRight() {
	rightPos += Math.ceil(15*widthfactor);
	$("pointer").style.left = rightPos+"px";
	if(rightPos > Math.ceil(span[1]*widthfactor)) {
		$("pointer").style.left = Math.ceil(span[1]*widthfactor)+"px";
		clearInterval(rpos);
	}
}


//---------------------------------------------------------------- code to move nav arrow in response to link click -----------------------------------------


var udpos = 0;


var rightPos = 0;
var finalPos = 0;

function moveArrow(link) {
	rightPos = Math.ceil(span[currentNav]*widthfactor);
	finalPos = Math.ceil(span[link]*widthfactor);
	amount = finalPos - rightPos;
	udpos = setInterval("moveUpDown("+amount+");",20);
}


function moveUpDown(amount) {

	if(amount < 0) {
		rightPos -= Math.ceil(15*widthfactor);
		$("pointer").style.left = rightPos+"px";
		if(rightPos < finalPos) {
			$("pointer").style.left = finalPos+"px";
			clearInterval(udpos);
			udpos = 0;
		}
	}
	else {
		rightPos += Math.ceil(15*widthfactor);
		$("pointer").style.left = rightPos+"px";
		if(rightPos > finalPos) {
			$("pointer").style.left = finalPos+"px";
			clearInterval(udpos);
			udpos = 0;
		}
	}
}


//------------------------------------------------------------------------------ link mouseOver effects ----------------------------------------------------

var currentNav = 1;

function dim() {
	if(1 != currentNav) $("nav1").style.backgroundColor = "#000000";
	if(2 != currentNav) $("nav2").style.backgroundColor = "#000000";
	if(3 != currentNav) $("nav3").style.backgroundColor = "#000000";
	if(4 != currentNav) $("nav4").style.backgroundColor = "#000000";
}


function glow(link) {
	if(link != currentNav) $("nav"+link).style.backgroundColor = "#580000";
}

function navto(link,caller) {
	//if(link != currentNav) {
		$("nav"+link).style.backgroundColor = "#580000";
		moveArrow(link);
		nextFrame("page.php","content","page="+link+"&caller="+caller);
		currentNav = link;

		//nave button used - reset all tree and grid parameters back to unused state

		currentbullet = 1;
		currentbulletid = 0;
		clearInterval(runbullettimer);
		runbullettimer = 0;

		dim();
	//}
}

//----------------------------------------------------------------------- load next content frame per link click ------------------------------------------


function nextFrame(URL,div,vars) {

	//in case bullet timer was running, reset it

	clearInterval(runbullettimer);
	runbullettimer = 0;

	formdata = "?browser="+BrowserDetect.browser+"&version="+BrowserDetect.version+"&os="+BrowserDetect.os+"&width="+widthofpage+"&height="+heightofpage+"&"+vars;
	new Ajax.Updater(div,URL,{method:'post',parameters:formdata,asynchronous:false});

	//if returning to a page with tree and grid and returning from a details page (navto not invoked)...

	if($("div_."+currentbulletid+"_1")) {

		//and if the viewer was looking at a bullet other than the top one...

		if(currentbullet != 1) {

			//then reset the tree and grid to bullet 1 and open back to the bullet being viewed when the page was left

			currentbullet = 1;
			runTreeAndGrid(currentbulletid)
		}
	}
}

function showBig(image) {

	//$("viewbig").style.height = "350px";
	//$("viewbig").style.width = "310px";
	//$("viewbig").style.overflow = "hidden";
	//$("viewbig").style.backgroundColor = "#FFFFFF";
  	//$("viewbig").style.visibility = "visible";
  	//$("viewbig").style.display = "block";
  	//$("viewbig").style.borderWidth = "5px";
  	//$("viewbig").style.borderStyle = "solid";
  	//$("viewbig").style.zIndex = 100;
  	//$("viewbig").style.position = "absolute";
  	//$("viewbig").style.left = "10px";
  	//$("viewbig").style.top = "10px";
	//$("viewbig").innerHTML = "<a style='cursor:pointer;text-decoration:none;color:black;' onclick='$(\"viewbig\").style.visibility = \"hidden\";'><font style='font-size:16pt;color:black;'>Close Window</font></a><br><img src='images/"+image+"'>";
	var destination = $("xfer").value;
	$(destination).src = "images/"+image;
	$(destination).style.height = "300px";
	$(destination).style.width = "300px";
}

//----------------------------------------------------------------------- accept email address submition ------------------------------------------

function validEmail(email) {
	invalidChars = " /:;,";

	if(email == "") return false;

	for(i=0;i<invalidChars.length;i++) {
		badChar = invalidChars.charAt(i);
		if(email.indexOf(badChar,0) > -1) return false;
	}
	atPos = email.indexOf("@",1);
	if(atPos == -1) return false;
	if(email.indexOf("@",atPos+1) > -1) return false;
	periodPos = email.indexOf(".",atPos);
	if(periodPos == -1) return false;
	if(periodPos+3 > email.length) return false;

	return true;
}

function saveEmailAddress() {
	var address = $("emailform").value;

	if((address == "")||(address == "Please enter your Email Address")) {
		$("emailform").value = "Please enter your Email Address";
		return;
	}

	if(!validEmail(address)) {
		$("emailform").value = "Invalid Address - Please try again";
		return;
	}

	new Ajax.Request("storeemailadd.php",{method:'post',parameters:"address="+address,asynchronous:true,onSuccess:function(transport){
		$("emailform").value = transport.responseText
	}
	});

}

//------------------------------------------------------------------------- Slideshow load and crossfade code ---------------------------------------------


var currentSlide = 2;
var currentDiv = 1;
var slideLimit = 4;
var intTiming = 0;
var	showing = 0;
var	fading = 100;


function slideShow() {
	fadeOut = currentDiv;
	if(currentDiv == 2) currentDiv = 0;
	currentDiv++;
	fadeIn = currentDiv;
	showing = 0;
	fading = 100;
	if(intTiming == 0) intTiming = setInterval("xfade(fadeIn,fadeOut);",100);
}


function xfade(fadeIn,fadeOut) {

	showing = showing + 5;
	fading = fading - 5;


	obj1 = $("shots"+fadeOut)
	obj2 = $("shots"+fadeIn)
	
	if (obj1.style) {
		if (obj1.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj1.style.MozOpacity = (fading/100);
		} else if (obj1.style.opacity!=null) {
			/* CSS3 compatible */
			obj1.style.opacity = (fading/100);
		} else if (obj1.style.filter!=null) {
			/* IE's proprietary filter */
			obj1.style.filter = "alpha(opacity="+fading+")";
		}
	}
	
	if (obj2.style) {
		if (obj2.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj2.style.MozOpacity = (showing/100);
		} else if (obj2.style.opacity!=null) {
			/* CSS3 compatible */
			obj2.style.opacity = (showing/100);
		} else if (obj2.style.filter!=null) {
			/* IE's proprietary filter */
			obj2.style.filter = "alpha(opacity="+showing+")";
		}
	}


	if(fading < 1) {
		clearInterval(intTiming);
		intTiming = 0;
		if(currentSlide == 4) currentSlide = 0;
		currentSlide++;
		$("shots"+fadeOut).innerHTML = "<img border='0' src='graphics/slide-"+currentSlide+".jpg' width='1008'>";
	}
	
}

//-------------------------------------------------------- tree and grid -----------------------------------------------------------------

var currentbullet = 1;
var currentbulletid = 0;
var raisebullets = 0;
var lowerbullets = 0;
var closepix = 0;
var openpix = 0;
var opentext = 0;
var nexttext = 0;
var bulletarray = new Array();
var tops = new Array();
var lefts = new Array();
var que1 = new Array(0,0,0,0,0,0,0,0,0);
var que2 = new Array(0,0,0,0,0,0,0,0,0);
var runbullettimer = 0;
var here = currentbullet;
var there = 0;
var imagepasscount = 0;

function runTreeAndGrid(bulletid) {
	bulletarray.length = 0;
	tops.length = 0;

	bulletarray = $('allbullets').value.split(",");
	opentext = $('height_'+bulletarray[currentbullet-1]).value;
	nexttext = $('height_'+bulletid).value;
	here = currentbullet;
	there = 0;

	for(var i=0; i< bulletarray.length;i++) {
		tops[i] = $('div_b_'+bulletarray[i]).style.top;
		if(bulletarray[i] == bulletid) there = i+1;
		if(BrowserDetect.browser == "Explorer") $('div_t_'+bulletarray[i]).style.display = "none";
	}

	if(there == currentbullet) return;

	lefts[1] = $("div_."+bulletid+"_1").style.left;
	lefts[2] = $("div_."+bulletid+"_2").style.left;
	lefts[3] = $("div_."+bulletid+"_3").style.left;
	lefts[4] = $("div_."+bulletid+"_4").style.left;
	lefts[5] = $("div_."+bulletid+"_5").style.left;
	lefts[6] = $("div_."+bulletid+"_6").style.left;
	lefts[7] = $("div_."+bulletid+"_7").style.left;
	lefts[8] = $("div_."+bulletid+"_8").style.left;
	lefts[9] = $("div_."+bulletid+"_9").style.left;

	raisebullets = 1;
	lowerbullets = 1;
	openpix = 1;
	closepix = 1;
	currentbullet = there;
	currentbulletid = bulletid;
	imagepasscount = 0;

	$("pix_a_"+bulletarray[here-1]).src = "images/pointer1.gif";

	runbullettimer = setInterval("changeTree()",20);
}

function changeTree() {
	factor = 6;
	var correction = 0;
	imagepasscount++;

	if(raisebullets == 1) {
		for(var i = here;i < bulletarray.length;i++) {
			$("div_b_"+bulletarray[i]).style.top = parseInt($("div_b_"+bulletarray[i]).style.top) - factor;
			$("div_a_"+bulletarray[i]).style.top = parseInt($("div_a_"+bulletarray[i]).style.top) - factor;
			$("div_t_"+bulletarray[i]).style.top = parseInt($("div_t_"+bulletarray[i]).style.top) - factor;
		}
		$("div_t_"+bulletarray[here-1]).style.height = parseInt($("div_t_"+bulletarray[here-1]).style.height) - factor;
		correction = parseInt($("div_t_"+bulletarray[here-1]).style.height) 
		if(correction < factor) {
			for(var i = here;i < bulletarray.length;i++) {
				$("div_b_"+bulletarray[i]).style.top = parseInt($("div_b_"+bulletarray[i]).style.top) - correction;
				$("div_a_"+bulletarray[i]).style.top = parseInt($("div_a_"+bulletarray[i]).style.top) - correction;
				$("div_t_"+bulletarray[i]).style.top = parseInt($("div_t_"+bulletarray[i]).style.top) - correction;
			}
			$("div_t_"+bulletarray[here-1]).style.height = 0;
			$("pix_a_"+bulletarray[here-1]).src = "images/pointer2.gif";
			raisebullets = 0;
		}
	}

	if(lowerbullets == 1) {
		for(var i = there;i < bulletarray.length;i++) {
			$("div_b_"+bulletarray[i]).style.top = parseInt($("div_b_"+bulletarray[i]).style.top) + factor;
			$("div_a_"+bulletarray[i]).style.top = parseInt($("div_a_"+bulletarray[i]).style.top) + factor;
			$("div_t_"+bulletarray[i]).style.top = parseInt($("div_t_"+bulletarray[i]).style.top) + factor;
		}
		if($("div_t_"+bulletarray[there-1]).style.height == "") $("div_t_"+bulletarray[there-1]).style.height = "0";
		$("div_t_"+bulletarray[there-1]).style.height = parseInt($("div_t_"+bulletarray[there-1]).style.height) + factor;
		correction = 0;
		if(parseInt($("div_t_"+bulletarray[there-1]).style.height) > parseInt($("height_"+bulletarray[there-1]).value)) {
			var correction = parseInt($("div_t_"+bulletarray[there-1]).style.height) - parseInt($("height_"+bulletarray[there-1]).value);
		}
		if(correction > 0) {
			for(var i = there;i < bulletarray.length;i++) {
				$("div_b_"+bulletarray[i]).style.top = parseInt($("div_b_"+bulletarray[i]).style.top) - correction;
				$("div_a_"+bulletarray[i]).style.top = parseInt($("div_a_"+bulletarray[i]).style.top) - correction;
				$("div_t_"+bulletarray[i]).style.top = parseInt($("div_t_"+bulletarray[i]).style.top) - correction;
			}
			$("div_t_"+bulletarray[there-1]).style.height = $("height_"+bulletarray[there-1]).value;
			$("div_t_"+bulletarray[there-1]).style.display = "block";//////////////////////////////////////////////////////////
			$("pix_a_"+bulletarray[there-1]).src = "images/pointer.gif";
			lowerbullets = 0;
		}
	}

	switch(imagepasscount) {
		case 1:
			que1[0] = 1;
			break;
		case 4:
			que1[1] = 4;
			break;
		case 7:
			que1[2] = 2;
			break;
		case 10:
			que1[3] = 7;
			break;
		case 13:
			que1[4] = 5;
			break;
		case 16:
			que1[5] = 3;
			break;
		case 19:
			que1[6] = 8;
			break;
		case 22:
			que1[7] = 6;
			break;
		case 25:
			que1[8] = 9;
			break;
	}
	
	for(i=0; i < 9; i++) {
		if(que1[i] != 0) {
			$("div_."+bulletarray[here-1]+"_"+que1[i]).style.width = parseInt($("div_."+bulletarray[here-1]+"_"+que1[i]).style.width) - (factor*2);
			$("div_."+bulletarray[here-1]+"_"+que1[i]).style.left = parseInt($("div_."+bulletarray[here-1]+"_"+que1[i]).style.left) + (factor);
			$("div_."+bulletarray[there-1]+"_"+que1[i]).style.width = parseInt($("div_."+bulletarray[there-1]+"_"+que1[i]).style.width) - (factor*2);
			$("div_."+bulletarray[there-1]+"_"+que1[i]).style.left = parseInt($("div_."+bulletarray[there-1]+"_"+que1[i]).style.left) + (factor);
			if(parseInt($("div_."+bulletarray[here-1]+"_"+que1[i]).style.width) < (factor * 2)) {
				$("div_."+bulletarray[here-1]+"_"+que1[i]).style.left = parseInt($("div_."+bulletarray[here-1]+"_"+que1[i]).style.left) + parseInt($("div_."+bulletarray[here-1]+"_"+que1[i]).style.width);
				$("div_."+bulletarray[there-1]+"_"+que1[i]).style.left = parseInt($("div_."+bulletarray[there-1]+"_"+que1[i]).style.left) + parseInt($("div_."+bulletarray[there-1]+"_"+que1[i]).style.width);
				$("div_."+bulletarray[here-1]+"_"+que1[i]).style.width = "1px";
				$("div_."+bulletarray[there-1]+"_"+que1[i]).style.width = "1px";
				$("div_."+bulletarray[here-1]+"_"+que1[i]).style.visibility = "hidden";
				$("div_."+bulletarray[there-1]+"_"+que1[i]).style.visibility = "visible";
				que2[i] = que1[i];
				que1[i] = 0;
				if((que1[0] == 0)&&(que1[1] == 0)&&(que1[2] == 0)&&(que1[3] == 0)&&(que1[4] == 0)&&(que1[5] == 0)&&(que1[6] == 0)&&(que1[7] == 0)&&(que1[8] == 0)) closepix = 0;
			}
		}
	}

	for(i=0; i < 9; i++) {
		if(que2[i] != 0) {
			$("div_."+bulletarray[here-1]+"_"+que2[i]).style.width = parseInt($("div_."+bulletarray[here-1]+"_"+que2[i]).style.width) + (factor*2);
			$("div_."+bulletarray[here-1]+"_"+que2[i]).style.left = parseInt($("div_."+bulletarray[here-1]+"_"+que2[i]).style.left) - (factor);
			$("div_."+bulletarray[there-1]+"_"+que2[i]).style.width = parseInt($("div_."+bulletarray[there-1]+"_"+que2[i]).style.width) + (factor*2);
			$("div_."+bulletarray[there-1]+"_"+que2[i]).style.left = parseInt($("div_."+bulletarray[there-1]+"_"+que2[i]).style.left) - (factor);
			if(parseInt($("div_."+bulletarray[here-1]+"_"+que2[i]).style.width) > 74) {
				$("div_."+bulletarray[here-1]+"_"+que2[i]).style.left = lefts[que2[i]];
				$("div_."+bulletarray[there-1]+"_"+que2[i]).style.left = lefts[que2[i]];
				$("div_."+bulletarray[here-1]+"_"+que2[i]).style.width = "74px";
				$("div_."+bulletarray[there-1]+"_"+que2[i]).style.width = "74px";
				que2[i] = 0;
				if((que2[0] == 0)&&(que2[1] == 0)&&(que2[2] == 0)&&(que2[3] == 0)&&(que2[4] == 0)&&(que2[5] == 0)&&(que2[6] == 0)&&(que2[7] == 0)&&(que2[8] == 0)) openpix = 0;
			}
		}
	}

	if((raisebullets == 0)&&(lowerbullets == 0)&&(closepix == 0)&&(openpix == 0)) {
		clearInterval(runbullettimer);
		runbullettimer = 0;
	}
}


