(function($,myshape){
myshape.gadgets.communityOutfits = function(){
	if(typeof this.init !== 'function'){
		return new myshape.gadgets.communityOutfits();
	} else {
		this.init();
		return this;
	}
};

myshape.gadgets.communityOutfits.prototype = {
	gadgetSelector:"#customer-outfit-page",
	init:function(){
		this.deleteable();
		this.filterable();
	},
	deleteable:function(){
		$(this.gadgetSelector+" .outfit-delete-link").live('click',function(){
			var id = $(this).attr('value');
			myshape.ajax.deleteCustomerOutfit(id,function(data){
				//$.log(data);
			});
			$(this).parents(".outfit-row-cont").remove();
			return false;
		});
		$(this.gadgetSelector+" .outfit-delete-yes").live('click',function(){
			return false;
		});
	},
	filterable:function(){
		var z = this;
		$(function(){
			var shapeFilter =  $(z.gadgetSelector+" .shape-filter")[0];
			if(shapeFilter){
				var search = {};
				if(location.search){
					search = myshape.util.parseQueryString(location.search);
					if(search.shape){
						$(shapeFilter).val(search.shape);
					}
				}

				$(shapeFilter).change(function(){
					var val = $(this).val();
					if(val && (+val) != 0){ // sting 0 is not empty
						search.shape = $(this).val();
					} else {
						delete search.shape;
					}

					var currentURL = location.href.split('/');
					var last = currentURL[currentURL.length-1];

					if(!myshape.util.isDigits(last)){
						location.search = $.param(search);
					} else {
						delete currentURL[currentURL.length-1];
						currentURL = currentURL.join('/');
						location.href = currentURL+'?'+$.param(search);
					}
				});
			}
		});
	},
	states:{
		node:function(){}
	}
};

$(function(){
	myshape.getGadget('communityOutfits');
});

})(jQuery,myshape);