var tab = new Object("pl","en");
tab["pl"] = new Object();
tab["en"] = new Object();

tab["pl"]["LAN_1"] = "Szukaj...";
tab["pl"]["LAN_2"] = "Login";

tab["en"]["LAN_1"] = "Search...";
tab["en"]["LAN_2"] = "Username";

$(document).ready(function(){

    $(".infoExtra").mouseover(function(){
      $(".infoExtraContent").stop().animate({height: "230px"},500);
      $(".infoExtraContentImg").stop().animate({height: "230px"},500);
    });

    $(".infoExtraContent").mouseout(function(){
      $(".infoExtraContent").stop().animate({height: "0px"},300);
      $(".infoExtraContentImg").stop().animate({height: "0px"},300);
    });
     
    var ln = $('meta[http-equiv=content-language]').attr("content");
    if(ln == 'en') {
      $("#job").hide();
    }

    $("#maincol h2.default:first, h2.Array:first, #maincol h2.cpage").addClass("disabled");
    
    // dodanie linijki wyswietlajacej blad
    var divError = $("<div>").addClass("infoInfo").hide();
    divError.insertBefore($("#maincol #content")); 

    // przenoszenie erroru
    if($(".infoInfo2").html() ){
      divError.html($(".infoInfo2").html());
      divError.show();
      $(".infoInfo2").remove();
    }
 
    // usuniecie pustych h2
    $("h2").each(function(){ if(!$(this).html()) $(this).remove();})
 
    if($(".infoInfo")) $(".infoInfo").insertBefore($("#maincol #content"));
 
     // tooltip
    $(".flagPL, .flagEN , .chapter, .linkLabelContent, .downloadLink, .searchButtonAdvance, .newsEmail img, .newsPrint img, #2Konferencja a, #Konferencja3 a, .showTitle, .bbcode_buttons, .postIcon img").tooltip({ 
        tip: '.tooltip', 
        opacity: 0.8,
        effect: 'fade', 
        fadeOutSpeed: 100, 
        predelay: 200, 
        position: "bottom center",         
    });

    $(".flagPL").attr("title",tab[ln]["LAN_2"]);
    $(".flagEN").attr("title",tab[ln]["LAN_3"]);    

    $("#job[rel]").overlay({expose: '#fff', effect: 'apple', onLoad: function(event) { 
       //var img = $("img:last").filter(function(){ return $(this).attr("id") == ""; });
       //img.height(this.getOverlay().height() + 30); 
    }}); 

    $(".Konferencja3PatronList").tooltip({ effect: 'slide', offset: [0, 0]});

    if(!$(".scrollable").hasClass("gallery"))
      $(".scrollable").scrollable({clickable: false, item: "a", size: 5}).navigator({item: "a", size: 5});

    // galeria
    if($("#2Konferencja a").length != 0){
      $("#2Konferencja a").overlay({ 
        target: '#gallery2Konferencja', 
        expose: '#f1f1f1' 
      }).gallery({ 
        speed: 800 
      });
    }

    // galeria
    if($("#Konferencja3 a").length != 0){
      $("#Konferencja3 a").overlay({ 
        target: '#galleryKonferencja3', 
        expose: '#f1f1f1' 
      }).gallery({ 
        speed: 800 
      });
    }

    // galeria
    if($("#Konferencja3Patron a").length != 0){
      $("#Konferencja3Patron a").overlay({ 
        target: '#galleryKonferencja3Patron', 
        expose: '#f1f1f1' 
      }).gallery({ 
        speed: 800 
      });
    }

    // dynamiczne dodanie div'a do li w menu
    $("#leftcol ul li a").each(function(){
      $(this).before("<div>");
      $(this).prev().addClass("point");
    });

    // wyszukiwarka
    $("#leftcol div.search").appendTo("#header_bottom");
    $("div.search .button").val("");
    $(".search .tbox").val(tab[ln]["LAN_1"])
                         .focus(function(){
                            if($(this).val() == tab[ln]["LAN_1"]){ 
                              $(this).val("");
                            }
                          })
                          .blur(function(){
                            if($(this).val() == ""){
                              $(this).val(tab[ln]["LAN_1"]);
                            } 
                          });

    // logowanie (kod przed zalogowaniem)    
    if($(".login form").length != 0)
    { 
      // ustawienie focus
      $(".login #username").focus(function(){
                              if($(this).val() == tab[ln]["LAN_2"]){ 
                                $(this).val("");
                              }
                            })
                            .blur(function(){
                              if($(this).val() == ""){
                                $(this).val(tab[ln]["LAN_2"]);
                              } 
                            });                          
                
      $(".login #userpassText").focus(function(){
                              $(this).hide();
                              $(".login #userpass").show().focus();        
                            });
      $(".login #userpass").blur(function(){
                              if($(this).val() == ""){
                                $(this).hide();
                                $(".login #userpassText").show();          
                              }
                            });
       
    // wiecej
    $(".login .more").mouseover(function(){
                          $(this).next().addClass("over");
                       //   $(".login .moreMenu a:first").addClass("first");
                       })
                       .mouseout(function(){
                          $(this).next().removeClass("over");
                         // $(".login .moreMenu a:first").removeClass("first");
                       });
  
    // tworzenie menu dla "wiecej"
    $(".login .moreMenu").mouseover(function(){
                              $(this).addClass("over");
                              $(this).prev().addClass("over");
                              $(".login .moreMenu a:first").addClass("first");
                         })
                         .mouseout(function(){
                            $(this).removeClass("over");
                            $(this).prev().removeClass("over");
                            $(".login .moreMenu a:first").removeClass("first");
                         });

    // przenoszenie bledow logowania
    if($(".login form").prev("div").length != 0){
      $(".infoInfo").show().html($(".login form").prev().html().replace(/\<.*\>/g,""));
      $(".login form").prev().remove();
    }
  }
  
  // wyrownanie wysokosci menu do contentu
  EqualHeight = function(){
    var menu = $("#leftHeight").height();
    var content = $("#content").height();
    if(menu > content) {
      $("#leftcol").height(menu);
      $("#maincol").height(menu);
    } else {
      $("#leftcol").height(content);
      $("#maincol").height(content);
    }
  }
  EqualHeight();
  
  // zaznaczenie aktualnie wyswietlanej podstrony
  var file = location.href.split("/").pop();
  $("#leftcol ul li a").removeClass("strong");
  $("#leftcol ul li a:first").addClass("strong");
  $("#leftcol ul li a").each(function(){
    var link = $(this).attr("href").split("/").pop();
    if(link == file || link == file.split("?")[0]){
      $(this).addClass("strong");
      $("#leftcol ul li a:first").removeClass("strong");
      
      // dodawanie klas do tagow dla wybranych podstron
      if($(".tableDownload")){
        $(".tableDownloadSearch .tbox").val(tab[ln]["LAN_1"])
                                       .focus(function(){
                                          if($(this).val() == tab[ln]["LAN_1"]){ 
                                            $(this).val("");
                                          }
                                        })
                                        .blur(function(){
                                          if($(this).val() == ""){
                                            $(this).val(tab[ln]["LAN_1"]);
                                          } 
                                        });   
      } 
            
      return false;
    }
  });

      if($(".tableDownloadList")){  
        var table = $(".tableDownloadList");
      //  table.find("tr:last").addClass("tableDown");
        table.find("tr").filter(function(i){                        
                          return i != 0 && i !=1; 
                        })
                        .each(function(i){
                          $(this).find("td:last").addClass("last");
                        });
      }
      
      if($(".tableDownloadEdit")){
        $(".tableDownloadEdit tr").filter(function(i){ return i!=0;})
                                  .each(function(i){
                                    $(this).addClass("even");
                                  });
      }


  if(file.split("?")[0] == "search.php"){
    $("#content h2").addClass("searchH2").each(function(){
      if($(this).next()) $(this).next().addClass("searchH2Content");
    });
  }

  if($(".tableSearch")){
    $(".tableSearch .searchInput").val(tab[ln]["LAN_1"])
                                  .focus(function(){
                                    if($(this).val() == tab[ln]["LAN_1"]){ 
                                      $(this).val("");
                                    }
                                  })
                                  .blur(function(){
                                    if($(this).val() == ""){
                                      $(this).val(tab[ln]["LAN_1"]);
                                    } 
                                  }); 
  } 

  // zwijanie/rozwijanie rozdzialow (status)
  $(".chapter").each(function(){
    $(this).next().hide();
    
    $(this).toggle(function(){      
      $(this).next().show('slow',function(){EqualHeight();});
      $(this).css("background-image",$(this).css("background-image").replace("right","bottom"));      
    }, function(){
      $(this).next().hide('slow',function(){EqualHeight();});
      $(this).css("background-image",$(this).css("background-image").replace("bottom","right"));         
    });
  }); 

  // zakladka Linki
  if($(".linkImg").lengt != 0){
    $(".linkImg").animate({marginRight: "0px"},1000);
    $(".linkLabelContent a").attr("target","_blank");
  }  

  // zakladka Kontakt
  $(".contactFrame, .contactFrameRight, .contactAttention").mouseover(function(){
    $(".contactFrameRight, .contactAttention").css({opacity: "0.3"});
    $(this).css({opacity: "1.0"});
  });

  $(".fileinputs .file").change(function(){
    $(".fileinputs .fakefile input").val($(this).val());
  });
  
  
/************************/
// GALERY
/************************/

  $(".scrollable.gallery").scrollable().navigator();
  
  $(".scrollable.gallery .items img").click(function() {
  
  	// see if same thumb is being clicked
  	if ($(this).hasClass("active")) { return; }
  
  	// calclulate large image's URL based on the thumbnail URL (flickr specific)
  	var url = $(this).attr("src").replace("_t", "");
  
  	// get handle to element that wraps the image and make it semi-transparent
  	var wrap = $("#image_wrap").fadeTo("medium", 0.5);
  
  	// the large image from www.flickr.com
  	var img = new Image();
  
  
  	// call this function after it's loaded
  	img.onload = function() {
  
  		// make wrapper fully visible
  		wrap.fadeTo("fast", 1);
  
  		// change the image
  		wrap.find("img").attr("src", url);
  
  	};
  
  	// begin loading the image from www.flickr.com
  	img.src = url;
  
  	// activate item
  	$(".items img").removeClass("active");
  	$(this).addClass("active");
  
  // when page loads simulate a "click" on the first image
  }).filter(":first").click();
  
  });

	function changeGallery(nr){
    $("#main_navi_gallery li").removeClass("active").each(function(i){
      if(nr-1 == i){
        $(this).addClass("active");
        return false;
      } 
    });
    
    $(".page").each(function(){
      if($(this).hasClass("enable")){
        $(this).css("opacity","0.0").removeClass("enable").addClass("disable").hide();
        $(this).find("img.active").addClass("activeHide").removeClass("active");
        return false;
      }
    });
    
    $(".page").each(function(){
      if($(this).attr("id") == "page"+nr){
        $(this).show().removeClass("disable").stop().animate({opacity: "1.0"},1000,function(){$(this).addClass("enable");});
        $("#image_wrap img").css("opacity","0.0").attr("src",$(this).find("img.activeHide").attr("src").replace("_t.jpg",".jpg"));
        $("#image_wrap img").stop().animate({opacity: "1.0"},600);
        $(this).find("img.activeHide").removeClass("activeHide").addClass("active");
        return false;
      }
    });
    EqualHeight();
  }
/************************/
