//standard.js
//common utility functions

//do browser detection here
//placeholder for now; more robust testing to follow
var isNN, isIE, isMac;
var agent = navigator.userAgent;
var isMac;

if (agent.lastIndexOf('Mac')<0) isMac=false;
else isMac=true;

if (document.all){
	isIE = true;
} else if (document.layers){
	isNN = true;
	document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP | Event.RESIZE);
    window.onresize=myResizeFunction;
}

//standard handler for dealing with
//netscape's bad habits
if (isNN)
{var ws = window.innerWidth;
 var hs = window.innerHeight;}
  
function myResizeFunction()
{if (isNN)
 {if ((window.innerWidth != ws) || (window.innerHeight != hs))
       {window.location.href=window.location.href;}
	   }
}
//makes layers, courtesy of peterg
function mkLay(n,w,h,x,y,z,vis,cnt,exn,exe) {
	if (isNN) {
		vis == 1 ? vis='show' : vis='hide';
		document.write('<layer width='+w+' height='+h+' left='+x+' top='+y+' name="'+n+'" z-index='+z+' visibility="'+vis+'" '+exn+'>'+cnt+'</layer>');
	} else if (isIE) {
		vis == 1 ? vis='visible' : vis='hidden';
		document.write('<div id="'+n+'" style="position:absolute;width:'+w+';height:'+h+';left:'+x+';top:'+y+';z-index:'+z+';visibility:'+vis+';'+exe+'" >'+cnt+'</div>');
	}
}

//cross-browser function to handle layer visibility
function visLay(nme,vis) {
	if (isNN) {
		vis ? vis='show' : vis='hide';
		document.layers[nme].visibility=vis;
	} else if (isIE) {
		vis ? vis='visible' : vis='hidden';
		document.all[nme].style.visibility=vis;
	}
}

//point struct; conveniently stores x & y
function point(x,y){
	this.x = x;
	this.y = y;
	return this;
}

//ie-only function returns x & y location
//of element id by looping up thru dom
//returns point
function getAbsOffset(id){
	var offX, offY;
	myEl = document.all[id];
	offX = myEl.offsetLeft;
	offY = myEl.offsetTop;

if (isMac) 
  while(myEl.parentElement != null){
		myEl =  myEl.parentElement;
		offX += myEl.offsetLeft;
		offY += myEl.offsetTop;
	}
else 
while(myEl.offsetParent != null){
	  myEl =  myEl.offsetParent;
	  offX += myEl.offsetLeft;
	  offY += myEl.offsetTop;
	}

	myPoint = new point(offX, offY);
	return myPoint;
}

// A function that don't do anything
function donull () {}

///////////////////////////////////////
//layerPos()
//cross-browser layer positioning
///////////////////////////////////////
function LayerPos(id,x,y){
	if (isNN){
		if (x != null) document.layers[id].left = x;
		if (y != null) document.layers[id].top = y;
	} else if(isIE){
		if (x != null) document.all[id].style.posLeft = x;
		if (y != null) document.all[id].style.posTop = y;
	}
}


function SwitchImg(which,newSrc,nnLayer){
	var layerInfo = "";
	if (isNN){
		layerInfo = nnLayer;
	}
	//eval(layerInfo + "document.images['" + which + "'].src = '" + newSrc.src + "'");
}

function GraphicSwap(flashpath,imagepath,width,height,border,url){
	//Modified by Brandon Cox bcox@inch.com
	//No Flash
	//if(isIE && (flashpath != "") & !isMac){
		//var str = '<OBJECT style="z-index: -10;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width='+ width +' height='+ height +'>  <param name="wmode" value="opaque">   <PARAM name="Movie" value="'+ flashpath +'"> </OBJECT>';
	//} else {
		var str = "";
		if (url != "") str+= '<A HREF="'+ url +'">';
		str += '<IMG SRC="'+ imagepath +'" WIDTH="'+ width +'" HEIGHT="'+ height +'" BORDER='+ border +'>';
		if (url != "") str+= '</A>';
	//}
	document.write(str);
}


var months = new Array();
months = ["January ","February ","March ","April ","May ","June ","July ","August ","September ","October ","November ","December "];
var days = new Array();
days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

function ShowDate(){
	var today = new Date();
	document.write("<center><b>" + "<font class='date'>" + days[today.getDay()] +"<br>"+ months[today.getMonth()] + today.getDate() + "</font>" + "</b></center>");
}

function rollon() 
{
	if (window.event.srcElement.className == "marketsub") 
	{
		window.event.srcElement.className = "marketsubhighlight"; // change class
	}
	else if (window.event.srcElement.className == "headlinks") 
	{
		window.event.srcElement.className = "headlinkshighlight"; // change class
	}
	else if (window.event.srcElement.className == "footlinks") 
	{
		window.event.srcElement.className = "footlinkshighlight"; // change class
	}
	else if (window.event.srcElement.className == "headhighlight") 
	{
		window.event.srcElement.className = "headhighlight2"; // change class
	}
}

function rolloff() 
{
	if (window.event.srcElement.className == "marketsubhighlight") 
	{
		window.event.srcElement.className = "marketsub"; // change class
	}
	else if (window.event.srcElement.className == "headlinkshighlight") 
	{
		window.event.srcElement.className = "headlinks"; // change class
	}
	else if (window.event.srcElement.className == "footlinkshighlight") 
	{
		window.event.srcElement.className = "footlinks"; // change class
	}
	else if (window.event.srcElement.className == "headhighlight2") 
	{
		window.event.srcElement.className = "headhighlight"; // change class
	}
}

// assign rollon() to handle onMouseOver events
document.onmouseover = rollon;

// assign rolloff() to handle onMouseOut events
document.onmouseout = rolloff;

