banners = {};

BannersComponent = Class.create();
BannersComponent.prototype = {
	
	initialize: function(app, id, options) {
		
		this.id = id;
		this.app = app;
		
		this.options = options || {mode:'display'};
		
		updaters[this.id+'_update'] = new Updater(this.id + '_update', this.app, '', this.options);
		
		if (this.options.mode == 'admin') {
			
			ax_forms[this.id+'_form'] = new AxForm(this.id+'_form', {updater:this.id+'_update',
																	 service:'system.adminBanner',
																	 use_return:true, state:'open',
																	 additional_params:['type=' + this.options.type]});
			
			if (this.options.orderable) {
				$(this.id+'_listing').style.display = '';	
			}
			
			listManagers[this.id+'_listing_content'] = new ListManager(this.id+'_listing_content', '', 
																	  {updater:this.id+'_update', 
																	   service:'system.adminBanner', 
																	   additional_params:['template=' + this.options.delete_template,
																	   					  'vars[type]='+this.options.type,
																	   					  'vars[comp_id]='+this.id]});
																	   
			toggle_sets[this.id] = new MultiToggle([this.id+'_display', this.id+'_admin'], this.id+'_display', {});
						
		}
			
	},
	
	mediaInsert: function(res) {
		var parts = res.split('|');
		if (console) console.log("Inserting Media " + parts[1]);
		var regExp = /\.(\w+)$/	;
		regExp.test(parts[1]);
		var ext = RegExp.$1;
		if (console) console.log("EXTENSION: " + ext);
		var temp = {					
					index: parts[0],
					src: parts[1]					
					};
	
		if (console) console.log(this.banners);
		this.banners.push(temp);
		this.bannercomp_new_banner_file_id.value = temp.index;

	},
	
	makeSortable: function() {
		var callParams = [];
		callParams.push('type=' + this.options.type);
		callParams.push('comp_id=' + this.id);
		listManagers[this.id+'_listing_content'].makeSortable(this.id, '', 'UpdateOrder', callParams);
	},
	
	disableSorting: function() {
		listManagers[this.id+'_listing_content'].disableSorting(this.id);
	}
	
	
};