var browser = navigator.userAgent.toLowerCase();
var touch_browser = (browser.indexOf('android')!=-1 || browser.indexOf('iphone')!=-1 || browser.indexOf('ipad')!=-1) ? true : false ;
var ipad_browser = (browser.indexOf('ipad')!=-1) ? true : false ;
var iphone_browser = (browser.indexOf('iphone')!=-1) ? true : false ;

// does site url have a trailing slash?
if(site_url!="undefined" && site_url.substr(-1)!="/"){
	site_url = site_url+"/";
}

$(document).ready(function(){
						   
	$('.slideshow li a').hover(function(){
		$('.slideshow .images').stop();							
		$('.slideshow li').removeClass('selected');
		$(this).parent().addClass('selected');
		id = $(this).parent().attr('id');
		no = id.replace('image','');
		$('.slideshow .images').animate({left:-no*620},1000);
		
		//height = $('p',this).height() + $('h2',this).height();
		
		//$(this).animate({marginTop:"-=26px"});
		
		
	},function(){
		
	});	
	
	load_list(site_url+'schedule/sidebar');
	
	$('#watch').click(function(){
		watch_tvs()
		return false;
	});
	
	$('#watch_footer,#menu li.view a').click(function(){
		watch_tvs()
		return false;
	})
	
	$('#tv .close').click(function(){
		close_tvs();
	})	

	
});

var offset = 0;
var height = 0;

function schedule_nav(scroll_to,h)
{
	
	height = h; // $('#sidebar-schedule .list-offset').height();
		
	// alert(scroll_to);
	$('#sidebar-schedule .down').click(function(){
		schedule_list('down');
		return false;
	});
	$('#sidebar-schedule .up').click(function(){
		schedule_list('up');
		return false;
	});
	
	offset = -scroll_to;
	if(scroll_to+264>height) offset = -height + 264;
	$('#sidebar-schedule .list-offset').animate({marginTop:offset});
}

function schedule_list(direction)
{
	
	if(direction=='down')
	{
		offset -= 264;
		if(Math.abs(offset)+264>height) offset -= height - (Math.abs(offset) + 264);
	}
	else
	{
		offset += 264;
	}
	
	if(offset>0) offset = 0;
	
	$('#sidebar-schedule .list-offset').animate({marginTop:offset});
	
	return false;
}

var _w = null;

function open_win(path,width,height,win)
{
	var w = window.screen.availWidth;
	var h = window.screen.availHeight;	
	
	var posL = (w-width)*.5;
	var posT = (h-height)*.5;
	
	if(_w && _w.open){
		_w.close();
	}	
	
	_w = window.open(path,win,'width='+width+',height='+height+',top='+posT+',left='+posL+',menubar=0,location=0,toolbar=0,personalbar=0,status=0,scrollbars=1,allowresize=1,dependent=1,resizable=1');	
}

function watch_tvs()
{
	open_win(site_url+'watch',392,339,'watch');	
	/*$('#tv').show('slow',function(){
		$('#tv .stream').load(site_url+'assets/template/object.html');
	});*/
}

function close_tvs()
{
	$('#tv .stream').html('');
	$('#tv').hide('slow');
}

function switch_list()
{
	$('.whats-on-switch').click(function(){
		$('#whats-on').hide('slow',function(){
			url = $('.whats-on-switch').attr('href');
			load_list(url);											
		})
		//$('#sidebar-schedule').hide('slow').load(site_url+'schedule/tomorrow');
		return false;
	})		
}

function load_list(url)
{
	$('#whats-on').load(url,function(){
		$(this).show('slow');
		switch_list();
	});		
}
