﻿// JScript

ASSETSWEB.AssetImage = function() {
    var win = null;
    var images = null;
    var thiz = { init: function(values) {
        images = values;
        var which = 0;
        // create the window on the first click and reuse on subsequent clicks

        win = new Ext.Window({
            title: 'Bridge Photo',
            layout: 'fit',
            width: 500,
            height: 300,
            autoScroll: true,
            maximizable: true,
            bodyCfg: { tag: 'img', src: images[which] },
            plain: true,
            buttons: [
            {
                type: 'button',
                id: 'b1',
                text: 'Previous',
                handler: function() {
                    which = thiz.getValue(which, 'previous');
                    thiz.previous(which);
                }
            },
            {
                type: 'button',
                id: 'b2',
                text: 'Next',
                handler: function() {
                    which = thiz.getValue(which, 'next');
                    thiz.next(which);
                }
}]

            }); //end of new window

            thiz.disableButtons(which);
            win.show(this);
        },  //end of init function

        disableButtons: function(which) {
            if (which == 0) {
                Ext.getCmp('b1').disable();
            }
            if (which == images.length - 1) {
                Ext.getCmp('b2').disable();
            }
        },

        previous: function(which) {
            win.body.dom.src = images[which];
            if (which == 0) {
                Ext.getCmp('b1').disable();
                Ext.getCmp('b2').enable();
            } else {
                Ext.getCmp('b2').enable();
            }
        },
        next: function(which) {
            win.body.dom.src = images[which];
            if (which == images.length - 1) {
                Ext.getCmp('b2').disable();
                Ext.getCmp('b1').enable();
            } else {
                Ext.getCmp('b1').enable();
            }
        },

        getValue: function(which, type) {
            if ('previous' == type) {
                if (which > 0) {
                    which--;
                    return which;
                } // end if

            } // end if
            if ('next' == type) {
                if (which < images.length - 1) {
                    which++;
                    return which;
                } // end if
            } // end if
            return which;
        }



}   // end of var thiz 
        return thiz;
    } (); 