/************************
Header Functions
*************************/
var theButtons;
var theAnchors;
var theDivs;

addLoadEvent(initChannelButtons);

function initChannelButtons(){

theButtons = document.getElementById('channel_buttons');
theAnchors = theButtons.getElementsByTagName("a");

}

function checkForCookie(){}
// Checks to see if there is a cookie. 
// IF cookie, select the proper button for the on state
// IF not, do nothing

function setButton(channel){ 
// Turns the proper button to the "on" state, makes sure the others are on "off"
// also turns all buttons "off" if commanded from popup window
//var theButton = document.getElementById('live_button');
//alert (theButton.name);
//var theAnchor = theButton.getElementsByTagName("a");
//theAnchor[0].className = "on"

var channel_map = {0: "kcrwlive",
                   1: "kcrwmusic",
                   2: "kcrwnews"}
for (i = 0; i < theAnchors.length; i++){
	if (i== (channel)){
		theAnchors[i].className = "on";
		//mediaPopup(i);
        launchPlayer("?type=live&id="+channel_map[channel]);
	}else{
		theAnchors[i].className = "off";
		
	}
}
}

function changeButton(channel){ 
// This changes the main page channel only... called from the media player
if (channel=="off"){
//	alert('caught it!');

	for (i = 0; i < theAnchors.length; i++){
		theAnchors[i].className = "off";
	}
}else{
for (i = 0; i < theAnchors.length; i++){
	if (i== (channel)){
		theAnchors[i].className = "on";
	}else{
		theAnchors[i].className = "off";
	}
}
}
}



function writeCookie(){}
// writes a new cookie



var newwindow = '';
function mediaPopup(channel){

	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = "/media_player_channel?channel="+ channel;
	}
	else
	{
		newwindow = window.open("/media_player_channel?channel="+ channel ,"player","toolbar=no,menubar=no,width=700px,height=465px,resizable");
		if (!newwindow.opener) newwindow.opener = self;
	}
//if (window.focus) {newwindow.focus()}
	newwindow.focus();
	return false;

}
// this calls the media popup

function mediaPopupArchive(action,url){
	if (!newwindow.closed && newwindow.location)
	{
//		newwindow.location.href = url + "/media_player_archives";
		newwindow.location.href = url + "/media_player_archives?action=" + action;
	}
	else
	{
//		newwindow = window.open(url + "/media_player_archives", "player","toolbar=no,menubar=no,width=700px,height=375px,resizable");
		newwindow = window.open(url + "/media_player_archives?action=" + action, "player","toolbar=no,menubar=no,width=700px,height=465px,resizable");
 
		if (!newwindow.opener) newwindow.opener = self;
	}
//	if (window.focus) {newwindow.focus()}
	newwindow.focus();
	return false;

}

var popWin = '';

function liveNowPlaying()	{
	otherPopup('/nowPlayPopLive');
	return false;
}

function musicNowPlaying()	{
	otherPopup('/nowPlayPopMusic');
	return false;
}

function otherPopup(url){
	if (!popWin.closed && popWin.location)
	{
		popWin.location.href = url;
	}  else 	{
		popWin = window.open(url,"nowplaypop","toolbar=no,menubar=no,width=400px,height=225px,resizable");

	}
	popWin.focus();
	return false;

}


/************************
Other Functions
*************************/

// NPR Localization

window.station="KCRW_FM";
window.localize=true;

// For DART

var axel = Math.random() + "";
var ord = axel * 1000000000000000000;


