(function(){
	
	var saw = window.saw;
	
	saw.widget = {};
	
	
	
	var Abstract = saw.widget.Abstract = function(opts){
		//Create jQuery wrapper of this instance
		this.$I = $(this);	
		//Copy the settings object for each instance	
		this._settings = $.extend(true, {}, this._settings);		
		//Extend this instance with all of the properties in the opts parameter.
		$.extend(this, opts);
		//console.log(this[$.expando]);
	};
	Abstract.prototype = {
		$I:null,
		className:"Abstract",
		_settings:{
			ajax:{
				type:"GET"
			}
		},
		settings:function(collection, key, value){
			if(arguments.length == 1){
				return $.isPlainObject(this._settings[collection]) ? this._settings[collection] : null;	
			}else if($.isPlainObject(key)){
				$.extend(this.settings(collection), key);
				this.trigger("settingsChanged");
				return this;
			}else if(typeof(key)==="string"){
				if(arguments.length == 3){
					this.settings(collection)[key]=value;
					this.trigger("settingsChanged");
					return this;
				}else{
					return this.settings(collection)[key];
				}
			}
		},
		bind:function(){
			if(arguments[2]!==false) arguments[0]+="."+this.className;
			this.$I.bind.apply(this.$I, arguments);
			return this;
		},
		unbind:function(){
			console.log("problem with widget.unbind()...need to look into");
			if(arguments[2]!==false) arguments[0]+="."+this.className;
			this.$I.unbind.apply(this.$I, arguments);
			return this;
		},
		trigger:function(){
			if(arguments[2]!==false) arguments[0]+="."+this.className;			
			this.$I.trigger.apply(this.$I, arguments);	
			return this;
		},
		load:function(settings){
			var I = this;
			var req = $.ajax($.extend({
					beforeSend:function(){
						I.trigger("beforeLoad", req);
					},
					error:function(){
						I.trigger("loadError", req);
					},
					complete:function(){
						I.trigger("loadComplete", req);	
					},
					success:function(){
						I.trigger("loadSuccess", req);	
					}
				}, this.settings("ajax"), settings));
			return this;
		},
		toString:function(){
			return "[object "+this.className+"]";	
		}
		
	};
	
	
})();
