﻿(function ($) {
    $.fn.jWIBannerCarousel = function (o) {
        o = $.extend({
            idBannerPosition: 0,
            cssClass: '',
            width: 0,
            height: 0
        }, o || {});
        $(this).hide();
        if (o.idBannerPosition == 1) {
            $(".img_banner_home").cycle({
                delay: 5000,
                speed: 800,
                pager: ".fases_banner_home",
                activePagerClass: "fase_ativa_banner_home",
                pagerAnchorBuilder: function (idx, el) {
                    var s = "";
                    s = "<li index=\"" + idx + "\"><span>" + $(el).attr("title") + "</span></li>";
                    return s; //<div class=\"seta_fase_ativa_banner_home\"><img src=\"http://localhost:49419/images/seta_fase_banner_ativo.png\" width=\"18\" height=\"19\" /></div>
                }

            });

            $(".fases_banner_home").children("li").click(function () {
                var index = $(this).attr("index");
                var found = false;
                var imgCurrent;
                $(".img_banner_home").children("a").each(function (idx, element) {
                    if (idx == index) {
                        found = true;
                        imgCurrent = $(this);
                        return;
                    }
                });
                if (found) {
                    $(".img_banner_home").children("a").hide();
                    $(imgCurrent).show();
                    $(".seta_fase_ativa_banner_home").hide();
                    $(this).parent().children("li").removeClass("fase_ativa_banner_home");
                    $(this).addClass("fase_ativa_banner_home");
                    $(this).children("div").show();
                }
            });
        }
        else {
            var divMain = $("<div>")
            .addClass("conteudo_pags_banners")
            .insertAfter($(this));

            var ul = $("<ul>")
            .attr("id", "ulBannerPosition" + o.idBannerPosition)
            .appendTo(divMain);

            $(this).css("width", o.width + "px");
            $(this).css("height", o.height + "px");
            $(this).cycle({
                fx: 'fade',
                speed: 'slow',
                timeout: 7000,
                pager: "#ulBannerPosition" + o.idBannerPosition,

                pagerAnchorBuilder: function (idx, el) {
                    return '<li><a href="#">' + (idx + 1) + '</a></li>';
                }
            });
        }
        $(this).show();
    };
})(jQuery);
