﻿/// <reference path="/Content/scripts/libs/jquery-1.5-vsdoc.js"/>
(function ($) {
    $ = jQuery;
    function FillSlides(ItemCount) {
        for (i = 0; i < ItemCount; i++) {
            $('<li><a class="item" href="#"></a></li>').appendTo('#Slides');
        }
        $("#Slides li:first-child + li a.item").addClass("current");
        $("#Slides").css('margin-left', "-" + $("#Slides").width() / 2 + "px");
        if (ItemCount > 1)
            $(".next").removeClass("disabled");
    }
    function CountSlides() {
        var itemCount = 0;
        $("#Slider .items .item").each(function () {
            itemCount++;
        });
        return itemCount;
    }

    $(function () {
        var ItemCount = CountSlides();
        var root;
        var teller = 0;
        if ($.browser.msie && $.browser.version < 9) {
            //Need to hack the images to fade in IE < 9
            $(".items > .item > img").css('opacity', 'inherit');
            $(".items > .item > img").css('filter', 'inherit');
        }

        $.tools.tabs.addEffect("emFade", function (tabIndex, done) {
            if (teller == 0) {
                this.getPanes().hide();
                this.getPanes().eq(tabIndex).show();
            }
            else {
                this.getPanes().fadeOut(600).delay(600);
                this.getPanes().eq(tabIndex).fadeIn(600);
            }
            teller++;
            done.call();
        });

        if (ItemCount > 1) {
            FillSlides(ItemCount);
            root = $("#Slides").tabs("#Slider > .items > .item", {
                effect: 'emFade',
                rotate: true,
                tabs: 'a.item'
            }).slideshow({ autoplay: true, autopause: false, interval: 8000, clickable: false });
            $('a.Control').addClass('Play');
            window.api = root.data("slideshow");
        }
        else {
            $("#Slider > .items > .item:first").show();
        }

        $("a.item").click(function () {
            $("a.Control").removeClass('Play');
            $("a.Control").addClass('Pause');
            api.stop();
        });
        $("a.Control").click(function () {
            if ($(this).is(".Play")) {
                $(this).removeClass('Play');
                $(this).addClass('Pause');
                api.stop();
            }
            else if ($(this).is(".Pause")) {
                $(this).removeClass('Pause');
                $(this).addClass('Play');
                api.play();
            }
        });
    });
})(jQuery);
