// Form Submission via Hyperlink
function submitform()
{
  document.OVGSearch.submit();
}

// Category Menu / Subcategory Menu Hover Blocks
// compensation for lack of IE support of the :hover psuedo class
// Son of Suckerfish - Modified by Ben - OVGuide
sfHover = function() {
 	var ol = document.getElementById("menuCategory");
	var sfEls = ol.getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		 	reset(sfEls);
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
	
	document.onmouseout=function() {
	 	reset(sfEls);
	};
}

function reset(sfEls) {
	for (var j=0; j<sfEls.length; j++) {
		sfEls[j].className=sfEls[j].className.replace(new RegExp(" hover\\b"), "");
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);




// External Links in New Window
// Script written by Drew Noakes -- http://drewnoakes.com
function initLinks() {
  for (i in document.links) {
    link = document.links[i];
    if (link.rel && link.rel.indexOf('external')!=-1) {
      link.onclick = onExternalLinkActivate;
      link.onkeypress = onExternalLinkActivate;
    }
  }
}

function onExternalLinkActivate() {
  window.open(this.href);
  return false;
}



// OVBUZZ
function pauseTimer() {
	clearTimeout(timerId);
	return true;
}

function resetTimer() {
 	var randomTimeout = (Math.floor(Math.random()*15000) + 15000);
 	pauseTimer();
	timerId = setTimeout('rotateKeywords(0)', randomTimeout);
	return true;
}

var userClicks = 0;
var timerId;

function rotateKeywords(click) {
 	userClicks += click;
 	
	if(20 == userClicks) {
	 	window.location.reload();
	} else {
	 	itemsToDisplay = 20;
	 	list = ol.getElementsByTagName("LI");
	 	var randomnumber = (Math.floor(Math.random()*4) + 2);
	 	hideNum = randomnumber;
	 	displayNum = randomnumber;
	 	listLength = list.length;
	 	start = 0; 
	 	end = listLength - (hideNum + displayNum + itemsToDisplay);
	 	
	 	var randomPosition = (Math.floor(Math.random()* end) + start);
	 	//alert(randomPosition);
	 	i = listLength-1;
	 	while(0 < hideNum) {
			list.item(i).style.display = 'none';
			//ol.appendChild(list.item(i));
			ol.insertBefore(list.item(i), list.item(randomPosition));
			hideNum--;
		}
		
		for(i=listLength-1; i >= (listLength-itemsToDisplay-randomnumber); i--) {
			if(displayNum > 0 && 'none' == list.item(i).style.display) {
				list.item(i).style.display = '';
				displayNum--;
			}
		}
		
		if(0 == click) {
			resetTimer();
		}
		//getVisits(click);
	}
}
// window.onload = initLinks;


// Browser Detection
//examples on how to use this 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();

// Homepage Feature Box
//** Tab Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com/dynamicindex17/tabcontent.htm)
// Modified by Wilson Wang Mar 31 2008

function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
	this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.prototype={

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
		//var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		this.expandsubcontent(subcontentid)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
		}
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
		}
	},
		
	init:function(){
	 	
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this //this here refers to the container object, we are passing it in a var
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					//this here refers to the tab being clicked
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
			}
			
		} //END for loop
			
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
			var dbox = document.getElementById('dbox');
		//	dbox.onmouseover = function(){
		//	 	tabinstance.pauseTimer();
	//		}
	//		dbox.onmouseout = function (){
	//	  		tabinstance.startTimer();
	//	  	}
	}, //END int() function
	startTimer:function(){
		this.pauseTimer();
 		var randomTimeout = (Math.floor(Math.random()*4000) + 8000);
 		//get_next_sites_dbox is the ajax refresh function
 		this.timerId = setTimeout('get_next_sites_dbox(\"fnw\", \"1\", \"1\")', randomTimeout);
 		return true;
	},
	pauseTimer:function(){
		clearTimeout(this.timerId);
		return true;
	}
	

}
