// JavaScript Document

$(document).ready(function(){
		// výběr žánru
		$('form.formSrch select').change(changeSelect);

		// vyscrollování kalendáře
		$('ul.calendar li.actual a').bind("mouseover", calExtend);

		// skrolování obsahu myší
		$('.scrollContent').draggable({
			cursor : 'move',
	    axis: 'x',
	    containment: [-1*(1768 - $('.scrollhole').width() -  $('.scrollContent').offset().left), 0, $('.scrollContent').offset().left, 0]
	  });

		// generování sekundární TH 
		$('.scrollhole').after('<div class="fixedTblMatr"><table class="fixedTitle"><tr><th class="topPoint">&nbsp;</th></tr></table></div>');
		$('div.scrollhole table tr th').each(function(index) {
	    $('table.fixedTitle').append('<tr><th>'+$(this).html()+'</th></tr>');
	  });

	  // zobrazení toolboxu s detailem
	  $('.scrollhole table td p strong a').bind("mouseenter", showTooltip);
	  $('.scrollhole table td p strong a').bind("mouseleave", hideTooltip);
	  
	  // zobrazení toolboxu na hvězdě
	  $('a.favoriteStar').bind("mouseenter", showTooltipStar);
	  $('a.favoriteStar').bind("mouseleave", hideTooltipStar);

		// generování vyšek DIVů programu
		var vyskaTabulky = ($('.scrollhole table tbody').children('tr').length)*60;
		$('.scrollhole').css({'height' : (vyskaTabulky+60)+'px'});
		$('.actualtime').css({'height' : (vyskaTabulky)+'px'});
		$('.scrollframe').css({'height' : (vyskaTabulky+40)+'px'});
});

		function changeSelect () {
			var targetSection = $(this).attr('value');
			if (targetSection == "all") {
				$('table.mainProgramTable').children('tbody').children('tr').children('td').show();
	  	} else {
				$('table.mainProgramTable').children('tbody').children('tr').children('td').hide();
				$('table.mainProgramTable').children('tbody').children('tr').children('td').children('div').children('p.'+targetSection).each(function(index) {
		    	$(this).parent('div').parent('td').show();
		  	});
			}
		
		}
		function showTooltip() {
			//$('div.tooltip div.content').append($('div#'+$(this).parent('strong').parent('p').parent('td').attr('class')).html());
			$('div.tooltip div.content').append($('div#'+$(this).attr('class')).html());
			$('div.tooltip').show();

			var myWidth = 0;
	    if( typeof( window.innerWidth ) == 'number' ) {
	      //Non-IE
	      myWidth = window.innerWidth;
	    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	      //IE 6+ in 'standards compliant mode'
	      myWidth = document.documentElement.clientWidth;
	    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	      //IE 4 compatible
	      myWidth = document.body.clientWidth;
	    }
	    	var vyskaTooltipu = $('.tooltip .content').height();
	    	//alert(vyskaTooltipu);
				var leveOdsazeni = (myWidth-960)/2;
				$(document).mousemove(function(e){
	      	$('div.tooltip').css({'top' : (e.pageY-(vyskaTooltipu+38))+'px', 'left' : (e.pageX-23)+'px'});
	   		});
		}
		function hideTooltip() {
			$('div.tooltip').hide();
			$('div.tooltip div.content').empty();
		}
		
		function showTooltipStar() {
			if (window.location.href.search("/cz/") != -1) {
				if (this.attr('class')=='favoriteStar off') {
					var text = 'Přidat film do Mého programu';
				} else {
					var text = 'Odebrat film z Mého programu';
				}
			} else {
				if ($(this).attr('class')=='favoriteStar off') {
					var text = 'Add film to My Program';
				} else {
					var text = 'Remove film from My Program';
				}
			}
			$('div.tooltip div.content').append(text);
			$('div.tooltip').show();

			var myWidth = 0;
	    if( typeof( window.innerWidth ) == 'number' ) {
	      //Non-IE
	      myWidth = window.innerWidth;
	    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	      //IE 6+ in 'standards compliant mode'
	      myWidth = document.documentElement.clientWidth;
	    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	      //IE 4 compatible
	      myWidth = document.body.clientWidth;
	    }
	    	var vyskaTooltipu = $('.tooltip .content').height();
	    	//alert(vyskaTooltipu);
				var leveOdsazeni = (myWidth-960)/2;
				$(document).mousemove(function(e){
	      	$('div.tooltip').css({'top' : (e.pageY-(vyskaTooltipu+38))+'px', 'left' : (e.pageX-23)+'px'});   
	   		});
		}
		function hideTooltipStar() {
			$('div.tooltip').hide();
			$('div.tooltip div.content').empty();
		}
		
		function calExtend() {
			$('ul.calendar').stop();
			$('ul.calendar li.actual').addClass('hospot');
			$('ul.calendar').animate({'width' : '940px'}, 'fast', pakak);
			function pakak() {
				$('ul.calendar').bind("mouseleave", calDextend);
			}
			return false;
		}
		function calDextend() {
			$('ul.calendar').stop();
			$('ul.calendar').animate({'width' : '220px'}, 'fast', pakukaz);
			function pakukaz() {
				$('ul.calendar li.actual').removeClass('hospot');
				$('ul.calendar li.actual a').unbind("click").bind("click", calExtend);
			}
			return false;
		}
