//initPrograms.js - compare to initPlaylist.js
//2008-03-02, Luke McKenzie theclockspot.com

//Not all of the Programs page is dynamically generated: the actual program info is actually just php-included in a new page
//(that way the show id can be in the url and people can bookmark it etc).
//However, the show lister is dynamically populated, as is the playlist.

//For the show selector: <div id='showselectordiv'>
//For the nav tools: <div id='navdiv'>
//For the playlist results: <div id='resultsdiv'>

//requires compShowSelector.js (components)
//requires compCalendarNav.js
//requires compOrderSelector.js
//requires lookupPlaylist.js (ajax lookup)

//var reloadSeconds; //if -1, not reloading.

//handle show selector onChange
function onShowSelect() {
	q=getShowSelectorValue();
	window.location = '?id='+q;
	/*if(q==-1) reloadSwitch(true); else reloadSwitch(false); //only do reloads when "all shows" is selected
	r=document.getElementById("showart");
	if(q>-1) { r.style.background='url('+pathtohome+'128/'+getImgurl()+')'; r.style.display='block'; }
	else { r.style.background='none'; r.style.display='none'; }
	lookupPlaylist(getStartDate(),getEndDate(),getShowSelectorValue(),getOrder()); //playlistresults.js*/
}
function onCalendarNav(isreset) {
	lookupPlaylist(getStartDate(),getEndDate(),getShowSelectorValue(),getOrder()); //playlistresults.js
	//if(isreset) reloadSwitch(true); else reloadSwitch(false);
}
function onOrderSelect() {
	lookupPlaylist(getStartDate(),getEndDate(),getShowSelectorValue(),getOrder()); //playlistresults.js
	//does not affect status of counter
}
function onSelectLoaded() {
	//don't do these things b/c we don't want the playlist shown yet
	//document.getElementById("navbox").style.display='block';
	//lookupPlaylist(getStartDate(),getEndDate(),getShowSelectorValue(),getOrder()); //playlistresults.js
}

//initiate controls
function initPrograms() {
	initCalendarNavForAll(); //calendarnav.js
	initOrderSelectorForAll(); //orderselector.js
	initShowSelectorForPrograms(); //showselector.js
	//this needs to be the last thing that loads
	//when it's done populating, onSelectLoaded() is triggered,
	//which in turn loads the first batch of data.
	//reloadSwitch(true);
}

/*function reloadCount() {
	if(reloadSeconds>-1) { //if running
		reloadSeconds--;
		if(reloadSeconds==0) {
			lookupPlaylist(getStartDate(),getEndDate(),getShowSelectorValue(),getOrder()); //playlistresults.js
			reloadSeconds=30;
		}
		setTimeout('reloadCount()',1000);
		document.getElementById("reloaddiv").innerHTML = "Auto-refresh in "+reloadSeconds+" second"+(reloadSeconds==1 ? '' : 's');
	}
}
function reloadSwitch(val) {
	//turns reloading counter off or on (and resets to 30 if the latter)
	if(val) { reloadSeconds=31; reloadCount(); document.getElementById("reloaddiv").style.display="inline"; }
	else { reloadSeconds=-1; document.getElementById("reloaddiv").style.display="none"; }
}*/