jQuery(document).ready(function() {

    //Cufon.replace(['.fonts'], {hover: true});

    /*POBRANIE WYSOKOSCI BLOKU PRODUKTU I NAGLOWKA*/
    $("div.blok").attr("id", function (arr) { return "blokwys" + arr; }) .each(function () {

            var tab = new Array();
            var tab2 = new Array();
            var id = this.id;

        $('#'+id).find("div.one_product").each(function(index, item) {

            tab[index] = $(item).outerHeight();
            tab2[index] = $(item).find("h3").outerHeight();

            var max = Math.max.apply(null, tab);
            var max2 = Math.max.apply(null, tab2);
            var min2 = Math.min.apply(null, tab2);

            if(max2 != min2) {
                /*Roznica pomiedzy najmniejsza a najwieksza wysokosc oraz paddingiem*/
                var tmp = max2 - min2 - 10;
                $('#'+id).find("div.one_product h3").css('height', max2-10);
                max = max + tmp;
            }
            $('#'+id).find("div.one_product").css('height', max-20);

        });
    });

    /***STOPKA***/
        
    if ($("body").height() > $(window).height()) {
        $('#jQ_foot').css('position', 'static');
    } else{
        $('#jQ_foot').css('position', 'fixed');
        $('#jQ_foot').css('bottom', '0px');
    }
    
});

/**FACEBOOK**/
jQuery(function () {
    jQuery(".facebook_outer").hover(function(){
        jQuery(".facebook_outer").stop(true, false).animate({left:"0"},"medium");
    },function() {
        jQuery(".facebook_outer").stop(true, false).animate({left:"-205"},"medium");
    },500);
    return false;
});

/**Ilosc**/
function increase(id, wartosc) {
    var ilosc = parseInt(document.getElementById(id).value);
    if(wartosc == '+') {
        if(ilosc >= 1)
            ilosc += 1;
        else
            ilosc = 1;
    } else if(wartosc == '-') {
        if(ilosc > 1)
            ilosc -= 1;
        else
            ilosc = 1;
    }
    jQuery('#'+id).val(ilosc);
}

/**KARUZELA**/
function karuzela(id, time) {

    var autop;
    var scrollp;
    var size = 4;

    /**Sprawdzenie czy mozna wlaczyc slider**/
    var counter = jQuery('#'+id).children().length;

    if(counter < size ) {
        autop = 0;
        scrollp = 0;
    } else {
        autop = 1;
        scrollp = 1;
    }

    jQuery('#'+id).jcarousel({
        auto: +autop,
        scroll: +scrollp,
        animation: +time,
        wrap: "circular",
        initCallback: hoverCarousel
    });
    
}

/**OBSLUGA NAJAZDU NA KARUZELE**/
function hoverCarousel(carousel){
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}
