﻿var bannerMgr =
{
    timeLength: 5000,
    timer: '',

    Init: function()
    {
        bannerMgr.timer = setTimeout("bannerMgr.ChangeImage('next')", bannerMgr.timeLength);
    },

    ChangeBannerImageByUserAction: function(userAction)
    {
        clearTimeout(bannerMgr.timer);
        bannerMgr.ChangeImage(userAction);
    },

    ChangeImage: function(userAction)
    {
        var bannerImg = $j(".bannerImg");
        var index = bannerImg.attr("imgindex");
        var totalImgs = bannerImg.attr("totalImgs");

        if (userAction == "prev")
        {
            index--;
        }
        else if (userAction == "next")
        {
            index++;
        }

        if (index <= 0)
        {
            index = totalImgs;
        }
        else if (index > totalImgs || isNaN(index))
        {
            index = 1;
        }
        //$j(".bannerImgContainer").fadeOut("slow");
        //$j(".bannerImgContainer").css("display", "none");
        AjaxService.GetBannerImageHtml(index, bannerMgr.GetBannerImageHtml_Complete, bannerMgr.GetBannerImageHtml_Error);
    },

    GetBannerImageHtml_Complete: function(result)
    {
        //$j(".bannerImgContainer").fadeOut("slow", function()
        // {
        //$j(".bannerImgContainer").css("display", "");
        $j(".bannerImgContainer").css("display", "none");
        $j(".bannerImgContainer").fadeIn(1000);
        $j(".bannerImgContainer").html(result);
        
        //});
        //$j(".bannerImgContainer").html(result);


        bannerMgr.timer = setTimeout("bannerMgr.ChangeImage('next')", bannerMgr.timeLength);
    },

    GetBannerImageHtml_Error: function(result)
    {
        //$j(".bannerImgContainer").html("");
    }


}
