﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
var timerFoto,divsFoto,imgsFoto,timeout=10000;

function swFoto(elem) {
    divsFoto.removeClass("sel");
    elem.addClass("sel");
    var img = imgsFoto.eq(divsFoto.index(elem));
    jQuery(".fotoKurier .tytul").replaceWith("<a class=\"tytul\" href=\"" + img.parent().attr("href") + "\"><strong>" + img.attr("title") + "</strong><span>" + img.attr("data-skrot") + "</span></a>");
    imgsFoto.filter(":visible").fadeOut("slow");
    img.fadeIn("slow");
    timerFoto = window.setTimeout(nextFoto, timeout);
}

function nextFoto() {
    var n = jQuery(".fotoKurier>div.sel").next(".fotoKurier>div");
    if (!n.length) n = jQuery(".fotoKurier>div:eq(0)");
    swFoto(n);
}

jQuery(document).ready(function() {
    //Fotokurier
    jQuery(".fotoKurier").append("<div class=\"btn1 sel\"></div><div class=\"btn2\"></div><div class=\"btn3\"></div><div class=\"btn4\"></div><div class=\"btn5\"></div><div class=\"btn6\"></div><a class=\"tytul\"></a>");
    imgsFoto = jQuery(".fotoKurier>a>img");
    divsFoto = jQuery(".fotoKurier>div");
    swFoto(divsFoto.eq(0));
    divsFoto.click(function() {
        if (jQuery(this).hasClass("sel")) return;
        window.clearTimeout(timerFoto);
        swFoto(jQuery(this));
    });

    jQuery(".zglos_blad_ikona").click(function() {
        jQuery(".zglos_blad").toggle("slow");
    });
});

