// JavaScript Document

	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();
	

	function findPosition(oLink) 
	{
		if(oLink.offsetParent) 
		{
			for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) 
			{
				posX += oLink.offsetLeft;
				posY += oLink.offsetTop;
			}
			
			return [ posX, posY ];
		} 
		else 
		{
			return [ oLink.x, oLink.y ];
		}
	}

	function getPageSize()
	{ 		
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
	
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
			yScroll = document.documentElement.scrollHeight;
			
			if(windowWidth == undefined) windowWidth = screen.width;
			if(windowHeight == undefined) windowHeight = screen.height;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
	
	
	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		
		return arrayPageSize;
	}
/*
	Object.prototype.getChildLink = function(parent)
	{
		var parent 	= new Object(this.getElementsByTagName(parent));
		var child	= new Array();

		for(var i=0; i < parent.length; i++)
		{
			var aChild = parent[i].getElementsByTagName('a');

				if(typeof(aChild[0]) == 'object')
				{
					var xml = document.createElement('rdf:data');
						xml.setAttribute('url', aChild[0].href);
						xml.setAttribute('target', (aChild[0].target != "") ? aChild[0].target : '_top');
						parent[i].appendChild(xml);	
						parent[i].onclick = function()
						{
							window.open(this.lastChild.getAttribute('url'), this.lastChild.getAttribute('target'), null)
						}
						
						try 
						{
							parent[i].style.cursor = 'pointer';
						} 
						catch(e){}
				}
		}
	}

	function getChildLink(object, parent)
	{
		var parent 	= new Object(object.getElementsByTagName(parent));
		var child	= new Array();
		
		for(var i=0; i < parent.length; i++)
		{
			var aChild = parent[i].getElementsByTagName('a')

				if(typeof(aChild[0]) == 'object')
				{
					var xml = document.createElement('rdf:data');
						xml.setAttribute('url', aChild[0].href);
						xml.setAttribute('target', (aChild[0].target != "") ? aChild[0].target : '_top');
						parent[i].appendChild(xml);	
						parent[i].onclick = function()
						{
							window.open(this.lastChild.getAttribute('url'), this.lastChild.getAttribute('target'), null)
						}
						
						try 
						{
							parent[i].style.cursor = 'pointer';
						} 
						catch(e){}
				}
		}
	}
*/

	var interval = new Array();

	function switchMenu(show, id)
	{
		var elementById = null;
		var elementByTagName = null;
		
		try
		{
			elementById = document.getElementById(id);
		}
		catch(e) {}
		
		if(elementById != null)
		{
			try
			{
				elementByTagName = elementById.getElementsByTagName('ul');
			}
			catch(e) {}
			
			if(typeof(elementByTagName) == 'object')
			{
				if(show == true)
				{
					clearInterval(interval[id]);
					
					if(elementByTagName.length > 0)
						elementById.style.display = 'block';	
				}
				else
				{
					interval[id] = 	setInterval(function() 
									{
										document.getElementById(id).style.display = 'none';
									}, 500)
				}
			}
		}
	}
	
	function setMenuPosition(id, pos)
	{
		var elementById = null;
		
		try
		{
			elementById = document.getElementById(id);
		}
		catch(e) {}
		
		if(elementById != null)
			elementById.style.marginLeft = pos + 'px';
	}

	function setMenu()
	{
		//var url 	= new String(document.location.href);
		var object 	= new String();
		var image	= new String();

		var objects = new Array('services', 'support', 'partners', 'about', 'contact', 'home');
		var images	= new Array('49.png', '50.png', '48.png', '45.png', '46.png', '47.png');
		
		if(section == 'news' || section == 'archive')
			section = 'about';
		else if(section == 'default')
			section = 'home';
	
		for(var i=0; i < objects.length; i++)
		{
			var floatMenu;
			var regexp = new RegExp(objects[i].toString());
			
			if(section.toString().match(regexp) != null)
			{
				object 	= objects[i].toString();
				image	= images[i].toString();
				
				try
				{
					floatMenu = document.getElementById('floatMenu_' + objects[i].toString());

					if(typeof(floatMenu) == 'object')
					{
						floatMenu.style.display	= 'block';
						
						pos = findPosition(document.getElementById(objects[i].toString()))[0] - findPosition(document.getElementById('baseOfContent'))[0];
						
						setMenuPosition('floatMenu_' + objects[i].toString(), pos);
					}
				}
				catch(e){}
			}
			else
			{	
				try
				{
					floatMenu = document.getElementById('floatMenu_' + objects[i].toString());

					if(typeof(floatMenu) == 'object')
					{
						document.getElementById(objects[i]).onmouseover = function()
						{
							pos = findPosition(this)[0] - findPosition(document.getElementById('baseOfContent'))[0];
							
							switchMenu(true, 'floatMenu_' + this.id);
							setMenuPosition('floatMenu_' + this.id, pos);
						}
						
						document.getElementById(objects[i]).onmouseout = function()
						{
							switchMenu(false, 'floatMenu_' + this.id);
						}

						document.getElementById('floatMenu_' + objects[i]).onmouseover = function()
						{
							switchMenu(true, this.id);
						}
						
						document.getElementById('floatMenu_' + objects[i]).onmouseout = function()
						{
							switchMenu(false, this.id);
						}
					}
				}
				catch(e){}
			}

		}

		if(object != '')
		{
			var element 	= document.getElementById(object);
				element.src = '/images/' + image;
		}
	}	
	
	function addLoadEvent(func)
	{	
		var oldonload = window.onload;
		
		if (typeof window.onload != 'function'){
			window.onload = func;
		} else {
			window.onload = function(){
			oldonload();
			func();
			}
		}
	
	}


	// show menus for editing individual articles
	function toggleEditToolbar()
	{
		var oTglMenus = getObjByID('toggleEditArticleMenus');
		var menus = getNodesFromObj_filterByTagClass(document.body,new Array('div'), 'editArticleMenu');
		var displ = (oTglMenus.innerHTML.toLowerCase().indexOf('hide') > -1)?'none':'block';

		for(var i=0;i < menus.length; i++){ 
			if(!menus[i].id || menus[i].id == '') menus[i].id = 'editArticleMenu_tmp' + i;
			getStyleObj(menus[i].id).display = displ;// getStyleObj() is in util.js
		}

		if(displ == 'none'){
			oTglMenus.innerHTML = 'Edit Page';
			oTglMenus.className = '';
		}else{
			oTglMenus.innerHTML = 'Hide Edit Page';
			oTglMenus.className = 'emph';
		}
	}


	// grab tag/class-specific child nodes. Returns array of matching nodes.
	// clsName is optional
	function getNodesFromObj_filterByTagClass(oPNode,tgNames, clsName)
	{
		if(oPNode == null || !oPNode.getElementsByTagName) return new Array();
		var ndes = new Array();
		for(var j=0; j < tgNames.length; j++)
		{
			var all = oPNode.getElementsByTagName(tgNames[j]);
			for(var i=0;i<all.length;i++)
			{
				if(all[i].nodeName.toLowerCase() == tgNames[j].toLowerCase() )
				{
					if(clsName != null){
						if(all[i].className.toLowerCase() == clsName.toLowerCase())  ndes[ndes.length] = all[i];
					}else ndes[ndes.length] = all[i];
				}
			}
		}
		return ndes;
	}

	/*
	window.onload = function()
	{
		setMenu();
		
		if(BrowserDetect.browser == 'Explorer')
			getChildLink(document.getElementById('columnOnePosts'), 'div');	
		else
			document.getElementById('columnOnePosts').getChildLink('div');
			
		links = document.getElementsByTagName('ul');
		
		for(var i=0; i < links.length; i++)
		{
			if(BrowserDetect.browser == 'Explorer')
				getChildLink(links[i], 'li');	
			else
				links[i].getChildLink('li');	
		}
	}
	*/
	