var ProductSelector = Class.create({	
	initialize: function(url){		
		this.initListeners();
		this.baseurl = url;
	},
	
	initListeners: function(){
		// Remove al previous listeners
		$$('li.product-category a.category').each(function(a){
		    a.stopObserving('click', this.update);
			a.addClassName('h'+a.getHeight());
		});
		
		// Set all category listeners
		$$('li.product-category a.category').each(function(a){
			a.observe('click', this.update.bindAsEventListener(this, a));			
		}.bind(this));
	},
	
	update: function(evt, a){
		evt.stop();
		a.down('img.loader').setStyle({display: 'block'});
		new Ajax.Request(a.href, {
			method: 'post',
			onSuccess: function(resp) {
				this.setActive(a.up('ul'), a.up('li'));
				$('category-overzicht').update(resp.responseText);
				this.initListeners();
			}.bind(this)
		});	
	},
		
	setActive: function(ul, active_li){
		var elements = ul.getElementsByTagName('li');
		
		for(i = 0; i < elements.length; i++)
			elements[i].removeClassName('active');
		
		active_li.addClassName('active');
	}
});
