function showMenu(menu, id)
{
	menuDivId = 'menuDiv' + id;
	menuDiv = document.getElementById(menuDivId);
	menuX = findPos(menu);
	menuTopID = 'menuTop' + id;
	
	windowWidth = getSize();
	boxLeft = document.getElementById('contentBox').offsetLeft;
	
	if(BrowserDetect.browser == 'Explorer')
	{
		topset = 26;
	}
	else
	{
		topset = 22;
	}
	
	if(document.getElementById(menuTopID).value == '000')
	{
		str = menuDiv.style.top;
		str.substr(0, str.length - 2);
		number = parseInt(str);
		number += topset;
		number = number + 'px';
		document.getElementById(menuTopID).value = number;
	}
	else
	{
		number = document.getElementById(menuTopID).value;
	}

	menuDiv.style.top = number;
	menuDiv.style.left = menuX[1];
	menuDiv.style.display = 'block';
	menuDiv.style.opacity = 0;
	menuDiv.style.filter = 'alpha(opacity=' + 0 + ')';

	
	menuWidth = menuDiv.offsetWidth;
	menuLeftStr = menuDiv.style.left;
	menuLeft = menuLeftStr.substr(0, menuLeftStr.length - 2);

	rightNum = parseInt(menuLeft) + parseInt(menuWidth);

	edgenum = 880 + boxLeft;
	if(rightNum > edgenum)
	{
		ammountOver = rightNum - edgenum;
		newLeft = menuLeft - ammountOver;
		menuDiv.style.left = newLeft + 'px';
	}

	menuDiv.style.opacity = 100;
	menuDiv.style.filter = 'alpha(opacity=' + 100 + ')';
}

function hideMenu(id)
{
	document.getElementById('menuDiv' + id).style.display = 'none';
}

function showStory(id)
{
	document.getElementById('rightArrow_' + id).style.display = 'none';
	document.getElementById('downArrow_' + id).style.display = '';
	document.getElementById('storyDiv_' + id).style.display = '';
}

function hideStory(id)
{
	document.getElementById('rightArrow_' + id).style.display = '';
	document.getElementById('downArrow_' + id).style.display = 'none';
	document.getElementById('storyDiv_' + id).style.display = 'none';
}

function findPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curtop, curleft];
}

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"
		}
	]

};

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
}

BrowserDetect.init();

