$(document).ready(
function(){

var wybrany=0;
var ilosc_m=$("#tabela_content_mezczyzni tr").length;
var ilosc_k=$("#tabela_content_kobiety tr").length;
var ilosc=0;
id_przycisk = "#tabela_content_mezczyzni";


    tabContainers = $(".tabs_content");  
    tabContainers.hide();      


    $("#tabs_line a:first").addClass('active');
    $(".tabs_content:first").fadeIn("fast");
        
    $('#tabs_line a').click(function () {
      //alert("dupa");
        tabContainers.hide();
        $($(this).attr("href")).fadeIn("fast");
        $('#tabs_line a').removeClass('active');
        $(this).addClass('active');
        
        return false;
    });

    tabContainers2 = $(".tabela_content");  
    tabContainers2.hide();      


    $("#tabela_right a:first").addClass('active');
    $(".tabela_content:first").fadeIn("fast");
        
    $('#tabela_right a').click(function () {
      //alert("dupa");
        tabContainers2.hide();
        $($(this).attr("href")).fadeIn("fast");
        $('#tabela_right a').removeClass('active');
        $(this).addClass('active');
        if($(this).attr("href")=="#tabela_content_mezczyzni")
        {
          id_przycisk="#tabela_content_mezczyzni";
          wybrany=0;
        }
        else
        {
          id_przycisk="#tabela_content_kobiety";        
          wybrany=1;  
        }  
        return false;
    });    




    $("#tabela_dol").click(
      function() {
      if(wybrany==0){
        ilosc=ilosc_m;  
      } else {
        ilosc=ilosc_k;        
      }

        var poz_left = parseInt($(id_przycisk).css('margin-top'));

        if( (ilosc*19+poz_left) > 8*19 )
        {
          if(wybrany==0)
            $("#tabela_content_mezczyzni").css("margin-top", (poz_left-19)+'px');
          else
            $("#tabela_content_kobiety").css("margin-top", (poz_left-19)+'px');            
        }
       return false;
      }
    );
    $("#tabela_top").click(
      function() {
        var poz_left = parseInt($(id_przycisk).css('margin-top'));
        if( poz_left <0 )
        {
          if(wybrany==0)
            $("#tabela_content_mezczyzni").css("margin-top", (poz_left+19)+'px');
          else
            $("#tabela_content_kobiety").css("margin-top", (poz_left+19)+'px');            
        }

       return false;
      }
    );
//start - shoutbox
var shoutbox_action = $('#shoutbox_form').attr("action");
$('#shoutbox_form').submit(
  function()
  {

    if( $("#shoutbox_input_tresc").val() == '' || $("#shoutbox_input_tresc").val() == 'Tekst')
      alert("Musisz wypełnić pole tekst");
    else if( $("#shoutbox_input_nick").val() == '' || $("#shoutbox_input_nick").val() == 'Nick' )
      alert("Musisz wypełnić pole nick");      
    else
    {
      $("#widoczne_okno_shoutbox").html(''); 
      $("#widoczne_okno_shoutbox").css('background', "url('images/loading.gif') 50% 50% no-repeat");            
      $.post(shoutbox_action, { shoutbox_nick: $("#shoutbox_input_nick").val(), shoutbox_tresc: $("#shoutbox_input_tresc").val() },
      function(data){
        $("#widoczne_okno_shoutbox").css('background', ""); 
        $("#widoczne_okno_shoutbox").scrollTop(0);             
        $("#widoczne_okno_shoutbox").html(data);
      });
    }
    return false;
  }
);
$("#shoutbox_refresh").click( 
  function()
  {
    refresh();  
    $("#widoczne_okno_shoutbox").scrollTop(0);
    return false;
  }
);
refresh();
function refresh()
{
  $("#widoczne_okno_shoutbox").html(''); 
  $("#widoczne_okno_shoutbox").css('background', "url('images/loading.gif') 50% 50% no-repeat");  
  $.post(shoutbox_action,
  function(data){
    $("#widoczne_okno_shoutbox").css('background', "");  
    $("#widoczne_okno_shoutbox").html(data);
 
  });
}
$("#shoutbox_input_tresc").attr('value','Tekst');
$("#shoutbox_input_nick").attr('value','Nick');
$("#widoczne_okno_shoutbox").scrollTop(0);
    $("#shoutbox_dol").click(
      function() {
        var offset_top = parseInt($("#widoczne_okno_shoutbox").scrollTop());
        $("#widoczne_okno_shoutbox").animate(
        {
          scrollTop : (offset_top+187)
        },600);
       return false;
      }
    );    
    
    $("#shoutbox_top").click(
      function() {
        var offset_top = parseInt($("#widoczne_okno_shoutbox").scrollTop());
        $("#widoczne_okno_shoutbox").animate(
        {
          scrollTop : (offset_top-187)
        },600);
       return false;
      }
    );  
//end - shoutbox  

//tabele small
    tab1 = $(".tabela_small");  
    tab2 = $(".tabela_small_result");  
    tab1.hide();   
    tab2.hide();   
    $(".tabela_small:first").fadeIn("fast"); 
    $(".tabela_small_result:first").fadeIn("fast");       
    $('.tabela_small_ul li a').click(function () {
        tab1.hide();
        tab2.hide();
        $($(this).attr("href")).fadeIn("fast");
        $($(this).attr("href")+'_result').fadeIn("fast");
        return false;
    });          
  }
);
