


TopCatBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'page_id':[],
		'categories':[],
		'content_part_id':0
	},
	
	initialize: function(options){
		
		//data members
		this.parent(options);
		this.setOptions(options);
		
		//alert(this.options.categories[0]);
		
		//generate HTML
		this.cat_container = new Element('div',{'class':'cat_container'});
		this.cat = new Element('div',{'class':'cat'});
		this.cat_label = new Element('div',{'class':'cat_label'});
		this.cat_input = new Element('select',{'class':'cat_input'});
		this.cat_option_default = new Element('option',{'value':''});
		this.cat_by = new Element('select',{'class':'cat_by'});
		this.cat_by_views = new Element('option',{'class':'cat_by_views'});
		this.cat_by_views.set('html','Views');
		this.cat_by_purchases = new Element('option',{'class':'cat_by_purchases'});
		this.cat_by_purchases.set('html','Purchases')
		this.cat_btn = new Element('input',{'type':'button','value':'Add'});
		
		this.cat_options = [];
		for(var i=0;i<this.options.categories.length;++i){
			this.cat_options[this.cat_options.length] = new Element('option',{'value':this.options.page_id[i]});
			this.cat_options[this.cat_options.length-1].set('html',this.options.categories[i]);
			this.cat_options[this.cat_options.length-1].inject(this.cat_input);
		}
		
		
		this.cat_label.set('html','Add Category:');
		
		//set styles
		this.cat_container.setStyles({'padding':'15px'});
		this.cat.setStyles({'margin-left':'0px'})
		this.cat_label.setStyles({'float':'left','font-family':'arial','color':'#aaaaaa','padding':'3px'});
		this.cat_input.setStyles({'float':'left','margin':'3px','width':'200px'});
		this.cat_btn.setStyles({'float':'left','margin':'3px'});
		this.cat_by.setStyles({'float':'left','margin':'3px'});
		
		//construct HTML
		this.cat_label.inject(this.cat);
		this.cat_input.inject(this.cat);
		this.cat_by_views.inject(this.cat_by);
		this.cat_by_purchases.inject(this.cat_by)
		this.cat_by.inject(this.cat);
		this.cat_btn.inject(this.cat);
		this.cat.inject(this.cat_container);
		this.cat_container.inject(this.box_content);
		
		this.cat_btn.addEvent('click',function(){
			var data = '&category='+this.cat_input.getProperty('value') + '&cat_by=' + this.cat_by.getProperty('value');
			var newCategory = new Request({'url':'index.cfm?action=pages.cp&component=top_products&do=addCategory&content_part_id='+this.options.content_part_id,'data':data,'onComplete':function(){
				window.location.reload(true);
			}.bind(this)}).send()
		}.bind(this))
		
	}
						  
});