function getElem(elName)
{
	return document.getElementById?document.getElementById(elName):null;
}
function gotosite(loc)
{
	if(loc != null && loc != '')
	{
		location.href = loc;
	}
}
var requests = new Object();
var xmlReqInProgress = false;
function RequestFactory()
{
	this.createRequest = function(rID, url, needsLoading)
	{
		var r;
		if(!xmlReqInProgress)
		{
			xmlReqInProgress = true;
			if(!requests[rID])
			{
				if(window.XMLHttpRequest)
				{
					r = new XMLHttpRequest();
					requests[rID] = new XMLRequest(r, needsLoading);
	        		requests[rID].req.open('GET', url, true);
					requests[rID].req.send(null);
				}
				else if(window.ActiveXObject)
				{
					r = new ActiveXObject('Microsoft.XMLHTTP');
					if(r)
					{
						requests[rID] = new XMLRequest(r, needsLoading);
						requests[rID].req.open('GET', url, true);
						requests[rID].req.send();
					}
				}
				else
				{
					requests[rID] = null;
				}
			}
			return requests[rID];
		}
		else
		{
			return null;
		}
	}
}
function getOffSets()
{
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	
	return new Array(x,y);
}
var selfXMLR;
function XMLRequest(req, needsLoading)
{
	selfXMLR = this;
	this.req = req;
	this.isInit = false;
	this.interval = 0;
	this.executing = false;
	this.isFirstRun = true;
	this.func = null;
	this.args = new Array();
	this.div = null;
	this.needsLoading = needsLoading;
	
	this.init = function()
	{
		if(this.req.readyState == 4)
		{
			if(this.req.status == 200)
			{
				this.isInit = true;
			}
		}
		
		if(!this.isInit)
		{
			if(this.isFirstRun)
			{
				this.interval = setInterval('selfXMLR.init()', 2);
			}
		}
		else
		{ 
			clearInterval(this.interval);
			if(this.executing)
			{
				this.execute();
			}
		}
		this.isFirstRun = false;
	}
	
	this.createLoadingHolder = function()
	{
		/*
		var body = document.getElementsByTagName('body')[0];
		var y = getOffSets()[1];
		this.div = document.createElement('div');
		this.div.setAttribute('id', 'loadingDiv');
		this.div.style.width = '100%';
		this.div.style.fontWeight = 'bold';
		this.div.style.backgroundColor = '#FFFFFF';
		this.div.style.color = '#000000';
		this.div.style.padding = '10px';
		this.div.style.display = 'none';
		this.div.style.position = 'absolute';
		this.div.style.top = y + 'px';
		this.div.style.left = '0px';
		this.div.style.zIndex = 100;
		this.div.appendChild(document.createTextNode('Loading...'));
		if(body)
		{
			body.appendChild(this.div);
		}
		*/
	}
	
	this.hideLoading = function()
	{
		//this.div.style.display = 'none';
	}
	
	this.showLoading = function()
	{
		//this.div.style.display = 'block';
	}
	
	this.createMethod = function(func, args)
	{
		this.func = func;
		this.args = args;
	}
	
	this.getXMLDoc = function()
	{
		return this.req.responseXML;
	}
	
	this.execute = function()
	{
		this.executing = true;
		if(this.needsLoading)
		{
			this.showLoading();
		}
		if(this.isInit)
		{
			clearInterval(this.interval);
			this.func.apply(this,this.args);
			this.hideLoading();
			xmlReqInProgress = false;
		}
		else
		{
			this.init();
		}
	}
	
	this.createLoadingHolder();
	this.init();
}
var rf = new RequestFactory();
var rque = new Array();
var ids = new Object();
var currentReq = null;

function proxyReq()
{
	this.url = null;
	this.id = null;
	this.nl = null;
	this.f = null;
	this.args = null;
}

function executeXML(url, id, needsLoading, func, args)
{
	var req = null;
	var newArgs;
	var success = false;
		
	if(id != null && id != '')
	{
		if(ids[id] == null)
		{
			ids[id] = new proxyReq();
			ids[id].url = url;
			ids[id].id = id;
			ids[id].nl = needsLoading;
			ids[id].f = func;		
			
			if(!args || typeof args != 'object')
			{
				newArgs = 'new Array(\'\')';
			}
			else
			{
				newArgs = 'new Array(';
				for(var i = 0; i < i.length; i++)
				{
					if(i < i.length -1)
					{
						newArgs += '\'' + args[i] + '\',';
					}
					else
					{
						newArgs += '\'' + args[i] + '\'';
					}
				}
				newArgs += ')';
			}
			ids[id].args = newArgs;
		}
		
		req = rf.createRequest(id, url, needsLoading);
		if(req != null)
		{
			req.createMethod(func,args);
			req.execute(req);
			success = true;
		}
		else if(ids[id] != null)
		{
			if(currentReq == ids[id] || currentReq == null)
			{
				setTimeout('executeXML(\'' + ids[id].url + '\',\'' + ids[id].id + '\',' + ids[id].nl + ',' + ids[id].f + ',' + ids[id].args + ');',2);
			}
		}
	}
	currentReq = ids[id];
	return success;
}

