$(document).ready(function(){
	
	if(jQuery.browser.msie)
	{

		if( parseInt(jQuery.browser.version) >= 8 )
		$('.srodek').css('height',$(document).height()-20);
	}
	var linki = new Array();
	var podlinki = new Array();
	var kt=0;
	var nowiny = new Array();
	
	$(".pod_menu ul").each(function(i,el){
		podlinki[i] = el;
		if(i == kt)
		{
			$(this).css('visibility','visible');
			
		}
	});
	$(".menu li").each(function(i,el)
	{
		linki[i] = el;
		if(i == kt)
		{
			$(this).children('a').addClass('selected');
			$(this).children('a').css('padding',"8px 9px 12px 9px");
		}
		$(this).attr('id',i);
	});
	var timer;
	$(".menu li").bind('mouseenter',function(){
		$(".menu li").children('a').removeClass('selected');
		$(".menu li").children('a').css('padding',"10px");
		$(this).children('a').addClass('selected');
		$(this).children('a').css('padding',"8px 9px 12px 9px");
		$(".pod_menu ul").css('visibility','hidden');
		$(podlinki[$(this).attr('id')]).css('visibility','visible');
	});
	$(".menu_holder").bind('mouseenter',function(){
		if(timer) {
    	    clearTimeout(timer);
	    }
	});
	$(".menu_holder").bind('mouseleave',function(){
		timer = setTimeout(function() {
		$(".menu li").children('a').removeClass('selected');
		$(".menu li").children('a').css('padding',"10px");
		$("a[rel='current']").parent().children('a').addClass('selected');
		$("a[rel='current']").parent().children('a').css('padding',"8px 9px 12px 9px");
		$(".pod_menu ul").css('visibility','hidden');
		$(podlinki[$("a[rel='current']").parent().attr('id')]).css('visibility','visible');
		}, 300);
	});
	
	$(".menu li").children('a').removeClass('selected');
	$(".menu li").children('a').css('padding',"10px");
	$("a[rel='current']").parent().children('a').addClass('selected');
	$("a[rel='current']").parent().children('a').css('padding',"8px 9px 12px 9px");

	$(".pod_menu ul").css('visibility','hidden');
	$(podlinki[$("a[rel='current']").parent().attr('id')]).css('visibility','visible');	
	
	$(".nowiny_body").each(function(i,el){
		nowiny[i] = $(this);
	});
	
	$(".nowiny_belka ul li").each(function(i,el)
	{
		$(this).attr('id',i);
	});
	
	
	$(".nowiny_belka ul li").bind('click',function()
	{
		if(!$(this).parent().hasClass("movie_nav"))
		{
		$(".nowiny_belka ul li").removeClass('zaz');
		$(this).addClass('zaz');
		$(".nowiny_body").removeClass('widoczne');
		$(nowiny[$(this).attr('id')]).addClass('widoczne');
		}
	});
	
	
	/*
	$("#pic_nav").children('li').bind('click',function(){
		if(!$(this).hasClass("last"))
		{
			var addr = $(this).attr('title');
			var img = "<img src=\"" + addr +"\" alt=\"\" style=\"display:none\" />";
			var w = $(".bg").append(img);
			$(".bg").children('img').last().fadeIn();

		}
	});
	*/
	$('.bg').cycle({ 
    fx:'fade', 
    speed:1000,
	timeout:3000,
	pager: '#pic_nav', 
    pagerAnchorBuilder: function(idx, slide) { 
        return '#pic_nav li:eq(' + idx + ')'; 
    } 
	});
	
	$("a[rel='box']").colorbox();
	
	
	
	$('.img_gl').cycle({ 
    fx:'fade', 
    speed:1000,
	timeout:0,
	pager: '#pic_nav', 
    pagerAnchorBuilder: function(idx, slide) { 
        return '.panner a:eq(' + idx + ')'; 
    } 
	});
	
	$()
	
	$('.img_navi span').first().css('color','#ffffff');
	$('.img_navi span').each(function(i,el){
		$(this).bind('click',function(){
			$('.img_navi span').css('color','#465fc8');
			$(this).css('color','#ffffff');
			$(".panner").animate({left:-i*160},500);
		});
	});
	
	
	$('#sekcja').bind('change',function(){
		//alert($(this).parent("form").attr("action"));
		window.location = $(this).parent("form").attr("action")+""+$('#sekcja').attr('value')+"/";
		//window.location = $(location).attr('href')+$(this).attr('value')+"/";
	});
	$('#sekcja_en').bind('change',function(){
		//window.location = "http://www.wff.pl/en/program/sekcje/0/"+$('#sekcja_en').attr('value')+"/";
		window.location = $(this).parent("form").attr("action")+""+$('#sekcja_en').attr('value')+"/";
	});
	$('#data').bind('change',function(){
		//window.location = "http://www.wff.pl/program/wyszukaj/"+$('#data').attr('value')+"/"+$('#miejsce').attr('value')+"/";
		window.location = $(this).parent("form").attr("action")+""+$('#data').attr('value')+"/"+$('#miejsce').attr('value')+"/";
	});
	$('#miejsce').bind('change',function(){
		//window.location = "http://www.wff.pl/program/wyszukaj/"+$('#data').attr('value')+"/"+$('#miejsce').attr('value')+"/";
		window.location = $(this).parent("form").attr("action")+""+$('#data').attr('value')+"/"+$('#miejsce').attr('value')+"/";
	});
	$('#data_en').bind('change',function(){
		window.location = $(this).parent("form").attr("action")+""+$('#data_en').attr('value')+"/"+$('#miejsce_en').attr('value')+"/";
		//window.location = "http://www.wff.pl/en/program/wyszukaj/"+$('#data_en').attr('value')+"/"+$('#miejsce_en').attr('value')+"/";
	});
	$('#miejsce_en').bind('change',function(){
		window.location = $(this).parent("form").attr("action")+""+$('#data_en').attr('value')+"/"+$('#miejsce_en').attr('value')+"/";
		//window.location = "http://www.wff.pl/en/program/wyszukaj/"+$('#data_en').attr('value')+"/"+$('#miejsce_en').attr('value')+"/";
	});
	
	function wyczysc_1()
	{
		$('#c1').attr('value',0);
		$('#c2').attr('value',0);
		$('#c3').attr('value',0);
	}
	function wyczysc_2()
	{
		$('#c4').attr('value',0);
	}
	
	$('#c1').bind('change',function(){ wyczysc_2(); $('#kryteria').submit(); });
	$('#c2').bind('change',function(){ wyczysc_2(); $('#kryteria').submit(); });
	$('#c3').bind('change',function(){ wyczysc_2(); $('#kryteria').submit(); });
	$('#c4').bind('change',function(){ wyczysc_1(); $('#kryteria').submit(); });
	
	/*
	$('.nowina').bind('mouseenter',function(){
		$(this).children('ul').first().stop(true);
		$(this).children('ul').first().slideDown(200);
	});
	$('.nowina').bind('mouseleave',function(){
		$(this).children('ul').first().stop(true);
		$(this).children('ul').first().slideUp(200);
	});
	*/
	/*
	$("div [title*='usera']").each(function(){
		$(this).children('ul').first().attr('title',$(this).children('ul').first().height());
		$(this).children('ul').first().css('display','block');
		$(this).children('ul').first().height(0);
		$(this).children('ul').first().css({'padding-top':'0px','padding-bottom':'0px'});
		$(this).children('ul').first().css('opacity',0);
	})
	$("div [title*='usera']").mouseover(function(event) {
       $(this).children('ul').first().stop().animate({ height: $(this).children('ul').first().attr('title'),opacity:1,'padding-top':10, 'padding-bottom':5 },200);
	});
	$("div [title*='usera']").mouseout(function() {
       $(this).children('ul').first().stop().animate({ height: 0,opacity:0,'padding-top':0, 'padding-bottom':0 },200);
	});
	*/
	$(".userowa").each(function(){
		$(this).children('ul').first().attr('title',$(this).children('ul').first().height());
		$(this).children('ul').first().css('display','block');
		$(this).children('ul').first().height(0);
		$(this).children('ul').first().css({'padding-top':'0px','padding-bottom':'0px'});
		$(this).children('ul').first().css('opacity',0);
	})
	$(".userowa").mouseover(function(event) {
       $(this).children('ul').first().stop().animate({ height: $(this).children('ul').first().attr('title'),opacity:1,'padding-top':10, 'padding-bottom':5 },200);
	});
	$(".userowa").mouseout(function() {
       $(this).children('ul').first().stop().animate({ height: 0,opacity:0,'padding-top':0, 'padding-bottom':0 },200);
	});
	
	$(".plus").bind('click',function(){
		id = $(this).attr('title');
		
		$.ajax({
		   type: "POST",
		   url: "./wff_admin/php/upTick.php",
		   data: "id="+id+"&act=inc",
		   success: function(msg)
		   {
			   var d = parseInt($(".tick_"+id).attr('value'));
			   $(".tick_"+id).attr('value',d+1);
		   }
		});
	});
	$(".minus").bind('click',function(){
		id = $(this).attr('title');
		if($(".tick_"+id).attr('value') > 1)
		$.ajax({
		   type: "POST",
		   url: "./wff_admin/php/upTick.php",
		   data: "id="+id+"&act=dec",
		   success: function(msg)
		   {
			    var d = parseInt($(".tick_"+id).attr('value'));
			   $(".tick_"+id).attr('value',d-1);
		   }
		});
	});

	
});
