﻿var TodaysMedia = {};

TodaysMedia.init = function()
{
	var selIndex,target,ctrl,tabs;
	
	selIndex = parseInt(Math.random() * 4) + 1;
	target = document.getElementById("toc_media_tab_" + selIndex);
	ctrl = document.getElementById("toc_media_controller");
	tabs = SlateDom.getElementsByClassName(ctrl.getElementsByTagName("div"),"media_tab");
	for(var i=0; i<tabs.length; i++)
	{
		SlateDom.addListener(tabs[i],"mouseover",TodaysMedia.highlight);
		SlateDom.addListener(tabs[i],"mouseout",TodaysMedia.lowlight);
	}
	
	try
	{
		SlateDom.dispatchEvent(target,"click");
	}
	catch(e)
	{		
		TodaysMedia.init()
	}
}

TodaysMedia.select = function(evt)
{
	var curElm, cntr, ctrl, divs, selIndex;
	
	curElm = SlateDom.getTarget(evt);
	cntr = document.getElementById("TodaysMediaContainer");
	ctrl = document.getElementById("toc_media_controller");
	divs = ctrl.getElementsByTagName("div");
	selIndex = curElm.id.substr(curElm.id.lastIndexOf("_")+1);
	
	for(var i=0; i<divs.length; i++)
	{
		TodaysMedia.turnOff(divs[i])
	}	
	TodaysMedia.turnOn(curElm)
	divs[0].style.backgroundColor = "#ccc";
	divs[divs.length-1].style.backgroundColor = "#ccc";
	
	for(var j=1; j<5; j++)
	{
		document.getElementById("toc_media_item_" + j).style.display = "none";
	}
		document.getElementById("toc_media_item_" + selIndex).style.display = "block";	
}

TodaysMedia.turnOn = function(elm)
{
	var bgColor,fontColor,borderColor;
	
	bgColor = "#fff";
	fontColor = "#666";
	borderColor = "#ccc"
	
	elm.setAttribute("status","on");
	with(elm.style)
	{
		backgroundColor = bgColor;
		color = fontColor;
		cursor = "default";
	}
	with(elm.previousSibling.style)
	{
		backgroundColor = borderColor;
	}
	with(elm.nextSibling.style)
	{
		backgroundColor = borderColor;
	}
}
TodaysMedia.turnOff = function(elm)
{
	var bgColor,fontColor;
	
	bgColor = (elm.className=="med_border")? "#fff": "#603";
	fontColor = "#fff";
	
	elm.setAttribute("status","off");
	with(elm.style)
	{
		backgroundColor = bgColor;
		color = fontColor;
		cursor = "pointer";
	}
}
TodaysMedia.highlight = function(evt)
{
	var elm = SlateDom.getTarget(evt);
	with(elm.style)
	{
		color = (elm.getAttribute("status")=="on")? "#666": "#ff0";
	}
}
TodaysMedia.lowlight = function(evt)
{
	var elm = SlateDom.getTarget(evt);
	with(elm.style)
	{
		color = (elm.getAttribute("status")=="on")? "#666": "#fff";
	}
}
