var smooth_timer;

function expandTab (i) {
	var rowObj = (document.getElementById) ? document.getElementById(i) : eval("document.all['"+i+"']");
	var imgObj = (document.getElementById) ? document.getElementById(i+'Img') : eval("document.all['"+i+"Img']");
	if ( rowObj != null ) {
		if ( rowObj.style.display == "none" ) {
			smoothHeight(i, 0, 100, 10, 'o');
			imgObj.src = "/pub_images/compress.gif";
			rowObj.style.display = "";
		} else {
			smoothHeight(i, 100, 0, 10, 'o');
			imgObj.src = "/pub_images/expand.gif";
			rowObj.style.display = "none";
		}
	}
}

function smoothHeight(id, curH, targetH, stepH, mode) {
	diff = targetH - curH;
	if (diff != 0) {
		newH = (diff > 0) ? curH + stepH : curH - stepH;
		((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
		if (smooth_timer) window.clearTimeout(smooth_timer);
		smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 20 );
	}
	else if (mode != "o") ((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";
}

var offsetfrommouse = [15,15];
var displayduration = 0;
var currentimagewidth = 0;

if ( document.getElementById || document.all ) {
	document.write('<div id="episodeInfoId">');
	document.write('</div>');
}

function getEpisodeObj() {
	if ( document.getElementById )
		return document.getElementById("episodeInfoId").style
	else if ( document.all )
		return document.all.episodeInfoId.style
}

function getEpisodeObjNoStyle() {
	if ( document.getElementById )
		return document.getElementById("episodeInfoId")
	else if ( document.all )
		return document.all.episodeInfoId
}


function trueBody() {
	return (! window.opera && document.compatMode && document.compatMode !=" BackCompat" )? document.documentElement : document.body
}

function showEpisodeInfo(ep_title, date, ep_num, ep_desc, ep_img) {
	if ( ep_img == '' ) { ep_img = 'http://www.iheartmorganwebb.com/pub_images/tba_2.jpg' }
	document.onmousemove = followmouse
	newHTML = '<div>'
	newHTML = newHTML + '<img src="/pub_images/episodeInfoTop.gif" alt="" title="" />'
	newHTML = newHTML + '<div class="ep_title">' + ep_title + '<br /><span class="smallFont" style="font-weight: normal;">'+date+' ET/PT<br /></div>'
	newHTML = newHTML + '<div class="ep_space" height="1"></div>'
	newHTML = newHTML + '<div class="innerEpText"><img src="'+ep_img+'" width="90" height="68" border="0" class="border" alt="'+ep_title+'" title="'+ep_title+'" hspace="3" vspace="1" align="left" /><strong>Episode #'+ep_num+'</strong><br /><br />'+ep_desc+'<br clear="all" /></div>'
	newHTML = newHTML + '<img src="/pub_images/episodeInfoBottom.gif" alt="" title="" />'
	newHTML = newHTML + '</div>'
	getEpisodeObjNoStyle().innerHTML = newHTML
	getEpisodeObj().visibility="visible"

}

function hideEpisodeInfo() {
	getEpisodeObj().visibility = "hidden"
	document.onmousemove=""
	getEpisodeObj().left = "-500px"
}

function followmouse(e) {
	var xcoord = offsetfrommouse[0]
	var ycoord = offsetfrommouse[1]

	var docwidth = document.all? trueBody().scrollLeft+trueBody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight = document.all? Math.min(trueBody().scrollHeight, trueBody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)

        //if ( document.all ) {
        //      getEpisodeObjNoStyle().innerHTML = 'A = ' + trueBody().scrollHeight + '<br>B = ' + trueBody().clientHeight;
        //} else {
        //      getEpisodeObjNoStyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
        //}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 300){
			xcoord = e.pageX - xcoord - 200; // Move to the left side of the cursor
			// alert(xcoord);
		} else {
			xcoord += e.pageX;
		}
		if (e.pageY - docheight < (currentimagewidth + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimagewidth + e.pageY - docheight - trueBody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + trueBody().scrollLeft - xcoord - 200; // Move to the left side of the cursor
		} else {
			xcoord += trueBody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimagewidth + 230)){
			ycoord += event.clientY + trueBody().scrollTop - Math.max(0,(230 + currentimagewidth + event.clientY - docheight));
		} else {
			ycoord += trueBody().scrollTop + event.clientY;
		}
	}

	var docwidth = document.all? trueBody().scrollLeft+trueBody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight = document.all? Math.max(trueBody().scrollHeight, trueBody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

	getEpisodeObj().left = xcoord+"px"
	getEpisodeObj().top = ycoord+"px"
}

function toggleCalendar(i, m)
{
	if ( document.getElementById('calendar'+i).style.display == '' )
	{
		document.getElementById('calendar'+i).style.display = 'none'
		document.getElementById('image'+i).src = '/pub_images/expandplus.jpg';
	}
	else
	{
		document.getElementById('calendar'+i).style.display = ''
		document.getElementById('image'+i).src = '/pub_images/collapseminus.jpg';
	}
	for ( j = 1; j < m; j++ )
	{
		if ( i != j ) {
			document.getElementById('calendar'+j).style.display = 'none'
			document.getElementById('image'+j).src = '/pub_images/expandplus.jpg';
		}
	}
}

function toggleOpen(i)
{
	var divEle = document.getElementById('game_'+i);

	if ( divEle.style.display == 'none' ) {
		divEle.style.display = ''
	} else {
		divEle.style.display = 'none'
	}
}
