// BROWSER SNIFF

opera=(navigator.userAgent.indexOf('Opera')>-1)?1:0;



// SET VARIABLES

var om=0;
var od=0;
dFlag=1;
tFlag=1;




// MAIN NAVIGATION FUNCTIONS

function writeMenu(){
	menuString='<table cellpadding="0" cellspacing="0" border="0"><tr>';
	for(i=0;i<10;i++){
		if(i==5) menuString+='</table><table cellpadding="0" cellspacing="0" border="0"><tr>';
		menuString+='<td><div class="navMenuOut" id="menu'+(i+1)+'" onMouseOut="killMenu()" class="navTopLevel" onMouseOver="keepAlive()"><img src="/images/menuTopGrad.gif" width="1" height="17" border="0"><a href="/'+menus[i][0][1]+'/"><img src="/images/clr.gif" width="100" height="17" border="0"></a><br><div class="navMenuIn"><table cellspacing="0" cellpadding="1" border="0" width="100%">';
		for(n=1;n<menus[i].length;n++){
			menuString+='<tr><td onMouseOver="hlRow(this,1)" onMouseOut="hlRow(this,0)" onClick=document.location="'+menus[i][n][1]+'">'+menus[i][n][0]+'</td></tr>';
		}
		menuString+='</table></div><nobr><img src="/images/menuBtmLeft.gif" width="5" height="8" alt=""><img src="/images/menuBtmMid.gif" width="120" height="8" alt=""><img src="/images/menuBtmRight.gif" width="5" height="8" alt=""></nobr><br></div></td><td id="nav'+(i+1)+'" onMouseOver="openMenu('+(i+1)+');keepAlive();" onMouseOut="killMenu()" class="navTopLevel"><img src="/images/nav_'+menus[i][0][1]+'.gif" height="18" border="0" alt="" onMouseOver="keepAlive()"></td>';
	}
	menuString+='</tr></table>';
	document.write(menuString);
}
							
function openMenu(m){
	if(om && om!=m) closeAllMenus();
	if(!om){
		newTo=setTimeout("delayOpen("+m+")",100);
		dFlag=0;
	}
}

function delayOpen(m){
	document.getElementById('nav'+m).className="navTopLevelOn";
	document.getElementById('menu'+m).style.visibility='visible';
	om=m;
}

function closeAllMenus(){
	for (i=1; i<11; i++){
		document.getElementById('nav'+i).className="navTopLevel";
		document.getElementById('menu'+i).style.visibility='hidden';
		om=0;
	}
}

function killMenu(){
	if(!dFlag){
		clearTimeout(newTo);
		dFlag=1;
	}
	if(om){
		killDiv = setTimeout("closeAllMenus()",250);
		tFlag = 0;
	}
	if(od){
		killDiv = setTimeout("closeDrop()",100);
		tFlag = 0;
	}
}

function keepAlive(){
	if (!tFlag){
		clearTimeout(killDiv);
		tFlag=1;
	}
}




// SEARCH DROP-DOWN FUNCTIONS

function openDrop(d){
	if(om) closeAllMenus();
	document.getElementById(d).style.visibility='visible';

	if(document.all && !opera) document.getElementById(d).childNodes[0].doScroll("scrollbarPageUp");
	od=d;
}

function closeDrop(){
	document.getElementById(od).style.visibility='hidden';
	od=0;
}

function killDrop(){
	if(od){
		killDiv = setTimeout("closeDrop()",100);
		tFlag = 0;
	}
	if(om){
		killDiv = setTimeout("closeAllMenus()",250);
		tFlag = 0;
	}
}

function changeSelection(i){
	document.getElementById('menuType').innerHTML=i;
	document.getElementById('menuSelected').innerHTML=i;
	closeDrop();
}

function setSearchArea(area){
	document.search_form.area.value = area;
}

function formFill(el,s){
	fill='Search:';
	if(s){
		el.style.background='#FFF';
		if(el.value==fill) el.value='';
	}
	else{
		if(!el.value) el.value=fill;
		el.style.background='#EEE';
	}
}

//function hlRow(e,s){
//	if(s){
//		keepAlive();
//		e.style.background="#F8F2EF";
//	}
//	else e.style.background="transparent";
//}

function hlRow(e,s){
	if(s){
		keepAlive();
		e.style.background='#F8F2EF url("/images/menuArrow.gif") 2px 2px no-repeat';
	}
	else e.style.background='url("/images/menuArrow.gif") 2px 2px no-repeat';
}

function hlMenu(e,s){
	if(s){
		keepAlive();
		e.style.background="#EDEDEF";
	}
	else e.style.background="transparent";
}

function hl(e){
	if(e.className!='sectionListOn'){
		if(e.className) e.className='';
		else e.className='sectionListOver';
	}
}
function hl2(e){
	if(e.className) e.className='';
	else e.className='sectionRelatedOver';
}



// CROSS-BROWSER TRANSPARENCY FUNCTIONS

function opacity(id, opacStart, opacEnd, millisec){ 
	var speed=Math.round(millisec/100); 
	var timer=0; 
	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++; 
		} 
	} 
} 

function changeOpac(opacity, id){ 
    var object=document.getElementById(id).style; 
    object.opacity=(opacity/100); 
    object.MozOpacity=(opacity/100); 
    object.KhtmlOpacity=(opacity/100); 
    object.filter="alpha(opacity="+opacity+")"; 
} 



// RANDOM PROGRAM DISPLAY

ranNum=Math.floor(Math.random()*progs.length);
rn=ranNum;
timeFade = 290;
timeRefresh = 6000;
cp = null;

function getRandomProg(p){
	topBox=document.getElementById('topFeature');
	if(p=='link') document.location=progs[rn][2];
	else{
		changeOpac(0,'topFeature');
		topBox.innerHTML='<span>'+progs[rn][0]+'</span><br>'+progs[rn][1];
		opacity('topFeature',0,100,timeFade);
		cp=setTimeout("changeRandomProg(1)",timeRefresh);
	}
}

function changeRandomProg(stp){
	if(stp==1){
		rn++;
		if(rn>progs.length-1) rn=0;
		opacity('topFeature',100,0,timeFade);
		setTimeout("changeRandomProg(2)",(timeFade+10));
	}
	else{
		topBox.innerHTML='<span>'+progs[rn][0]+'</span><br>'+progs[rn][1];
		opacity('topFeature',0,100,290);
		cp=setTimeout("changeRandomProg(1)",timeRefresh);
	}
}

function suspendRandomProg(sw){
	if(sw) clearTimeout(cp);
	else cp=setTimeout("changeRandomProg(1)",timeRefresh/2);
}
