﻿// Funkcja sluzaca do preloadowania obrazkow menu
function preloadImage(obrazki,src) {
    var tabelaObrazki = obrazki.split(",");

    for (i = 0; i < tabelaObrazki.length; i++) {
        picture = new Image;
        picture.src = src + tabelaObrazki[i];
    }
}

// Funkcje sluzaca do preloadowania obrazkow bannera
function preloadBanner() {
    var img = $("img[id^=bannerId]");
    var loaded = 0;
    var count = img.length;

    img.each(function(i) {
        var tempSrc = $(this).attr("src");
        $(this).attr("src", "");

        jQuery(this).load(function() {
            loaded++;
            if (count == loaded) {
                $('ul#dynamicBanner').innerfade({
                    speed: 2000,
                    timeout: 4000,
                    type: 'sequence',
                    containerheight: '218px'
                }).css({ 'visibility': 'visible' });
            }
        }).attr("src", tempSrc);
    });
}

// Funkcje przy starcie strony
function onLoadPage() {
    $("#ctl00_mainContentMorePlaceHolder_katEmail").click(function() {
        $(this).val("");
    });

    $("#ctl00_mainContentMorePlaceHolder_katButton").click(function() {
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var email = $("#ctl00_mainContentMorePlaceHolder_katEmail").val();

        if (email == "") {
            $(".catalogOnlineBoxInput div").html("Podaj adres e-mail");
            return false;
        } else if (!emailReg.test(email)) {
            $(".catalogOnlineBoxInput div").html("Podaj poprawny adres e-mail");
            return false;
        }

    });
}

function changeImageShow() {
    var images = $(".preview");

    images.each(function(i) {
        $(this).load(function() {
            if (i === 0) $(this).click().css({ "display": "block", "opacity": 0 }).fadeTo(500, 1, function() { });
            else $(this).css({ "display": "block", "opacity": 0 }).fadeTo(500, 0.5, function() { });
        }).attr("src", jQuery(this).attr("rel"));
    });


    $(".preview").bind("click", function() {
        $(".preview:not(#" + ($(this).attr("id")) + ")").fadeTo(250, 0.5, function() { }).removeClass("active");
        $(this).addClass("active");
        var src = $(this).attr("src").replace('Min', '');
        var tit = $(this).attr("title");

        if ($("#previewImage img").css("display") != "none") $("#previewImage img").fadeOut(500);

        setTimeout(function() {
            $("#previewImage img").load(function() {
                $("#previewImage img").fadeIn(500);
                $("#previewTitle").html(tit);
            }).attr("src", src);
        }, 500);


        return false;
    }).bind("mouseover", function() {
        $(this).fadeTo(250, 1, function() { });

    }).bind("mouseout", function() {
        if (!$(this).hasClass("active")) $(this).fadeTo(250, 0.5, function() { });
    });
}

