$(document).ready(function(){	
	$('#info-switcher').cycle({fx: 'fade', pause: 1, next: "#info-switcher li" });
	
	var pairLeft = $('.equal-left').height();
	var pairRight = $('.equal-right').height();
	
	if(pairLeft > pairRight) 
		$('.equal-right .grey-box').height(pairLeft-16);
	else
		$('.equal-left .grey-box').height(pairRight-16);
		
	$("#menu li.parent>a").mouseover(function() {
		$("#menu li.current").removeClass("current");
		$(this).parent().addClass("current");
	});
	
	$("#pharse, #search-ogolne form .txt").focus(function() {
		$(this).val("");
	});
	$("#pharse, #search-ogolne form .txt").blur(function() {
		if($(this).val()=='')
			$(this).val("Wpisz szukaną frazę...");
	});
	
	var sign = 0;
	$("#file-desc").keypress( function() {
		sign = $(this).val().length;
		sign -= 1;
		if (sign>=0 && sign<1025)
			$("#sign-num em").html(1024-sign);
	});
	
	var sw_height =	$(".switcher-text").height();
	$(".switcher-bg").height(sw_height+20);
	
	$(".external").click(function() {
		window.open($(this).attr("href"));
		return false;
	});
	
	$(".submit, .submit2").hover(function() { $(this).addClass("hover-submit")}, function() { $(this).removeClass("hover-submit")} );
	
	$('#add-next').click(function(){
		var div_n = createElement("Plik:", "Format: avi, mpeg, 3gp do 100MB", "files[file][]");
		$(this).parent().parent().append(div_n);
		return false;
	});
	
	$('#add-next-photo').click(function(){
		var div_n = createElement("Zdjęcie:", "max. 800 pikseli, 200 kB", "files[file][]");
		$(this).parent().parent().append(div_n);
		return false;
	});
	
	$(".remove-div").click(function() {
		$(this).parent().remove();
		return false;
	});
	
	$(".tabs a").click(function() {
		var id= $(this).attr("rel");
		if (!id) { return; }
		var parent = $(this).parent().parent();
		$(parent).children("li").each(function(i){ 
			$(this).children("a.current").removeClass("current");
		});
		$(this).addClass("current");
		parent.parent().children(".content").children(".show").removeClass("show");
		//parent.parent().parent().children(".show").removeClass("show");
		$("#"+id).addClass("show");
		return false;
	});
	
	$(".main .tabs a").click(function() {
		var id= $(this).attr("rel");
		var parent = $(this).parent().parent();
		$(parent).children("li").each(function(i){ 
			$(this).children("a.current").removeClass("current");
		});
		$(this).addClass("current");
		//parent.parent().children(".content").children(".show").removeClass("show");
		parent.parent().parent().children(".show").removeClass("show");
		$("#"+id).addClass("show");
		return false;
	});
	
	/*$("#left-intro-new .slide a").click(function() {
		$("#left-intro-new .slide a.active").removeClass("active");
		$(this).addClass("active");
		return false;
  	});*/

  	$("#right-intro .mask li a").click(function() {
		$("#right-intro .mask li a.active").removeClass("active");
		$(this).addClass("active");
		return false;
  	});
	/*
	$(".infoslider .mask li a").click(function() {
		$(".infoslider .mask li a.active").removeClass("active");
		$(this).addClass("active");
		//return false;
  	});
	*/
  	
  	var showed=$("#content #main-bar .switcher .content").children("div.show");
	/*
	$(".tabs-fade a").click(function() {
		var id= $(this).attr("rel");
		var parent = $(this).parent().parent();
		$(parent).children("li").each(function(i){ 
			$(this).children("a.current").removeClass("current");
		});
		$(this).addClass("current");
		if(showed!=null) {
			$(showed).removeClass("show");
			$(showed).fadeTo("fast", 0);
		}
		
		$("#"+id).addClass("show"); 
		$("#"+id).fadeTo("slow", 1);
		showed =  $("#"+id);
		return false;
	});
	*/

    $('.scroll-pane').each(function(){
            var hide_after_scroll_add = false;                            
            if ($(this).parent().parent().parent().css('display') == 'none'){
                $(this).parent().parent().parent().addClass('show');
                hide_after_scroll_add = true;
            }
            $(this).jScrollPane({dragMinHeight: 30, dragMaxHeight: 30, animateInterval: 10, animateStep:1});
            if (hide_after_scroll_add){
               $(this).parent().parent().parent().parent().removeClass("show");
            }
        });

  	$("#e-wydanie-gallery").slide();
  	$("#nice-gallery").slide();
  	$("#simple-gallery").slide();
  	$("#naj-zdjecia").slide();
  	$("#wide-gallery").slide({ elementWidth: 120, lastElementWidth: 50, numberOfVisibleElements: 4 });
  	$("#wide-gallery2").slide({ elementWidth: 120, lastElementWidth: 50, numberOfVisibleElements: 4 });
  	$("#naj-video").slide();
  	$("#rel-videoblog").slide();
  	$("#rel-video").slide();
  	$(".gallery-art").slide({ lastElementWidth: 28, numberOfVisibleElements: 1 });
  	$("#first-info-slider").slide({ elementWidth: 124, lastElementWidth: 58, numberOfVisibleElements: 4 });
  	$("#third-info-slider").slide({ elementWidth: 124, lastElementWidth: 58, numberOfVisibleElements: 4 });
  	
  	$("#relacje-slider").slideVertical({ elementWidth: 105, lastElementWidth: 50, numberOfVisibleElements: 2 });
  	$("#photo-big-slider").slideVertical({ elementWidth: 77, lastElementWidth: 47, numberOfVisibleElements: 4 });
  	$("#left-slider1").slideVertical({ elementWidth: 95, lastElementWidth: 50, numberOfVisibleElements: 2 });
  	$("#left-slider2").slideVertical({ elementWidth: 95, lastElementWidth: 50, numberOfVisibleElements: 2 });
  	$("#left-slider3").slideVertical({ elementWidth: 95, lastElementWidth: 50, numberOfVisibleElements: 2 });
  	$("#eska-slide").slideVertical({ elementWidth: 52, lastElementWidth: 20, numberOfVisibleElements: 3 });
  	
  	$("#main-page-gallery").slideWhole({ numberOfVisibleElements: 3 });
  	$("#right-slider1").slideWhole({ elementWidth: 124, numberOfVisibleElements: 3 });
  	$("#right-slider2").slideWhole({ elementWidth: 124, numberOfVisibleElements: 3 });
  	$("#right-slider3").slideWhole({ elementWidth: 124, numberOfVisibleElements: 3 });
  	$("#eska-gallery").slideWhole({ elementWidth: 181, numberOfVisibleElements: 3 });
  	$("#program-gallery").slideWhole({ elementWidth: 190, numberOfVisibleElements: 3 });
  	
  	$(".red .list li:even").addClass("even");
  	$(".results dd:even").addClass("even");
  	
	$('#form1 :radio.star').rating({
  		callback: function(value, link){
  			$("div.last").removeClass("last");
    		$(".measure-mark em").html(value);
    		$("div.star_on:last").addClass("last");
 	 	}
	});
	
	var paging_length = $(".paging").children().length;
	if(paging_length > 25) paging_length = 25;
	$(".paging").width(paging_length*23);
	
	/*
	$('#main-left-flash').flashembed({
		src: '/media/static/se_tmp.swf',
		width: 366,
		height: 366,
		id: 'mainFlash',
		wmode: 'transparent'
	});
	*/
/*	
	$('#left-intro .mask li a').click(function() {
		changepicture($(this).attr("rel"));
		return false;
	}); 
*/	
/*
	$('#tn-news').click(function() {
		var rel = $("#news .main-mask a:first-child").attr("rel");
		changepicture(rel);
	});
	
	$('#tn-sport2').click(function() {
		var rel = $("#sport2 .main-mask a:first-child").attr("rel");
		changepicture(rel);
	});
	
	$('#tn-rozrywka').click(function() {
		var rel = $("#rozrywka1 .main-mask a:first-child").attr("rel");
		changepicture(rel);
	});
*/
	$('#left-intro-new ul.tabsx a').click(function() {
		var slide_array = ["#tn-news", "#tn-plotki", "#tn-wydarzenia", "#tn-sport", "#tn-porady"];
		for(i=0; i<slide_array.length; i++) {
			var rel = $(slide_array[i]).attr("rel");
			$('#' + rel).hide();
		}
		$("#" + $(this).attr('rel')).show();
	});




	var adHeight = $("#header .ads").height();
	if (adHeight<100) {
		$("#sky").css("top", 138);
	};
    $("#h1hp").hide()
    $("#se_logo").mouseover(function(){$("#h1hp").show(); });
    $("#se_logo").mouseout(function(){$("#h1hp").hide(); });
});

function createElement(label, text, name) {	
	return $.DIV({},
			$.LABEL({'for':'file'}, label),
			$.INPUT({'class':'txt', 'type':'file', 'id':'file', 'name':name}),
			$.P({}, text),
			$.A({'href':'#', 'class':'more remove-div'}, "Usuń")
	);
}

function changepicture(pictureID){	
	var flashMovie=getFlashMovieObject("mainFlash");
	flashMovie.SetVariable("pictureID", pictureID);
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else
  {
    return document.getElementById(movieName);
  }
}

