﻿///<reference path="../../../../File.js"/>
///<reference path="../../../Element.js"/>
///<reference path="../../../Button.js"/>

var njs;
if (!njs) njs = {};
if (!njs.ui) njs.ui = {};
if (!njs.ui.widgets) njs.ui.widgets = {};
if (!njs.ui.widgets.buttons) njs.ui.widgets.buttons = {};

njs.ui.widgets.buttons.ImageButton = function (image, onClickEvent)
{
    this.base = njs.ui.Button;
    this.base(onClickEvent);
    
    this.SetType('njs.ui.widgets.buttons.ImageButton');
    this.SetClass('njs-buttons-ImageButton');
    
    this.Input = new njs.ui.Element(document.createElement('input')); 
    this.Input.SetAttribute('type', 'image');
    
    this.SetImage(image);
    this.Add(this.Input);
}
njs.ui.widgets.buttons.ImageButton.prototype = new njs.ui.Button;  

///Static methods
njs.ui.widgets.buttons.ImageButton.CreateNext = function(onClickEvent) {
    return new njs.ui.widgets.buttons.ImageButton(
        'Assets/Scripts/njs/1.0.0/ui/widgets/buttons/ImageButton/images/next.png', onClickEvent);
}
njs.ui.widgets.buttons.ImageButton.CreatePrev = function(onClickEvent) {
    return new njs.ui.widgets.buttons.ImageButton(
        'Assets/Scripts/njs/1.0.0/ui/widgets/buttons/ImageButton/images/back.png', onClickEvent);
}

///Sets an image to display
njs.ui.widgets.buttons.ImageButton.prototype.SetImage = function(image) {
    if (njs.Asserter.IsNullOrEmpty(image)) return; 
    
    this.Image = new njs.File(image);
    this.ImageDisabled = this.Image.WithSuffix('Disabled');
    //this.ImageMouseOver = this.Image.WithWithSuffix('MouseOver');
    //this.ImageMouseOut = this.Image.WithWithSuffix('MouseOut');
    this.Enable();
}

njs.ui.widgets.buttons.ImageButton.prototype.Disable = function() {
    this.Display(this.ImageDisabled);
    this.IsDisabled = true;
    this.RemoveEvent('click', this.OnClick);
    this.Container.disabled = true;
    this.Input.Container.disabled = true;
}
njs.ui.widgets.buttons.ImageButton.prototype.Enable = function() {
    this.Display(this.Image);
    this.IsDisabled = false;
    this.AddEvent('click', this.OnClick);
    this.Container.disabled = false;
    this.Input.Container.disabled = false;
}

//Private function
njs.ui.widgets.buttons.ImageButton.prototype.Display = function(imageFile) {
    this.Input.SetAttribute('src', imageFile.Path);
}
