var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;
var pos 			= null;
var liw				= null;

function redirectHome()
{
	window.location = sURL;
}

function redirect(postFix)
{
	window.location = sURL+postFix;
}

function jsddm_open()
{	
	jsddm_canceltimer();
	jsddm_close();
	
	var submenu = $(this).find('ul').eq(0);
	var t = $(submenu).width() - liw;
	
	if (t < 0 )
	{
		t = t * -1;
	}

	//newleft = pos.left;
	//var newleft = pos.left - Math.round(t / 2); 
	
	//$(submenu).css('left', newleft);
	$(submenu).css('top',  pos.top+31);
	ddmenuitem = $(submenu).css('visibility', 'visible');
}

function jsddm_close()
{	
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer()
{	
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{	
	if(closetimer)
	{	
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

document.onclick = jsddm_close;

$(document).ready(function(){
	var aBBlocks = new Array();
	var iIterator= 0;
	$('.partbans_item').each(function() { 
		aBBlocks.push($(this).attr('id'));
	});
	
	if (aBBlocks.length > 0)
	{
		$('#' + aBBlocks[0]).show();
	}
	
	window.setInterval(yourfunction, 3000);

	function yourfunction() 
	{ 
		$('#' + aBBlocks[iIterator]).hide();
		if ((iIterator + 1) < aBBlocks.length)
		{
			$('#' + aBBlocks[iIterator]).hide();
			iIterator = iIterator + 1;
			$('#' + aBBlocks[iIterator]).show();
		}else
		{
			$('#' + aBBlocks[iIterator]).hide();
			iIterator = 0;
			$('#' + aBBlocks[iIterator]).show();
		}
	}
	
	$('#jsddm > li').bind('mouseover',function(){
		pos = $(this).offset();
		liw = $(this).width();
		//alert(pos.x);
	});
	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);

	$('#tvcalendar').jCal({
		
		day:			new Date(),
		days:			1,
		showMonths:		1,
		monthSelect:	true,
		sDate:			new Date(),
		/*
		dCheck:			function (day) {
		  return ((day.getDay() != 6) && (day.getDay() != 0));
		},*/

		callback:	function (day, days) { //ze bolo kliknute
		    if (day!=new Date('<?php echo $this->OverClass->_month.'/'.$this->OverClass->_day.'/'.$this->OverClass->_year; ?>')){
			     window.location = sURL+"tvprogram/table/"+day.getDate()+"-"+( day.getMonth() + 1 )+"-"+day.getFullYear();
		    }
		  return true;
		}
	});
	
	if (ProgramDate != null){
		var xdate = ProgramDate;
		//var xdate = new Date();
	}
    //alert('div[id*=d_' + (xdate.getMonth() + 1) + '_' + xdate.getDate() + '_' + xdate.getFullYear() + ']');
	var dF = $('#tvcalendar').find('div[id*=d_' + (xdate.getMonth() + 1) + '_' + xdate.getDate() + '_' + xdate.getFullYear() + ']');
	if ( dF.length > 0 ) {
		dF.stop().addClass('selectedDay');
	}
});
