<!-- 
$(document).ready(function()
{
	// Your code here	
	
	/** 
	 * calculates max left position
	 * @param object scrollable_object
	 * @return int 
	 */
	function getMaxLeft(obj)
	{
		var parent_width = parseInt(obj.parent().css('width'));
		if(isNaN(parent_width))
		{
			parent_width = 0;
		}
		
		var obj_width = parseInt(obj.css('width'));
		if(isNaN(obj_width))
		{
			obj_width = 0;
		}
		
		var max_left = obj_width - parent_width;
		return max_left;
	} // end of function getMaxLeft(obj)
	
	
	
	/** 
	 * positions scroller object for specifed hour
	 * @param int hour 
	 * @param object obj, scroller object 
	 * @return void()
	 */
	 function positionScrollerForHour(hour, obj)
	 {
	 	switch(hour)
		{
			case 3:
			case 4:
			case 5:
				// scroll to max left position
				obj.animate({"left": "-=" + max_left + "px"}, 200);
				break;
			
			
			case 6:
			case 7:
			case 8:
				// stay at the begining
				break;
			
			
			default:
				// position current hour close to begining
				var temp_hour = hour;
				if(temp_hour < 3)
				{
					temp_hour = 24 + temp_hour;
				}
				var pos = (temp_hour - 6) * 240;
				obj.animate({"left": "-" + pos + "px"}, 200);
				break;
		} // end of switch(hour)
	 } // end of function positionScrollerForHour(hour, obj)
	
	
	var channel_scroller = $('div.channel_scroller');
	
	
	//var parent_width 	= channel_scroller.parent().css('width');
	var max_left 		= getMaxLeft(channel_scroller);
	var common_step		= 718;
	
	
	// position scroller for current hour
	var date 			= new Date();
	var hour 			= date.getHours();
	
	if(window.i_day == window.i_def_day)
	{
		positionScrollerForHour(hour, channel_scroller);
	}
	
	
	// handle right arrow
	$('a.channel_right_big_1, a.channel_right_big_2').click(function()
	{
		// get current left
		var curr_left = Math.abs(parseInt(channel_scroller.css('left')));
		
		// calculate step
		var step  		= common_step;
		var temp_left 	= curr_left + common_step;
		if(temp_left > max_left)
		{
			step = common_step - (temp_left - max_left);
		}
		
		if(step == 0)
		{
			// scroll back to beginning - rewind
			channel_scroller.animate({"left": "0px"}, 200);
		}
		else
		{
			channel_scroller.animate({"left": "-=" + step + "px"}, 200);
		}
		
		$(this).blur();
		return false;
	});
	
	
	// handle left arrow
	$('a.channel_left_big_1, a.channel_left_big_2').click(function()
	{
		// get current left
		var curr_left = Math.abs(parseInt(channel_scroller.css('left')));
		
		if(isNaN(curr_left))
		{
			curr_left = 0;
		}
		
		if(curr_left == 0)
		{
			// just exit
			return false;
		}
		
		var scroller_width = Math.abs(parseInt(channel_scroller.css('width')));
		if(isNaN(scroller_width))
		{
			scroller_width = 0;
		}
		
		var parent_width = Math.abs(parseInt(channel_scroller.parent().css('width')));
		if(isNaN(parent_width))
		{
			parent_width = 0;
		}
		
		
		// calculate step
		var step  		= common_step;
		var temp_left 	= curr_left + common_step;
		
		if(temp_left > scroller_width)
		{
			step = temp_left - scroller_width;
		}
		
		
		if(curr_left < parent_width)
		{
			//scroll back to beginning - rewind
			channel_scroller.animate({"left": "0px"}, 200);
		}
		else
		{
			channel_scroller.animate({"left": "+=" + step + "px"}, 200);
		}
		
		$(this).blur();
		return false;
	});
	
	
	// handle currently_on_tv 
	if(window.i_day == window.i_def_day)
	{
		/*
		$('h2#currently_on_tv').css('cursor', 'pointer');
		
		$('h2#currently_on_tv').hover(
			function()
			{
				$(this).css('color', '#ff0000');
			}, 
				
			function()
			{
				$(this).css('color', '#484848');
			}
		);
		*/
		$('a#currently_on_tv').click(function()
		{
			// shuffle schedule before displaying it
			positionScrollerForHour(hour + 3, channel_scroller);
			positionScrollerForHour(hour, channel_scroller);
			
			$(this).blur();
			return false;
		});
	} // end of if(window.i_day == window.i_def_day)
	
	
	// manage preporucujemo
	var todays_recommendations = $('ul#todays_recommendations');
	
	// calculate width for todays_recommendations
	var todays_recommendations_width = (todays_recommendations.find('li.lista-clan').length * 162);
	todays_recommendations.css('width', todays_recommendations_width + 'px');
	
	var rec_parent_width 	= parseInt(todays_recommendations.parent().css('width'));
	if(isNaN(rec_parent_width))
	{
		rec_parent_width = 486;
	}
	
	var rec_max_left 		= todays_recommendations_width - rec_parent_width;
	var rec_common_step		= 486;
	
	// handle right_arrow_small
	$('a#right_arrow_small_1').click(function()
	{
		// check num of elements
		if(todays_recommendations.find('li.lista-clan').length < 4)
		{
			return false;
		}
		
		// get current left
		var curr_left = Math.abs(parseInt(todays_recommendations.css('left')));
		
		if(isNaN(curr_left))
		{
			curr_left = 0;
		}
		
		// calculate step
		var step  		= rec_common_step;
		var temp_left 	= curr_left + rec_common_step;
		if(temp_left > rec_max_left)
		{
			//step = temp_left - rec_max_left;
			step = rec_common_step - (temp_left - rec_max_left);
		}
		
		//if((curr_left + step) > rec_max_left)
		if(step == 0)
		{
			// scroll back to beginning - rewind
			todays_recommendations.animate({"left": "0px"}, 200);
		}
		else
		{
			todays_recommendations.animate({"left": "-=" + step + "px"}, 200);
		}
		
		$(this).blur();
		return false;
	});
	
	
	// handle left_arrow_small 
	$('a#left_arrow_small_1').click(function()
	{
		// get current left
		var curr_left = Math.abs(parseInt(todays_recommendations.css('left')));
		if(isNaN(curr_left))
		{
			curr_left = 0;
		}
		
		if(curr_left == 0)
		{
			// just exit
			return false;
		}
		
		// calculate step
		var step  		= rec_common_step;
		var temp_left 	= curr_left + rec_common_step;
		
		if(temp_left > todays_recommendations_width)
		{
			step = temp_left - todays_recommendations_width;
		}
		
		
		//if((todays_recommendations_width - (curr_left + step)) > rec_parent_width)
		if(curr_left < rec_parent_width)
		{
			// scroll back to beginning - rewind
			todays_recommendations.animate({"left": "0px"}, 200);
		}
		else
		{
			todays_recommendations.animate({"left": "+=" + step + "px"}, 200);
		}
		
		$(this).blur();
		return false;
	});
});
-->