var selected = "";
var sub_selected = "";
var subcategories = "";
var selected_page = "page_1"
var selected_pager_container = 1;

function changePageCSS(active){
	if (active != selected_page){
		if(selected_page != "")
			document.getElementById(selected_page).style.color = "#CC0000";
		document.getElementById(active).style.color = "#FFFFFF";
		selected_page = active;
	}
}

function changePagerContainer(type){
	if(type=="+" && document.getElementById("pager_container_"+selected_pager_container)){
		document.getElementById("prev_pager_container").style.display = "block";
		document.getElementById("pager_container_"+selected_pager_container).style.display = "none";
		selected_pager_container++;
		document.getElementById("pager_container_"+selected_pager_container).style.display = "block";
		var have_container = selected_pager_container+1;
		if(!document.getElementById("pager_container_"+have_container)){
			document.getElementById("next_pager_container").style.display = "none";
		}
	}else{
		document.getElementById("next_pager_container").style.display = "block";
		document.getElementById("pager_container_"+selected_pager_container).style.display = "none";
		selected_pager_container--;
		document.getElementById("pager_container_"+selected_pager_container).style.display = "block";
		var have_container = selected_pager_container-1;
		if(!document.getElementById("pager_container_"+have_container)){
			document.getElementById("prev_pager_container").style.display = "none";
		}
	}	
}

function changeCategoryCSS(active){
	if (active != selected){
		
		if(selected != "" && document.getElementById(selected) != null)
			document.getElementById(selected).className = "category";
		
		document.getElementById(active).className = "category_selected";
		selected = active;
	}
}
function changeSubCategoryCSS(active){
	if (active != sub_selected){
		if(sub_selected != "")
			document.getElementById(sub_selected).className = "subcategory";
		document.getElementById(active).className = "subcategory_selected";
		sub_selected = active;
	}
}
function checkActiveCategory(){
	if(document.getElementById(selected))
		document.getElementById(selected).className = "category_selected";
	if(document.getElementById(sub_selected))
		document.getElementById(sub_selected).className = "subcategory_selected";
}
function tell(url){
	new Ajax.Updater('contents', url, {method:'get',asynchronous:true, evalScripts:true, onComplete:function(request, json){frontend_hide('category_loader');videolist_show('categories')}, onLoading:function(request, json){videolist_hide('categories'); frontend_show('category_loader')}});
}
function openCategory(content_url, active, subcategory){
	new Ajax.Updater('contents', content_url, {script:true, asynchronous:true, evalScripts:true, onComplete:function(request, json){frontend_hide('category_loader');videolist_show('categories')}, onLoading:function(request, json){videolist_hide('categories'); frontend_show('category_loader')}});
	if(!subcategory)
		changeCategoryCSS(active);
	else
		changeSubCategoryCSS(active);
	return false;
}
function register(url){
	if(document.getElementById(selected)){
		document.getElementById(selected).className = "category";
		selected = "";
	}
	if(document.getElementById(sub_selected)){
		document.getElementById(sub_selected).className = "subcategory";
		sub_selected = "";
	}
	new Ajax.Updater('contents', url, {method:'get',asynchronous:true, evalScripts:true, onComplete:function(request, json){frontend_hide('category_loader');videolist_show('categories')}, onLoading:function(request, json){videolist_hide('categories'); frontend_show('category_loader')}});
	return false;
}
function openOnaAir(onair_url, schema_url){
	new Ajax.Updater('contents', content_url, {asynchronous:true, evalScripts:true, onComplete:function(request, json){frontend_hide('category_loader');videolist_show('categories')}, onLoading:function(request, json){videolist_hide('categories'); frontend_show('category_loader')}});
	changeCategoryCSS('on_air');
	return false;
}
function openContent(content_url, details_url){
	new Ajax.Updater('details_container', details_url, {asynchronous:true, evalScripts:true});
	new Ajax.Updater('video', content_url, {asynchronous:true, evalScripts:true, onComplete:function(request, json){frontend_hide('category_loader');}, onLoading:function(request, json){frontend_show('category_loader')}});
	
	return false;
}
function uploadVideo(url){
	new Ajax.Updater('contents', url, {asynchronous:true, evalScripts:true, onComplete:function(request, json){frontend_hide('category_loader');videolist_show('categories')}, onLoading:function(request, json){videolist_hide('categories'); frontend_show('category_loader')}});
}
function frontend_hide(id)
{
	document.getElementById(id).style.display = "none";
}
function frontend_show(id)
{	
	//document.getElementById(id).style.display = "block";
}
function videolist_hide(id){
	if(id == 'categories' || id == 'contents')
		return;
		
	document.getElementById(id).style.display = "none";
}
function videolist_show(id){
	if(id == 'categories')
		return;
		
	document.getElementById(id).style.display = "block";
}
function startclock()
	{
		var thetime=new Date();
		
		var nhours=thetime.getHours();
		var nmins=thetime.getMinutes();
		var nsecn=thetime.getSeconds();
		var nday=thetime.getDay();
		var nmonth=thetime.getMonth();
		var ntoday=thetime.getDate();
		var nyear=thetime.getYear();
		var AorP=" ";
		
		if (nhours>=12)
		    AorP="P.M.";
		else
		    AorP="A.M.";
		
		if (nsecn<10)
		 nsecn="0"+nsecn;
		
		if (nmins<10)
		 nmins="0"+nmins;
		
		if (nday==0)
		  nday="Sunday";
		if (nday==1)
		  nday="Monday";
		if (nday==2)
		  nday="Tuesday";
		if (nday==3)
		  nday="Wednesday";
		if (nday==4)
		  nday="Thursday";
		if (nday==5)
		  nday="Friday";
		if (nday==6)
		  nday="Saturday";
		
		nmonth+=1;
		
		if (nyear<=99)
		  nyear= "19"+nyear;
		
		if ((nyear>99) && (nyear<2000))
		 nyear+=1900;
		
		document.getElementById("clock_time").innerHTML = nhours+":"+nmins+":"+nsecn;
		
		setTimeout('startclock()',1000);
	
	} 
	function hideRegister(){
		if(document.getElementById('register_button_text'))
			document.getElementById('register_button_text').style.display = 'none';
	}

	function playRadio()
	{
		new Ajax.Updater('video', '/radio/show', {asynchronous:true, evalScripts:true});
		new Ajax.Updater('details_container', '/radio/details', {asynchronous:true, evalScripts:true});
	}