/*
 * moduł czyszczący domyślny tekst inputa po rozpoczęciu wprowadzania treści
 */
(function($){
    $.fn.inputText = function (){
        $(this).each(function() {
            var $that = $(this);
            var $start_text = $that.val();
		
            $that.focus(function() {
                if ( $(this).val()==$start_text ) {
                    $(this).val("");
                }
            }).blur(function() {
                if ( $(this).val()=="" ) {
                    $(this).val($start_text);
                }
            });
		
        });
    }
})(jQuery); 


var $delayTime = 3000; //czas miedzy zmianami produktow w sliderze
var $itemWidth = 166; // szerokosci produktu (160 ma sidebar + 6 marginesu prawego)

/*
 * moduł zwijania i rozwijania zakładek w sidebarze
 */
(function($){
    $.fn.tabEffect = function (){

        var $that = $(this);
        $that.children(".tab_item").each(function() {
            var $firstHeight = $(this).find(".product_container:first").outerHeight();
		
            var $childrenAmount = $(this).find(".product_container").length;
		
            $(this).find(".product_outer").height($firstHeight);
            $(this).find(".product_scroller").width($childrenAmount*$itemWidth);
        });
	
        /* po otwarciu strony rozwini�cie tylko pierwszej zak�adki */
        $that.children(".tab_item").children(".tab_inner").hide();
        $that.children(".tab_item").children("h3").addClass("show_more");
        $that.children(".tab_item:first").children(".tab_inner").show();
        $autoSlide = window.setInterval('startSlider( $(".tab_inner:visible") )', $delayTime); // powtarzanie przewijania co okre�lony czas
        $that.children(".tab_item:first").children("h3").removeClass("show_more").addClass("show_less");
	
        /* rozwijanie zak�adek po klikni�ciu na tytule */
        $(this).children(".tab_item").children("h3").click(function() {
            if ( $(this).hasClass("show_more") ) {
                $that.children(".tab_item").children(".tab_inner").slideUp();
                $that.children(".tab_item").children("h3").removeClass("show_less").addClass("show_more");
                $(this).parent(".tab_item").children(".tab_inner").slideDown();
                clearInterval($autoSlide);
                $autoSlide = window.setInterval('startSlider( $(".tab_inner:visible") )', $delayTime); // powtarzanie przewijania co okre�lony czas
                $(this).removeClass("show_more").addClass("show_less");
            }
        });
	
    }
})(jQuery);

/* funkcja przewijająca produkty */
var counter = 0;
function startSlider(element){	
    if ( parseInt(element.find(".product_scroller").css("left")) <= (((-1)*parseInt(element.find(".product_scroller").width()))+$itemWidth) ) {
        counter = 0;
        var $tmpHeight = element.find(".product_container:eq("+counter+")").outerHeight();
        element.find(".product_scroller").animate({
            left: 0
        }, 500);
        element.find(".product_outer").animate({
            height: $tmpHeight
        }, 500);
    } else {
        if (counter != 0) {
            counter = ((-1)*parseInt(element.find(".product_scroller").css("left")))/$itemWidth;
        }
        counter++;
        var $tmpHeight = element.find(".product_container:eq("+counter+")").outerHeight();
        element.find(".product_scroller").animate({
            left: '-='+$itemWidth
            }, 500);
        element.find(".product_outer").animate({
            height: $tmpHeight
        }, 500);
    }
}
