$(document).ready(function() {
  if($("#index_items")){
    //$("#index_items").load('page/w_pracy_lista.html');
  }
  
  $("#na-zimno").click(function(){
    $("#index_items").load('page/w_pracy_lista/na-zimno.html');
    $(this).css('color', '#ab1818');
    $("#na-cieplo").css('color', '#000');
    $("#najpopularniejsze").css('color', '#000');
  });
  
  $("#na-cieplo").click(function(){
    $("#index_items").load('page/w_pracy_lista/na-cieplo.html');
    $(this).css('color', '#ab1818');
    $("#na-zimno").css('color', '#000');
    $("#najpopularniejsze").css('color', '#000');
  });
  
  $("#najpopularniejsze").click(function(){
    $("#index_items").load('page/w_pracy_lista.html');
    $(this).css('color', '#ab1818');
    $("#na-zimno").css('color', '#000');
    $("#na-cieplo").css('color', '#000');
  });
  
  $("#products").autocomplete("page/produkt/", {
		width: 278,
		selectFirst: false,
		multiple: true
	});
  
  jQuery(document).ready(function($) {
    $('a[rel*=facebox]').facebox() 
  });
  
  $("#popularnosc").mouseover(function(){
    $("#popularnosc").css("background-position", "bottom");
  });
  
  $("#alfabetycznie").mouseover(function(){
    $("#alfabetycznie").css("background-position", "bottom");
  });
  
  $("#zgodnosc").mouseover(function(){
    $("#zgodnosc").css("background-position", "bottom");
  });
  
  $("#popularnosc").mouseout(function(){
    if($("#hid_popularne").val() != 1){
      $("#popularnosc").css("background-position", "top");
    }
  });
  
  $("#alfabetycznie").mouseout(function(){
    if($("#hid_alfabetycznie").val() != 1){     
      $("#alfabetycznie").css("background-position", "top");
    }
  });
  
  $("#zgodnosc").mouseout(function(){
    if($("#hid_zgodnosc").val() != 1){     
      $("#zgodnosc").css("background-position", "top");
    }
  });
  
  $('#movie').click(function() { 
        $.blockUI({ message: $('div.show'),
        css: { 
            top:  ($(window).height() - 505) /2 + 'px', 
            left: ($(window).width() - 883) /2 + 'px', 
            color: '#fff',
            width: '883px'
        } }); 
 		$('.show').show();        
  }); 
  

});

function f_search_sort(by){
	var sort_form = document.getElementById('sort_form'); 
	document.getElementById('mode').value = by;  
	sort_form.submit();
}

function f_gotopage(page){
	var sort_form = document.getElementById('sort_form'); 
	document.getElementById('page').value = page;  
	sort_form.submit();
}

        function f_glosowanie(href){
        
          $.getJSON(href, function(json){
            if (json.state == "ok") {
              $('.votes .box_item_border').hide('slow');
              $('.w_pracy_glos').hide('slow');
              //$('#glosowanie-' + json.id).hide("slow");
              $('#border-ok-' + json.id).show("slow");
              $('#wynik-ok-' + json.id).show("slow");
              $('#item_votes-' + json.id).html('Liczba głosów: ' + json.value);
			  setInterval(function() {
	              $('.votes .box_item_border').hide('slow');
	              $('.w_pracy_glos').hide('slow');			  	
			  },7000);
              return false;
            } else {
              $('.votes .box_item_border').hide('slow');
              $('.w_pracy_glos').hide('slow');
              $('#border-error-' + json.id).show("slow");
              $('#wynik-error-' + json.id).show("slow");
			  setInterval(function() {
	              $('.votes .box_item_border').hide('slow');
	              $('.w_pracy_glos').hide('slow');			  	
			  },7000);
              return false;
            }
          });  
        }
        
function f_add_tag(tag) {
	var input = $("#products").val();
	
	if(input.substr(-1,1) === ',' || !input) tag = tag + ',';
	else tag = ',' + tag + ',';
	
	$("#products").val(input + tag);
}

function f_show_movie() {
	$.kvOverlay().html('<div class="show"></div>');
	
	//var bodyHeight = $('body').height();
	//$('div.kvOverlay').height();	
	//alert(bodyHeight);
	

	        
	$('div.show').html('');
                
	$('div.kvOverlay').click(function (e) {
		var clicked = $(e.target);
		if (clicked.is('div.kvOverlay')) $.kvOverlay.destroy();
	});



}
