$().ready(function()
{	
	$(".zaw-opis").hide();
	$(".hidden").hide();
	$(".zawodnik .toggle").addClass("rozwin");
	
	$("#tab-live a.pokaz").click(function() {
	  $("#tab-live .hidden").show();
	  $("#tab-live a.pokaz").hide();
	  return false;
	});
	
	$("#wideo a.schowaj").click(function() {
	  $("#wideo .hidden").hide();
	  $(this).hide();
	  $("#wideo a.pokaz").show();
	  return false;
	});
	
	$("#wideo a.pokaz").click(function() {
	  $("ul.hidden").show();
	  $("#wideo a.pokaz").hide();
	  $("#wideo a.schowaj").show();
	  return false;
	});
	
	$(".hidden a.schowaj").click(function() {
	  $(this).parent().hide();
	  $("#tab-live a.pokaz").show();
	  return false;
	});
	
	$(".program .group a.rozwin").click(function() {
		var index = $(".program .group a.rozwin").index(this);
		$(".program .kanaly").eq(index).show();
		$(".program .rozwin").eq(index).hide();
		$(".program .zwin").eq(index).show();
		return false;
	});
	
	$(".program .group a.zwin").click(function() {
		var index = $(".program .group a.zwin").index(this);
		$(".program .kanaly").eq(index).hide();
		$(".program .rozwin").eq(index).show();
		$(".program .zwin").eq(index).hide();
		return false;
	});
	
	$("#ogladaj .header a.next").click(function() {
		var index2 = $("#ogladaj div.program").index($("#ogladaj div.program.active"));
		
		if ($("#ogladaj div.program").size() > (index2 + 1) ) {
			$("#ogladaj div.program.active").hide();
			$("#ogladaj div.program.active").addClass("hidden");
			$("#ogladaj div.program.active").removeClass("active");
			$("#ogladaj div.program").eq(index2 + 1).addClass("active");
			$("#ogladaj div.program.active").removeClass("hidden");
			$("#ogladaj div.program.active").show();
			
			$("#ogladaj .header span.godz.active").hide();
			$("#ogladaj .header span.godz.active").addClass("hidden");
			$("#ogladaj .header span.godz.active").removeClass("active");
			$("#ogladaj .header span.godz").eq(index2 + 1).addClass("active");
			$("#ogladaj .header span.godz.active").removeClass("hidden");
			$("#ogladaj .header span.godz.active").show();
		}
		
		return false;
	});
	
	$("#ogladaj .header a.prev").click(function() {
		var index2 = $("#ogladaj div.program").index($("#ogladaj div.program.active"));
		
		if ((index2) > 0) {
			$("#ogladaj div.program.active").hide();
			$("#ogladaj div.program.active").addClass("hidden");
			$("#ogladaj div.program.active").removeClass("active");
			$("#ogladaj div.program").eq(index2 - 1).addClass("active");
			$("#ogladaj div.program.active").removeClass("hidden");
			$("#ogladaj div.program.active").show();
			
			$("#ogladaj .header span.godz.active").hide();
			$("#ogladaj .header span.godz.active").addClass("hidden");
			$("#ogladaj .header span.godz.active").removeClass("active");
			$("#ogladaj .header span.godz").eq(index2 - 1).addClass("active");
			$("#ogladaj .header span.godz.active").removeClass("hidden");
			$("#ogladaj .header span.godz.active").show();
		}
		
		return false;
	});
	
	$(".taby .taby-nav a").click(function()
	{
		$(this).blur();
			
		var id=$(this).parent().parent().parent().attr("id");
			
		$("#"+id +" .taby-nav li.active").removeClass("active");
		$(this).parent().addClass("active");

		var element_index = $("#"+id +" .taby-nav a").index(this);

		$("#"+id +" .taby-tresc:visible").hide();
		$("#"+id +" .taby-tresc").eq(element_index).show();
		
		var x = $("#"+id +" .taby-tresc").eq(element_index).children().attr("id");
		
		if (id == "taktyka") {animuj_boisko(x);}
		
		return false;
	});
	
	$(".zawodnik .toggle").click(function()
	{
		$(this).blur();
		var id2=$(this).parent().parent().attr("id");
		var id3=$(this).parent().parent().parent().attr("id");
		
		if ($(this).hasClass("rozwin")) {
			$("#"+id3 +" .zaw-opis").hide();
			$("#"+id3 +" a.toggle").addClass("rozwin");
			$("#"+id3 +" .zaw-head").css("background-image","url(img/zaw-bg.gif)");
			$("#"+id3 +" .zaw-head p").css("font-weight","normal");
			$("#"+id2 +" .zaw-opis").show();
			$("#"+id2 +" .zaw-head").css("background-image","none");
			$("#"+id2 +" .zaw-head p").css("font-weight","bold");
			} else {
			$("#"+id2 +" .zaw-opis").hide();
			$("#"+id2 +" .zaw-head").css("background-image","url(img/zaw-bg.gif)");
			$("#"+id2 +" .zaw-head p").css("font-weight","normal");
		}
		
		$(this).toggleClass("rozwin");
		
		return false;
	});
	
	$("#boisko-1 .sklad").ready(animuj_boisko("boisko-1"));
});


function animuj_boisko(id) {
	var pos = [];
	var i = 0;
		
	for (i = 0; i < $("#" +id +" .sklad li").size(); i++) {
		pos[i] = $("#" +id +" .sklad li").eq(i).css("left");
	}
	
	pos[0] = "10px";
	
	$("#" +id +" .sklad li").css("left","0");
	
	for (i = 0; i < $("#" +id +" .sklad li").size(); i++) {
		$("#" +id +" .sklad li.pilkarz-" +(i+1)).animate({"left": "+=" +pos[i]}, "slow");
	}	
}


	
	
