$(document).ready(function() {
  
        
    // form
    $("form").submit(function(){

      // name
      var uriName = '';
      var tmpName = $("#simpleSearch input:first").val();
      tmpName = tmpName.replace(/(\s{1,})/gi, "_");
      if($("#simpleSearch input:first").val()) uriName = '/name/'+ tmpName;
          
      // kategorie
      var uriCat = '';
      $(".parseCategory input[@checked]").each( function(){
        if($(this).val()){
          if(!uriCat) uriCat = '/cat/'; else uriCat = uriCat + ',' ;
          uriCat = uriCat + $(this).val();  
        }
      });
      
      // daty
      var uriDate = ''; var first = 1;
      $(".searchDate1").each( function(){
        if($(this).val()){
          if(!uriDate) uriDate = '/date/';
          if(first == 0 )uriDate = uriDate + ',' ;
          uriDate = uriDate + $(this).val();  
        }
        first = 0;
      });



      var uriOpus = '';
      if($("#opus").val()) var tmpOpus = $("#opus").val();
      else  var tmpOpus = '';
      tmpOpus = tmpOpus.replace(/(\s{1,})/gi, "_");
      if($("#opus").val()) uriOpus = '/opus/'+ tmpOpus;
   
      // osoby
      var uriPerson = '';
      if($("#person").val()) var tmpPerson = $("#person").val();
      else  var tmpPerson = '';
      tmpPerson = tmpPerson.replace(/(\s{1,})/gi, "_");
      if($("#person").val()) uriPerson = '/person/'+ tmpPerson;



      // country        
      var uriCountry = '';
      var tmpCountry = $('#country').val();
      if(tmpCountry) uriCountry = '/country/'+ tmpCountry;

      // publisher        
      var uriPublisher = '';
      var tmpPublisher = $('#publisher').val();
      if(tmpPublisher) uriPublisher = '/publisher/'+ tmpPublisher;

      // type        
      var uriType = '';
      var tmpType = $('#type').val();
      if(tmpType) uriType = '/type/'+ tmpType;

      // location        
      var uriLocation = '';
      var tmpLocation = $('#location').val();
      if(tmpLocation) uriLocation = '/location/'+ tmpLocation;






      // source_type
      var uriSource_type = '';
      if($("#source_type").val()) var tmpSource_type = $("#source_type").val();
      else  var tmpSource_type = '';
      tmpSource_type = tmpSource_type.replace(/(\s{1,})/gi, "_");
      if($("#source_type").val()) uriSource_type = '/source_type/'+ tmpSource_type;

      // location
      var uriLocation = '';
      if($("#location").val()) var tmpLocation = $("#location").val();
      else  var tmpLocation = '';
      tmpLocation = tmpLocation.replace(/(\s{1,})/gi, "_");
      if($("#location").val()) uriLocation = '/location/'+ tmpLocation;





      // bio
      var uriBio = '';
      if($("#bio").attr('checked')) uriBio = '/bio/yes';
 
 
       
      fullPage=thisPage+uriName+uriCat+uriOpus+uriPerson+uriDate+uriBio+uriSource_type+uriLocation+uriCountry+uriPublisher+uriType;  
       // alert(fullPage);
      location.href = fullPage;
      return false;   
     });
 
 
////////////////////

  // zmiana widoku listingu

  // linie
  $("#content hr").wrap("<div class='hr'></div>");
  $(".listingLeft  tr:even").addClass("listingDarker");
  $(".listingRight  tr:even").addClass("listingDarker");
  // podswietlanie lini 
  $(".listing tr").hover(
     function(){ $(this).addClass("over"); }
    ,function(){ $(this).removeClass("over");
  });
  
////////////////////
  
  
  // ukrywanie przy load
  if($("#searchSlideBox").attr('class')) {
    $("#searchSlideTrigger").html('<span>'+txtSimple+'&laquo;</span><span style="display:none;">'+txtAdvanced+'&raquo;</span>');
  } else {
    $("#searchSlideTrigger").html('<span>'+txtAdvanced+'&raquo</span><span style="display:none;">'+txtSimple+'&laquo</span>');
    $("#searchSlideBox").hide();
  }
  // rozwijanie / zwijnie
  $("#searchSlideTrigger").bind('click',function(){ 
    $("#searchSlideBox").slideToggle('normal');
    $("#searchSlideTrigger span").toggle();
  });

  // checkbox
  $("#searchSlideBox input:checkbox").hide();
  $(".searchCategory label").not('.text').each( function() {
    if($(this).children("input").attr('checked'))
      $(this).addClass("checkFalse").addClass("checkTrue");
    else
      $(this).addClass("checkFalse");
  });
  $("#searchSlideBox label").click(function(){
    if($(this).attr('class') == "checkFalse") {
      $(this).removeClass("checkFalse").addClass("checkTrue");
      $(this).children("input").attr('checked', true);
      return false;
    } else {
       $(this).removeClass("checkTrue").addClass("checkFalse");
       $(this).children("input").removeAttr('checked');
      return false;
    }
  });
    
});
  