AE.namespace('AE.tool.disableEvent');

AE.tool.disableEvent = function(){
	this.defConfig = {
		targetTag : ['img'],
		targetClass : ['AE:disable'],
		disableEvent : ['contextmenu','selectstart','copy','cut','paste']
	}
};

AE.tool.disableEvent.prototype = YL.merge(AE.tool.disableEvent.prototype, {
	_P_DATA : {
		_items : []
	},

	getTarget : function(){
		try{
			var _cfg = this.defConfig;
			var _tempList = [];
			var _list = [];
			if( (_cfg['targetTag'].length > 0)){
				for(var i=0;i<_cfg['targetTag'].length;i=i+1){
					for(var j=0;j<document.getElementsByTagName(_cfg['targetTag'][i]).length;j=j+1){
						_tempList.push(document.getElementsByTagName(_cfg['targetTag'][i])[j])
					}
				}
			}
			if(_cfg['targetClass'].length > 0){
				for(var i=0;i<_cfg['targetClass'].length;i=i+1){
					for(var j=0;j<_tempList.length;j=j+1){
						if(_tempList[j].className.indexOf(_cfg['targetClass'][i])!=-1){
							_list.push(_tempList[j]);
						}
					}
				}
			}else{
				_list = _tempList;
			}
			this._P_DATA['_items'] = _list;
			return true;
		}catch(e){
			return false;
		}
	},

	disableEvent : function(){
		return false;
	},

	eventBind : function(){
		for(var i=0;i<this._P_DATA['_items'].length;i=i+1){
			for(j=0;j<this.defConfig['disableEvent'].length;j=j+1){
				var _event = 'on' + this.defConfig['disableEvent'][j];	//for ff
				this._P_DATA['_items'][i].setAttribute(_event,'return false');	//for ff

				YUE.on(this._P_DATA['_items'][i],this.defConfig['disableEvent'][j],function(){return false;})	// for ie
			}
		}
	},

	init : function(userConfig){
		this.defConfig = YL.merge(this.defConfig, userConfig || {});
		if(this.getTarget()){
			this.eventBind();
		}
	}
})