var MostPopularBlock = new Class({
	
	Implements: Options,
	
	options: {
		tab_pfx:				'mostpopular-category-',
		container_pfx:			'mostpopular-container-',
		
		active_category:		1,
		
		category_count:			5
	},	
	
	initialize: function(options) {
		this.setOptions(options);
		
		for (var i = 0; i < this.options.category_count; i++) {
			if($(this.options.tab_pfx + i))
				$(this.options.tab_pfx + i).addEvent('click', this.setActiveCategory.bind(this, i));
		}
		
		this.setActiveCategory(0);
	},
	
	setActiveCategory: function(index) {
		if($(this.options.tab_pfx + index) == null) {
			return;
		}
		
		if(this.options.active_category == index) {
			this.options.active_category = index;
			return;
		}
		
		if ($(this.options.tab_pfx + this.options.active_category)) {
			$(this.options.tab_pfx + this.options.active_category).className = "simple";
			$(this.options.tab_pfx + this.options.active_category).firstChild.className = "simple";
		}
		
		this.hideObjectContainer(this.options.active_category);
		this.options.active_category = index;
		
		$(this.options.tab_pfx + this.options.active_category).className = "act";
		$(this.options.tab_pfx + this.options.active_category).firstChild.className = "act";
		
		this.showObjectContainer(index);
		
		return false;
	},

	hideObjectContainer: function(index) {
		if($(this.options.container_pfx + index) == null) {
			return;
		}
		
		$(this.options.container_pfx + index).className = "hide";
	},
	
	showObjectContainer: function(index) {
		if($(this.options.container_pfx + index) == null) {
			return;
		}
		
		$(this.options.container_pfx + index).className = "show";
	}
	
});

/*
window.addEvent('domready', function() {
	var mostpopularblock = new MostPopularBlock(mostpopular_options);
});
*/

$$('a.nostat').addEvent('click', function() {
    $('mostpopular-form').action = this.href;
    $('mostpopular-form').submit();
    return false;
});