var pc_ie="Microsoft Internet Explorer";var pc_nn="Netscape"; var pc_ns="Netscape";var pc_browser=navigator.appName;var pc_mac="MacPPC";var pc_os=navigator.platform;
function eObj(){return(pc_browser==pc_nn?'event':'\'\'');}
// DHTML CONTROLS
var layerRef = '';var styleSwitch = '';var layerRefOther = '';
if (document.getElementById)
{
	layerRef='document.getElementById(layer)';
	layerRefOther='document.getElementById(referenceLayer)';
	styleSwitch='.style';
}
else if(pc_browser==pc_nn)
{
	layerRef='document.layers[layer]';
	layerRefOther='document.layers[referenceLayer]';
}
else if(pc_browser == pc_ie)
{
	layerRef='document.all[layer]';
	layerRefOther='document.all[referenceLayer]';
	styleSwitch='.style';
}
function move(layer, top, left)
{
	px=pc_browser==pc_nn?'px':'';
	eval(layerRef + styleSwitch).top=top+px;
	eval(layerRef + styleSwitch).left=left+px;
}
function moveToMouse(e, layer, offset_x, offset_y)
{
	x=getPointerX(e);
	y=getPointerY(e);
	move(layer,eval(y)+ eval(offset_y),eval(x)+eval(offset_x));
}
function getPointerX(e)
{
	return(e != ''?e.pageX:getRealLeftByObj(window.event.srcElement));
}
function getPointerY(e)
{
	return(e != ''?e.pageY:getRealTopByObj(window.event.srcElement));
}
function getRealLeft(layer)
{
	thisObj=document.getElementById(layer);
	xPos=getRealLeftByObj(thisObj);
	return xPos;
}
function getRealTop(layer)
{
	thisObj=document.getElementById(layer);
	yPos=getRealTopByObj(thisObj);
	return yPos;
}
function getRealLeftByObj(thisObj)
{
	xPos=0;
	if(thisObj)
	{
		xPos=thisObj.offsetLeft;
		tempEl=thisObj.offsetParent;
		while(tempEl!=null)
		{
			xPos+=tempEl.offsetLeft;
			tempEl=tempEl.offsetParent;
		}
	}
	return event.clientX + document.documentElement.scrollLeft;//xPos;
}
function getRealTopByObj(thisObj)
{
	yPos = 0;
	if(thisObj)
	{
		yPos=thisObj.offsetTop;
		tempEl=thisObj.offsetParent;
		while(tempEl!=null){
			yPos+=tempEl.offsetTop;
			tempEl=tempEl.offsetParent;
		}
	}
	return event.clientY + document.documentElement.scrollTop;//yPos;
}

var loc = '/' + g_Sport + '/xml/headlineXML?storyId=';
var isOff = true;
function lp(locat,theId,showPreview,type)
{
	var el = getElem('holder');	
	if(okToProceed)
	{
		if(isOff && el)
		{
			el.innerHTML = 'GENERATING PREVIEW...';
			el.style.visibility = 'visible';
		}
		isOff = false;
		locat += ('&type=' + type);
		executeXML(locat,theId,false,showPreview,[null]);
	}
}
function showPreview(e)
{
	var doc = this.getXMLDoc();
	var nodes = doc.getElementsByTagName('node');
	var headlineNode = null;
	var photoNode = null;
	var bodyNode = null;
	var urlNode = null;
	var bylineNode = null;
	var hd;
	var hh;
	var bh;
	var holder = getElem('holder');
	holder.innerHTML = '';
	
	for(var i=0; i<nodes.length; i++)
	{
		if(nodes[i].getAttribute('id') == 'text')
		{
			bodyNode = nodes[i];
		}
	}
	
	if(bodyNode && holder)
	{
		holder.innerHTML = bodyNode.childNodes[0].nodeValue;
	}
}

function m(e)
{
	var yoff = pc_browser==pc_ie?15:10;
	var xoff = pc_browser==pc_ie?15:45;
	if(getElem('holder'))
	{
		moveToMouse(e,'holder',xoff,yoff);
	}
}

function hidePreview()
{
	isOff = true;
	setTimeout('checkStatus()',1000);
}

function buildHolder()
{
	var bod = document.getElementById('mc');
	var holder;
	var d = document;
	
	if(bod && okToProceed)
	{
		holder = document.createElement('div');
		holder.setAttribute('id','holder');
		holder.style.visibility = 'hidden';
		holder.style.position = 'absolute';
		holder.style.zIndex = '99';
		holder.style.width = '200px';
		holder.style.backgroundColor = '#F1F4D4';
		holder.style.borderWidth = '1px';
		holder.style.borderStyle = 'solid'; 
		holder.style.borderColor = '#C6CA9A';
		holder.style.color = '#000000';
		holder.style.lineHeight = '12px';
		holder.style.padding = '5px 3px';
		holder.style.fontFamily = 'Verdana, Sans-serif';
		holder.style.fontSize = '10px';
		holder.innerHTML = '';
		bod.appendChild(holder);
	}
	else
	{
		setTimeout('buildHolder()',1000);
	}
}

function checkStatus()
{
	var el = getElem('holder');
	if(isOff && el)
	{
		el.style.visibility = 'hidden';
	}
}

var okToProceed = false;
function pollPage()
{
	if(document.all)
	{
		func = function()
		{
			okToProceed = true;
		}
		window.attachEvent('onload', func);
	}
	else
	{
		okToProceed = true;
	}
}

pollPage();
buildHolder();