//cerberus.js for new website
// 
// ver 3.0

//Browser capablilities
navigator.di=typeof(document.images)!='undefined';
navigator.dl=typeof(document.layers)!='undefined';
navigator.da=typeof(document.all)!='undefined';
navigator.w3c=((typeof(document.getElementById)!='undefined')&&(typeof(document.createElement)!='undefined'));
navigator.webtv=navigator.userAgent.indexOf('WebTV')>-1;

navigator.bt=bt();
//Browser Type used by the navbar 
function bt(){
	if ((typeof(document.documentElement)!="undefined") && (typeof(document.documentElement.scrollTop)!="undefined")) return 3;
	if(typeof(window.pageYOffset)!="undefined") return 1;
	return 0;
}

var getEl=null;		//vars for functions
var getElStyle=null;
var hb=new HB; 		//create object for Hover Buttons

function walkLayers(d, id){					//hack function for NN4x
	var o=null;
	for( var e in d) { 						//first check for id'd elements with document layer
		if(e==id) {
			d[e].id=id;						//NN4 uses NAME for images so create Property here
			return d[e];  					//return object if id matches
		}
	}
	for( var l in d.layers ){				//check if matches dhtml layers
		if(l==id) return d.layers[l];		//return matching layer
		if(d.layers[l].document) {			//check if element in dhtml layer 
			o=walkLayers(d.layers[l].document, id);
			if(o) return o;
		}			
	}
	return o;								//if previously found, pass on object	
}

if(navigator.dl){							//set functions
	getEl=new Function("id", "return walkLayers(document, id)");
	getElStyle=getEl;
}
else if(navigator.da){
	getEl=new Function("id", "return document.all[id]");
	getElStyle=new Function("id", "return document.all[id].style");
}
else if(navigator.w3c){
	getEl=new Function("id", "return document.getElementById(id)");
	getElStyle=new Function("id", "return document.getElementById(id).style");
}

//############## new version special buttons use with PHP ###
function addBtn(id, pfx, sfx){
	var me=this;
	var a=new Array;
	for(var i=0; i<2; i++ ){
		a[i]=new Image;
		a[i].src=pfx + i + '.' + sfx;
		a[i].handle=null;
	}	
	me.btns[id]=a;
}

function hoverBtn(id, state, idx){		
	var b=this.btns[id];				//Use typeof, IE <6.0 doesn't have constant 'undefined'
	if(typeof(idx) == 'undefined'){							//idx for 'up' buttons 
		if(!b.handle) { b.handle=getEl(id);	} //set once
		b.handle.src=b[state].src;	}
	else{		//idx for 'up' buttons
		if(!b.handle) { b.handle=new Array; } 				//create array if missing
		if(!b.handle[idx]){ b.handle[idx]=getEl(id+idx); }	//set once
		b.handle[idx].src=b[state].src;
	}
}

function HB(){
	this.btns=new Object;
	this.add=addBtn;
	this.hover=hoverBtn;
}
//###########################################################



//###########################################################
//MSIE hack for lack of CSS LI roll overs
<!--//--><![CDATA[//><!--

var sfHover = function() {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);

//--><!]]> 


//###########################################################
//New Sticky routines

function getScrollHack(){
	//seems damn new browsers set one or the other, opposite stays 0 
	//if this behavior changes will have to add more code forks
	//many set document.documentElement.scrollTop
	//NN sets window.document.body.scrollTop
	//and damn Opera sets both!!!!
	
	if(window.document.documentElement.scrollTop) return window.document.documentElement.scrollTop;
	if(window.document.body.scrollTop) return window.document.body.scrollTop;
	return 0;
}
	
function browserType(){
	if(typeof(document.documentElement)!="undefined") {
		if(typeof(document.documentElement.scrollTop)!="undefined") return 3;
	}
	if(typeof(window.pageYOffset)!="undefined") return 1;
	//Don't test for document.body.scrollTop, WebTV has a static 0 but uses 'window.pageYOffset'!
	//But IE4 as document.body.scrollTop but no window.pageYOffset so MUST test AFTER wpYO
	if(typeof(document.body.scrollTop)!="undefined") return 2;
	return 0;
}

function jump(){
	var me=this;
	me.dyW=me.getD();
	me.hStyle.top=me.dyW+me.yOfs+me.units; //relocate
	setTimeout(me.id + "_x.sticky()",5);
}

function bounce(){
	var me=this;
	me.dyW=me.getD();
	var t=me.dy;
	if(me.dyW!=me.dy){
		var pos=(me.dyW-me.dy) * .2;
		pos>0 ? pos=Math.ceil(pos) : pos=Math.floor(pos);
		me.dy+=pos;
		t=me.dy + me.yOfs;
		me.hStyle.top= t + me.units;
	}	
	setTimeout(me.id + "_x.sticky()",5);
}

function makeSticky(id,useBounce){		
	var me=getEl(id);
	var bt=browserType();
	switch(bt){
		//DOM
		case 3: me.getD=getScrollHack; break;
		//IE4
		case 2: me.getD=new Function("return document.body.scrollTop;"); break;
		//NN4
		case 1: me.getD=new Function("return window.pageYOffset;"); break;
		//Text or Ancient
		default:  me.getD=new Function("return 0");
	}
	me.units = bt>1 ? "px" : "";	
	me.hStyle=getElStyle(id);					//handle to style
	me.yOfs=(typeof(me.pageY)=='number' ? me.pageY : 0); 		//el's init yOfs
	me.yOfs+= (typeof(me.offsetTop)=='number' ? me.offsetTop: 0);	//WebTV fix
	me.dy=0;							//el's delta y init as zero
	me.sticky=(useBounce ? bounce : jump );					//set sticky type
	window[me.id+"_x"]=me;			//make a universal document handle		
	me.sticky();
	//return me.hStyle; 			//use to make visible
}

function bootstrap(){
	if(!(navigator.dl || navigator.webtv)) makeSticky('navbar',1);
}
  
function statusPrompt(text){
	window.status=text;
	return true;
}

function demo(m){ 
	alert(m);
	return void(0);		
}

function dummy(){
	alert('This is just a sample link');
	return false;
}
