Enjin_Shopping = function(cfg) {	Enjin_Shopping.__instances[cfg.preset_id] = this;	this.init(cfg);}Enjin_Shopping.__preset_id = null;Enjin_Shopping.__instances = {};Enjin_Shopping.getInstance = function(preset_id) {		return Enjin_Shopping.__instances[preset_id];}Enjin_Shopping.prototype = {	items: []	,init: function(config)	{		this.preset_id = config.preset_id;		this.items = config.items;		this.currency = config.currency;		this.url = config.url;	}			,showDetail: function(item_index)	{		var options = {};		var item = this.items[item_index];				options.cls = 'shopping-details-window';		options.title = item.item_name;				var img = item.image_name == '' || item.image_name == null ? this.url.default_image : item.image_name;		options.content = $('<div class="image element_avatar simple"><img src="'+img+'" border="0"/></div><div class="info"><div class="button"></div><div class="description">'+item.description+'</div></div>');									var self = this;		options.content.find('.button').append(Enjin_UI.button({value:'Buy ' + this.getPrice(item),click:function() { Enjin_Core.hideCustomPopup(Enjin_Core._popup); self.purchase(item_index); }, button_type: 'element_bigbutton'}));		options.hideFooter = true;							  		Enjin_Core.showWindowPopup(options); 		return false;	}		,purchase: function(item_index, forcePurchase )	{		if ( this.items[item_index].custom_field && parseInt(this.items[item_index].show_custom,10) && typeof forcePurchase === 'undefined' )		{			this.showCustom(item_index);		}		else		{			var item = this.items[item_index];			var form = $('.m_shopping-' + this.preset_id + ' form');						form.find('input[name=item_number]').val(item.paypal_item);			form.find('input[name=amount]').val(item.item_price);			form.find('input[name=item_name]').val(item.item_name);			form.find('input[name=custom]').val( typeof forcePurchase === 'undefined' ? '' : forcePurchase );			form.find('input[name=on0]').val(item.custom_field);			form.find('input[name=os0]').val( typeof forcePurchase === 'undefined' ? '' : forcePurchase );			form.find('input[name=return]').val( form.find('input[name=return]').val() + item.item_id );						form.submit();		}	}		,showCustom: function(item_index)	{		var self = this;		var options = { cls: 'shopping-custom-window' };		var item = this.items[item_index];				options.title = 'More information required';		options.hideFooter = true;			options.content = $('<div class="custom-field-wrapper"><div class="field-label">' + item.custom_field + '</div><div class="input-text"><input type="text" name="custom_field"/></div><div class="error hidden">Please enter a value</div><div class="button"></div></div>');							options.content.find('.button').append(Enjin_UI.button({value:'Continue purchase',click:function() { var w = $(this).closest('.element_popup_window'); var v = w.find('input[name=custom_field]').val(); if ( $.trim(v) == '' ) { w.find('.error').show(); w.find('.input-text').addClass('input-error'); } else { self.purchase(item_index,v); } }}));						  		Enjin_Core.showWindowPopup(options); 		return false;		}		,getPrice: function(item)	{		var amount = parseFloat(item.item_price).toFixed(2);		return ( this.currency.pos == 'append' ? amount + this.currency.symbol : this.currency.symbol + amount );	}}
