﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="../../scripts/jquery-1.3.2-vsdoc2.js" />

Type.registerNamespace("Thallo");

Thallo.ImageViewerControl = function(element) {
    Thallo.ImageViewerControl.initializeBase(this, [element]);
    this._index = 0;
    this._jimage = null;
    this._jprev = null;
    this._jnext = null;
    this._jtext = null;
}

Thallo.ImageViewerControl.prototype = {
    initialize: function() {
        Thallo.ImageViewerControl.callBaseMethod(this, 'initialize');
        this._jimage = $("td:eq(0)", this._element).click(Function.createDelegate(this, this._onImageClick));
        this._jprev = $(".tl-iv-prev", this._element).click(Function.createDelegate(this, this._onPrevClick));
        this._jnext = $(".tl-iv-next", this._element).click(Function.createDelegate(this, this._onNextClick));
        this._jtext = $("span", this._element);
        this.layout();
    },
    dispose: function() {
        Thallo.ImageViewerControl.callBaseMethod(this, 'dispose');
    },
    layout: function() {
        if (this._Images && this._Images.length > 0) {
            this._jimage.css("backgroundImage", "url(/uploads/" + this._Images[this._index].src + ")").html((this._index + 1) + "/" + this._Images.length);

            this._jtext.html(this._Images[this._index].text);
        }
        if (this._index == 0)
            this._jprev.addClass("tl-iv-prev-disabled");
        else
            this._jprev.removeClass("tl-iv-prev-disabled");

        if (this._index >= this._Images.length - 1)
            this._jnext.addClass("tl-iv-next-disabled");
        else
            this._jnext.removeClass("tl-iv-next-disabled");
    },
    _onPrevClick: function(evt) {
        if (this._index == 0)
            return;
        this._index--;
        this.layout();
    },
    _onNextClick: function() {
        if (this._index == this._Images.length - 1)
            return;
        this._index++;
        this.layout();
    },
    _onImageClick: function() {

    }
}
Thallo.ImageViewerControl.registerClass('Thallo.ImageViewerControl', Sys.UI.Control);
Thallo.ImageViewerControl.registerProperties(["Images"]);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

