/*
 * SP2 Routines
 *
 * Copyright (c) 2008 Fabrizio Fiandanese (creativepattern.com)
 *
 * $Date: 2009/03/13 10:51:35 $
 * $Rev: 110 $
 */
 
 /* show/hide div elements*/
function _showSubDiv(cssExp,idx)
{
	 $(cssExp).each(function(i){
		
			//Active class check
			if (idx==i)
			{			
				$(this).show();
			}
			else
			{
				$(this).hide();
			}
	});
}

function _showSubDivByClass(cssExp,className)
{
	
	 $(cssExp).each(function(i){
		
			//Active class check
			if ($(this).attr("class")==className)
			{			
				$(this).show();
			}
			else
			{
				$(this).hide();
			}
	});
}

function _showSubDivById(cssExp,id)
{

	 $(cssExp).each(function(i){
		
			//Active class check
			if ($(this).attr("id")==id)
			{			
				$(this).show();
			}
			else
			{
				$(this).hide();
			}
	});
}

/*custom routines */

function showContent(type)
{
	//hide all subcontents
	$('#sp_content div.item').hide();
	
	//turn off all links
	$('#sp_nav .subnav a').removeClass('active');
	
	//enable first link
	$($('#sp_nav .subnav .' + type + ' a').get(0)).addClass('active');
	
	showSubNav(type);
	
	//refresh stream nav if active display running
	
	if (type=='stream')
	{
		refreshStreamSubNav();
	}	
	
	showSubContent(type,0);	
}	

function showSubNav(type)
{
	_showSubDivByClass('#sp_nav .subnav div',type);	
}	

function showSubContent(type,idx)
{
	_showSubDiv('#sp_content .' + type + ' div.item',idx);
}

function showSubContentById(type,id)
{
	_showSubDivById('#sp_content .' + type + ' div.item',id);
}


function showTab(type)
{
	//turn off all links
	$('#sp_tabs a').removeClass('active');
	
	//enable tab	
	$('#sp_tabs a.' + type).addClass('active');
}	

function showFrontend(url)
{
	var t='';
	var a= url;
	var g='';
		
		tb_show(t,a,g);
}


function contentCall(state)
{

	dt= new Date();

	var tie = state.indexOf('?') == -1 ? '?' : '';
	
	//clear the iframe buffer
	
	$("#sp_async_content #async_buffer").empty();
	$("#sp_async_content #async_buffer").load(state + tie + '&' + dt.getTime());	
}

function contentNavCall(area,state)
{
	dt= new Date();

	var tie = state.indexOf('?') == -1 ? '?' : '';
	
	$("#" + area).load(state  + tie + '&' + dt.getTime());	
}

function streamMetadataCall(state)
{
	dt= new Date();

	var tie = state.indexOf('?') == -1 ? '?' : '';

	$("#sp_async_stream_metadata").load(state + tie + '&' + dt.getTime());
}


function enableVScroll(zone)
{
	
	//serial scrolls
	$('#' + zone + ' .items').serialScroll({
		items:'a',
		prev:'#' + zone + ' .up',
		next:'#' + zone + ' .down',
		stop:true,
		force:true,
		duration:0,
		axis:'y',
		step:3 
	});	


	//enable first link
	$($('#' + zone + ' .items a').get(0)).addClass('active');

	//enable automatic highlight
	var lnks=new TabMaster('#' + zone + ' .items a');	

}

function getEpoch()
{ 	
	dDate = new Date();
	return parseInt(Date.UTC(dDate.getUTCFullYear(),dDate.getUTCMonth(),dDate.getUTCDate(),dDate.getUTCHours(),dDate.getUTCMinutes(),dDate.getUTCSeconds(),dDate.getUTCMilliseconds())/1000) 
} 

function getCustomEpoch(hours,minutes)
{ 
	dDate = new Date();
	return parseInt(Date.UTC(dDate.getUTCFullYear(),dDate.getUTCMonth(),dDate.getUTCDate(),hours,minutes,0,0)/1000) 
}

function getToday(timezone_shift)
{ 
	dDate = new Date();
	tDate= new Date(dDate.getUTCFullYear(),dDate.getUTCMonth(),dDate.getUTCDate(),dDate.getUTCHours()+timezone_shift,dDate.getUTCMinutes(),dDate.getUTCSeconds());
	
	return tDate.getDay();
}
