﻿Type.registerNamespace('Inductronic');Inductronic.DropTargetImageBehavior = function(element) {
Inductronic.DropTargetImageBehavior.initializeBase(this, [element]);this._initialized = false;this._onLoadDelegate = null;this._onMouseDownDelegate = null;this._preloadImageUrl = '';this._imageUrl = '';this._imageRecipe = '';this._key = '';this._data = '';this._description = '';this._index = -1;this._loading = true;this._enabled = true;this._registered = false;}
Inductronic.DropTargetImageBehavior.prototype = {
initialize : function() {
Inductronic.DropTargetImageBehavior.callBaseMethod(this, 'initialize');var el = this.get_element();if(this._onLoadDelegate == null)
{
this._onLoadDelegate = Function.createDelegate(this, this._onLoadEvent);$addHandler( el, 'load', this._onLoadDelegate );}
if(this._onMouseDownDelegate == null)
{
this._onMouseDownDelegate = Function.createDelegate(this,this._onMouseDownEvent);$addHandler( el, 'mousedown', this._onMouseDownDelegate);}
this._handleRegistration(true);this.update();this._loading = false;this._initialized = true;}, 
dispose : function() { 
this._handleRegistration(false);var el = this.get_element();if(this._onLoadDelegate)
{
$removeHandler(el, 'load',this._onLoadDelegate);delete this._onLoadDelegate;this._onLoadDelegate = null;}
if (this._onMouseDownDelegate)
{
$removeHandler(el, 'mousedown',this._onMouseDownDelegate);delete this._onMouseDownDelegate;this._onMouseDownDelegate = null;}
Inductronic.DropTargetImageBehavior.callBaseMethod(this, 'dispose');}, 
_handleRegistration : function(register) {
if(register == true && this._registered == false) {
Inductronic.DragDropManagerInternal.registerDropTarget(this);Inductronic.ApplicationManagerBehavior.getInstance().registerSelectable(this);this._registered = true;} else if(register == false && this._registered == true) {
Inductronic.DragDropManagerInternal.unregisterDropTarget(this);Inductronic.ApplicationManagerBehavior.getInstance().unregisterSelectable(this);this._registered = false;}
},
update : function()
{
var el = this.get_element();if(this._preloadImageUrl != null && this._preloadImageUrl.length > 0)
{
this._imageUrl = '';el.src = this._preloadImageUrl;}
if( this._key != null && this._key.length > 0 && this._imageRecipe != null && this._imageRecipe.length > 0 )
{
this.set_imageUrl(Inductronic.ApplicationManagerBehavior.getInstance().createImageUrl(this._key, this._imageRecipe));} 
if(this._imageUrl != null && this._imageUrl.length > 0)
{
if(!Sys.UI.DomElement.containsCssClass(el, 'loading'))
{
Sys.UI.DomElement.addCssClass(el, 'loading');}
if( el.complete && Sys.Browser.agent == Sys.Browser.Opera )
{
el.src = this._imageUrl;this._onLoadEvent(null);}
else 
{ 
el.src = this._imageUrl;}
}
if(this._loading == true)
{
$common.setVisible(el, true);}
},
reset : function()
{
this.set_key('');this.set_description('');this.set_imageUrl('');this.update();},
select : function() {
var el = this.get_element();if(!Sys.UI.DomElement.containsCssClass(el, 'selected'))
{
Sys.UI.DomElement.addCssClass(el, 'selected');}
},
deselect : function() {
var el = this.get_element();if(Sys.UI.DomElement.containsCssClass(el, 'selected'))
{
Sys.UI.DomElement.removeCssClass(el, 'selected');}
},
_onLoadEvent : function(ev)
{
var el = this.get_element();if(Sys.UI.DomElement.containsCssClass(el, 'loading'))
{
Sys.UI.DomElement.removeCssClass(el, 'loading');}
},
_onMouseDownEvent : function(ev)
{
ev.preventDefault();if(this._enabled == true) {
Inductronic.ApplicationManagerBehavior.getInstance().select(this);this._raiseEvent('imageClick', Sys.EventArgs.Empty);}
},
get_dropTargetElement: function()
{
return this.get_element();},
canDrop: function(dragMode, dataType, data)
{
return (dataType == 'DragDropImage');},
drop: function(dragMode, dataType, data)
{
if (this._enabled == true && dataType == 'DragDropImage')
{ 
this.set_key(data.key);this.update();if( this._loading == false )
{
this._raiseEvent('imageChanged', Sys.EventArgs.Empty);}
Inductronic.ApplicationManagerBehavior.getInstance().select(this);}
},
onDragEnterTarget: function(dragMode, dataType, data)
{
}, 
onDragLeaveTarget: function(dragMode, dataType, data)
{
},
onDragInTarget: function(dragMode, dataType, data)
{
},
add_imageClick : function(handler) {
this.get_events().addHandler('imageClick', handler);}, 
remove_imageClick : function(handler) {
this.get_events().removeHandler('imageClick', handler);}, 
add_imageChanged : function(handler) {
this.get_events().addHandler('imageChanged', handler);}, 
remove_imageChanged : function(handler) {
this.get_events().removeHandler('imageChanged', handler);}, 
_raiseEvent : function(eventName, eventArgs) { 
var handler = this.get_events().getHandler(eventName);if (handler) { 
if (!eventArgs) { 
eventArgs = Sys.EventArgs.Empty;} 
handler(this, eventArgs);} 
},
get_enabled : function() {
return this._enabled;}, 
set_enabled : function(value) {
var e = Function._validateParams(arguments, [{name: 'value', type: Boolean }]);if (e) throw e;if (this._enabled != value) {
this._enabled = value;if(this._initialized) {
this._handleRegistration(this._enabled);}
this.raisePropertyChanged('enabled');}
},
get_imageUrl : function()
{
return this._imageUrl;}, 
set_imageUrl : function(value)
{
var e = Function._validateParams(arguments, [{name: 'value', type: String}]);if (e) throw e;if (this._imageUrl != value) {
this._imageUrl = value;this.raisePropertyChanged('imageUrl');}
},
get_imageRecipe : function() {
return this._imageRecipe;}, 
set_imageRecipe : function(value) { 
var e = Function._validateParams(arguments, [{name: 'value', type: String}]);if (e) throw e;if (this._imageRecipe != value) {
this._imageRecipe = value;this.raisePropertyChanged('imageRecipe');}
},
get_key : function() {
return this._key;}, 
set_key : function(value) { 
var e = Function._validateParams(arguments, [{name: 'value', type: String}]);if (e) throw e;if (this._key != value){
this._key = value;this.raisePropertyChanged('key');} 
},
get_data : function() {
return this._data;}, 
set_data : function(value) {
var e = Function._validateParams(arguments, [{name: 'value', type: String}]);if (e) throw e;if (this._data != value){
this._data = value;this.raisePropertyChanged('data');} 
},
get_index : function() {
return this._index;}, 
set_index : function(value) { 
var e = Function._validateParams(arguments, [{name: 'value', type: Number}]);if (e) throw e;if (this._index != value){
this._index = value;this.raisePropertyChanged('index');} 
}, 
get_preloadImageUrl : function() {
return this._preloadImageUrl;}, 
set_preloadImageUrl : function(value) { 
var e = Function._validateParams(arguments, [{name: 'value', type: String}]);if (e) throw e;if (this._preloadImageUrl != value) {
this._preloadImageUrl = value;this.raisePropertyChanged('preloadImageUrl');}
},
get_description : function() {
return this._description;}, 
set_description : function(value) {
var e = Function._validateParams(arguments, [{name: 'value', type: String}]);if (e) throw e;if (this._description != value) {
this._description = value;if(this._description == null)
{
this._description = '';}
var el = this.get_element();if(el)
{
el.alt = this._description;}
this.raisePropertyChanged('description');}
}
}
Inductronic.DropTargetImageBehavior.registerClass('Inductronic.DropTargetImageBehavior', AjaxControlToolkit.BehaviorBase, AjaxControlToolkit.IDropTarget, Sys.IDisposable);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();