﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />

/// <reference path="jquery.intellisense.js"/>

/// <reference path="Kleenex.Core.js"/>

Kleenex.CardBrowser = function(clientId)
{
    this.ClientID = clientId;
    this.Selector = "#" + clientId;
    this.Initialize();
    this.CurrentIndex = 0;
};
Kleenex.CardBrowser.prototype =
{
    Name : 'Kleenex.CardBrowser',
    __typeName : 'Kleenex.CardBrowser',
    __class : true,
    AttachEvents : function()
    {
        var __app = this;
        
        this.CardDetails = $(this.Selector + ' .CardDetail');
        this.MaxIndex = this.CardDetails.length;
        
        var goLast = function()
        {
            this.blur();
            var index = __app.CurrentIndex - 1;
            if (index < 0)
            {
                index = __app.CardDetails.length - 1;
            }
            __app.ShowCard(index);
        };
        
        var goNext = function()
        {
            this.blur();
            var index = __app.CurrentIndex + 1;
            if (index >= __app.CardDetails.length)
            {
                index = 0;
            }
            __app.ShowCard(index);
        };
        
        var navigation = $(this.Selector + ' .Navigation a');
        $(navigation.get(0)).click(goLast);
        $(navigation.get(2)).click(goNext);
    },
    Display : function()
    {
        var __app = this;
        
        this.CardDetails.hide();
        $(this.CardDetails.get(0)).show();
    },
    ShowCard : function(index)
    {
        var __app = this;
        
        var delay = 200;
        
        if (index <= this.MaxIndex)
        {
            $(__app.CardDetails.get(__app.CurrentIndex)).fadeOut(delay, function()
            {
                $(__app.CardDetails.get(__app.CurrentIndex)).hide();
                $(__app.CardDetails.get(index)).fadeIn(delay);
                __app.CurrentIndex = index;
            });
        }
    }
};

Kleenex.Extend(Kleenex.CardBrowser, Kleenex.UserControl);

