// this is a fix for the jQuery slide effects
function slideToggle(el, bShow){
  var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");

  // if the bShow isn't present, get the current visibility and reverse it
  if( arguments.length == 1 ) bShow = !visible;
  
  // if the current visiblilty is the same as the requested state, cancel
  if( bShow == visible ) return false;
  
  // get the original height
  if( !height ){
    // get original height
    height = $el.show().height();
    // update the height
    $el.data("originalHeight", height);
    // if the element was hidden, hide it again
    if( !visible ) $el.hide().css({height: 0});
  }

  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
  if( bShow ){ // show
    $el.show().animate({height: height}, {duration: 500});
  } else { // hide
    $el.animate({height: 0}, {duration: 500, complete:function (){
        $el.hide();
      }
    });
  }
} 

$(document).ready(function() {

  // ukrywamy elementy wysuwane
  $(".moar").hide();

  // wysuwanie/wsuwanie elementow gornego menu
  $(".top-menu-element").hover(
    function() {
      var moar = $(this).children(".inner");
      moar = moar.children(".moar");
      slideToggle(moar, true);
    },
    function() {
      var moar = $(this).children(".inner");
      moar = moar.children(".moar");
      slideToggle(moar, false);
    }
  );

  // Tekst w polu wyszukiwania  
  var defaultString = "Szukaj...";
  $("#search-input").attr("value", defaultString);
  $("#search-input").focus(function(){  
       if($(this).attr("value") == defaultString) $(this).attr("value", "");  
   });  
  $("#search-input").blur(function(){  
        if($(this).attr("value") == "") $(this).attr("value", defaultString);  
   });

  // Tekst w RRRR-MM-DD
  var defaultString2 = "RRRR-MM-DD";
  $(".rrrr-mm-dd").attr("value", defaultString2);
  $(".rrrr-mm-dd").focus(function(){  
       if($(this).attr("value") == defaultString2) $(this).attr("value", "");  
   });  
  $(".rrrr-mm-dd").blur(function(){  
        if($(this).attr("value") == "") $(this).attr("value", defaultString2);  
   });  


});


/* Zastępujemy brakujące zdjęcia na liście produktów */
$(window).load(function() {
	var badImg = new Image();
	badImg.src = 'smarty\/template\/images\/no_image.png';
	for (var i=0;i<document.images.length;i++) {
		if (document.images[i].className == "photo") {
			var cpyImg = new Image();
			cpyImg.src = document.images[i].src;
			if (!cpyImg.width) {
				document.images[i].src = badImg.src;
			}
		}
	}
});


