// bubble
var bubbleTout=null;
var bubcache=new Array();

$(document).ready(function() {
	
		$('.fadehover').css({opacity: 0.8});
		$('.fadehover').hover(
		function () {
			$(this).dequeue().animate({opacity: 1},100);

		},  
		function () {
			$(this).dequeue().animate({opacity: 0.8},100);
		}
		);		

		$('.hidehover .hidehover_this').css({opacity: 0});
		$('.hidehover').hover(
		function () {
			$('.hidehover_this',this).dequeue().animate({opacity: 1},100);

		},  
		function () {
			$('.hidehover_this',this).dequeue().animate({opacity: 0},100);
		}
		);		
	

	$('#nav li.l0').hover(
		function () {
			$('a.l0',this).addClass('navhover');
			$('a.l0',this).css({'background':'#ffffff','color':'#000000'});
			var t=$('> ul',this);
 			t.slideDown(100);

		},  
		function () {
			$('a.l0',this).removeClass('navhover');
			$('a.l0',this).css({'background':'#000000','color':'#ffffff'});
			$('> ul', this).slideUp(50);			
		}
	);
	
	$('#nav li.l1').hover(
		function () {
			var t=$('ul',this);
 			t.slideDown(100);

		},  
		function () {
			$('ul', this).slideUp(50);			
		}
	);
	
	
	// score selector
	$('.scoreselect').click(function() {
		if (loggedin) {
			$(this).children().fadeOut(200);
			programid=$(this).attr('rel');
			filmid=$(this).attr('id'); filmid=filmid.replace('f','');
			var place=$(this);
			
			$.get(
			"ajax_scoreselect.php",
			"programid="+programid+"&filmid="+filmid,
			function(data) { 
				loguj(data);
				place.html(data);
				},
			"html"
			);	
			return false;
		} else {
			show_calhelp();
		}
	});
	 
	// kalendarz help

	// dla niezalogowanych guzik
	$('.showcalhelp').css('opacity',0.5);
	$('.showcalhelp').click(function() {
		show_calhelp();
		return false;
	});
	
	function show_calhelp() {
		$('.calhelp_screen').show();
		fh=$('.calhelp_screen .txtframe').outerHeight();
		fw=$('.calhelp_screen .txtframe').outerWidth();
		wh=$(window).height();
		ww=$(document).width();
		$('.calhelp_screen .txtframe').css('top',$(window).scrollTop()+wh/2-fh/2);
		$('.calhelp_screen .txtframe').css('left',ww/2-fw/2).fadeIn(800);
		
		$('.calhelp_screen .bg').css('opacity',0.8).width(ww).height(wh).show();
	}

	$('.calhelp').click(function() {
		show_calhelp();

		return false;
	});
	
	$('.calhelp_screen .bg').click(function() {
		$('.calhelp_screen').hide();
	});


	vtip(); // vtip init
	
	



	$('.filmdata').hover(function() {
			var t=$(this);

			
			bubbleTout=window.setTimeout(function() {
				filmid=t.attr('rel');
				of=t.offset();
				ofmod=t.outerHeight()+12;
				$('#bub').stop().remove();
				$('body').append('<div id="bub" style="display: none;"><'+'/div>');
				$('#bub').html($('.filmbubble-'+filmid).html());
				
				leftpos=of.left;
				$('#bub .arr').css({'backgroundPosition':'left'});
				$('#bub').css({'position':'absolute','top':of.top+ofmod,'left':leftpos});
				$('#bub').stop().fadeIn(120);
				
				if (bubcache[filmid]) { 
					$('#bub .ajax').html(bubcache[filmid]);
					loguj('ca');
				} else {
						$.ajax({ 
						  url: 'ajax_getbubble.php?id='+filmid,
					  success: function(data) {
							$('#bub .ajax').html(data);
							bubcache[filmid]=data;
						  }
						});
						
//  					$.get(
//  					"ajax_getbubble.php",
//  					"id="+filmid,
//  					function(data) { 
//  						$('#bub .ajax').html(data);
//  						bubcache[filmid]=data;
//  					},
//  					"html"
//  					);	
				}
				
			}, 300);
			
	},function() {
		clearTimeout(bubbleTout);
		$('#bub').stop().fadeOut(100, function() {
			$('#bub').remove();
		});
	});


});	

function update_trans() {
	if ($.browser.msie) {
		$('.trans1').addClass('ietrans1').removeClass('trans1');
		$('.trans2').addClass('ietrans2').removeClass('trans2');
		$('.trans3').addClass('ietrans3').removeClass('trans3');
		$('.trans4').addClass('ietrans4').removeClass('trans4');
	} 
}


function loguj(co) {
return false;
// 	try
// 	  {
// 	 console.log(co);
// 	  }
// 	catch(err)
// 	  {
// 		return false;
// 	}
}

this.vtip = function() {    
    this.xOffset = 0; // x distance from mouse
    this.yOffset = 10; // y distance from mouse       
    
    $(".vtip").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            
            $('body').append( '<p id="vtip">' + $(this).next().html() + '</p>' );
            
           
            var w=$('p#vtip').outerWidth();
            $('p#vtip').hide();
            $('p#vtip').css("top", this.top).css("left", (this.left-w/2)).fadeIn(200);
            
			of=$('p#vtip').offset();
			if (of) {
				if (of.left<10) $('p#vtip').css("left",10);
			}            
        },
        function() {
            this.title = this.t;
            $("p#vtip").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
            var w=$('p#vtip').outerWidth();
                         
            $("p#vtip").css("top", this.top+"px").css("left", (this.left-w/2)+"px");
            
			of=$('p#vtip').offset();
			if (of) {
				if (of.left<10) $('p#vtip').css("left",10);
			}
        }
    );            
    
};


