define(['scripts/knockout-3.3.0','scripts/ACTComponent.js'], function(ko, ACTComponent) {

	function ImageComponentViewModel(params, element) {
		this.base      = new ACTComponent($(element), params);
		this.source    = ko.observable("");
		this.alt       = ko.observable("");
		this.width     = ko.observable("default");
		this.height    = ko.observable("default");
		this.className = ko.observable("imgComp");
		this.element   = element;

		this.base.onRefresh = function(obj) {
			params.ready(false);
			this.source(obj.Source);
			this.alt(obj.AlternateText);

			if (obj.Width == -1) {
				this.width("default");
			} else {
				this.width(obj.Width + "px");
			}

			if (obj.Height == -1) {
				this.height("default");
			} else {
				this.height(obj.Height + "px");
			}

			if (obj.Center) {
				this.className("imgCompCenter");
			} else {
				this.className("imgComp");
			}
			params.ready(true);
		}.bind(this);

		this.base.onMessage = function(name, obj) {
			if (name == "SetSource")
				this.source(obj);
		}.bind(this);

		this.base.initialize();
	}

	return {
		createViewModel: function(params, componentInfo) {
			return new ImageComponentViewModel(params, componentInfo.element);
		}
	};

});

