
/* Clipped this from Quirksmode (http://www.quirksmode.org/js/detect.html) */
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 dims = getWinDims();
var w = ((dims[0] / 2) - 178);
var h = ((dims[1] / 2) - 110);
*/

function getWinDims() {
  if (BrowserDetect.browser == 'Explorer') {
	if (document.documentElement.clientHeight == 0) {
	  var winX = document.body.clientWidth;
	  var winY = document.body.clientHeight;
	}
	else {
	  var winX = document.documentElement.clientWidth;
	  var winY = document.documentElement.clientHeight;
	}
  }
  else {
	var winX = window.innerWidth;
	var winY = window.innerHeight;
  }

  return [winX, winY];
}



function gallery(txtid) {
  if (!document.getElementById('img_' + txtid)) {return false;}

  var picloc = document.getElementById('where_' + txtid).value;
  var picase = document.getElementById('img_' + txtid);
  picase.src = picloc;

  var mult = document.getElementById('galord_' + txtid).value.match(/([0-9]):([0-9])/);
  scrollx('gallery_main_case', parseInt(mult[2]), 1000);
  scrolly('gallery_main_case', parseInt(mult[1]), 1000);

  fadeMe(picase.id, 0, 100, 300);
}

/* Start scroll functions */
function scrollx(div, vpos, secs) {
  var shiftDiv = document.getElementById(div);
  var speed = Math.round(secs / 100);
  var timer = 0;
  var vrepos = (550 * vpos); /* the first number is the width of the framing elements */
  var z = 50; /* and this should be a multiple of it */

  if (shiftDiv.scrollLeft > vrepos) {
	for (var i = shiftDiv.scrollLeft; i >= vrepos; i -= z) { 
	  setTimeout("shiftit('" + div + "', " + i + ")", (timer * speed));
	  timer++;
	}
  }
  else {
	for (var i = shiftDiv.scrollLeft; i <= vrepos; i += z) {
	  setTimeout("shiftit('" + div + "', " + i + ")", (timer * speed));
	  timer++;
	}
  }
}
function scrolly(div, hpos, secs) {
  var shiftDiv = document.getElementById(div);
  var speed = Math.round(secs / 100);
  var timer = 0;
  var hrepos = (700 * hpos); /* the first number is the height of the framing elements */
  var z = 70; /* and this should be a multiple of it */

  //alert(shiftDiv.id + ' ' + shiftDiv.scrollTop + ' ' + shiftDiv.offsetHeight);

  if (shiftDiv.scrollTop > hrepos) {
	for (var i = shiftDiv.scrollTop; i >= hrepos; i -= z) {
	  setTimeout("liftit('" + div + "', " + i + ")", (timer * speed));
	  timer++;
	}
  }
  else {
	for (var i = shiftDiv.scrollTop; i <= hrepos; i += z) { 
	  setTimeout("liftit('" + div + "', " + i + ")", (timer * speed));
	  timer++;
	}
  }
}
function liftit(div, y) {
  document.getElementById(div).scrollTop = y;
}
function shiftit(div, x) {
  document.getElementById(div).scrollLeft = x;
}
/* End scroll functions */



/* Start fade functions */

function toggleFade(thisdiv, howmuch, howlong) {
  if (document.getElementById(thisdiv).style.opacity == (howmuch/100)) {fadeMe(thisdiv, howmuch, 0, howlong);}
  else {fadeMe(thisdiv, 0, howmuch, howlong);}
}

function fadeMe(thisdiv, fropac, topac, howlong) {
  var box = document.getElementById(thisdiv).style;
  if (fropac == 0) {box.zIndex = 3; box.display = "block"; opacity(thisdiv, fropac, topac, howlong);}
  if (topac == 0) {
	opacity(thisdiv, fropac, topac, howlong);
	setTimeout("document.getElementById('" + thisdiv + "').style.zIndex = '-3'", howlong);
	//	setTimeout("document.getElementById('" + thisdiv + "').style.display = 'none'", howlong);
  }
}

function opacity(id, opacStart, opacEnd, millisec) {
  //speed for each frame
  var speed = Math.round(millisec / 100);
  var timer = 0;

  //determine the direction for the blending, if start and end are the same nothing happens
  if(opacStart > opacEnd) {
	for(i = opacStart; i >= opacEnd; i--) {
	  setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	  timer++;
	}
  } else if(opacStart < opacEnd) {
	for(i = opacStart; i <= opacEnd; i++) {
	  setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	  timer++;
	}
  }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
  var fadingdiv = document.getElementById(id).style;
  fadingdiv.opacity = (opacity / 100);
  fadingdiv.MozOpacity = (opacity / 100);
  fadingdiv.KhtmlOpacity = (opacity / 100);
  fadingdiv.filter = "alpha(opacity=" + opacity + ")";
  //	alert(id + ' ' + opacity);
  return true;
}

/* End fade functions */




function getCont(which) {
  var bd = document.getElementById(which + '_brief');
  var cd = document.getElementById(which + '_long');
  var nk = document.getElementById(which + '_lnk');

  if ((document.getElementById(which + '_gotcont')) && (document.getElementById(which + '_gotcont').value == 1)) {
	if (bd.style.display == 'block') {
	  bd.style.display = 'none';
	  cd.style.display = 'block';
	  nk.innerHTML = '-';
	}
	else {
	  bd.style.display = 'block';
	  cd.style.display = 'none';
	  nk.innerHTML = '+';
	}
  }

  else {
	if (htob = newhtob()) {
	  var poststr = 'dowhat=getcont&which=' + which;
	  htob.open('POST', 'functs.php', true);
	  htob.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  htob.onreadystatechange = function() {
		if ((htob.readyState == 4) && (htob.status == 200)) {
		  cd.innerHTML = htob.responseText;
		  cd.style.display = 'block';
		  bd.style.display = 'none';
		  nk.innerHTML = '-';
		  document.getElementById(which + '_gotcont').value = '1';
		}
	  }
	  htob.send(poststr);
	}
	else {alert('Your browser does not support Ajax. Please upgrade!');}
  }
}

function newhtob() {
  var htob = false;
  if (window.XMLHttpRequest) {htob = new XMLHttpRequest();}
  else if (window.ActiveXObject) {htob = new ActiveXObject("Microsoft.XMLHTTP");}
  else {alert("Cannot create new HTTP Request.");}
  return htob;
}
