Event.observe(window, 'load', function() {

	new LookManager(looks, 'look-title', 0);

	if($('customTutorial') != undefined) {
		$('customTutorial').down('ul.tab-style-4').down('li').observe('click', function(event){
			if($('customTutorial').hasClassName('selected')) {
				contentTutorial.hideTutorial('customTutorial');
			} else {
				contentTutorial.showTutorial('customTutorial');
				Event.stop(event);
			}
		});
	}

});

function selectMenu(menu) {
	$('menu-console').childElements().each(function(li, i) {
		if(li.id == menu) {
			li.addClassName("selected");
		} else {
			li.removeClassName("selected");
		}
	});

	return true;
}



var CategoryManager = Class.create();
CategoryManager.prototype = {

	page: null,
	id: null,
	max: null,
	nbPerPage: null,

	initialize: function(id, max, nbPerPage) {
		this.page = 0;
		this.max = max;
		this.nbPerPage = nbPerPage;
		this.id = id;

		var self = this;

		if($(this.id+'-category-back') != undefined) {
			$(this.id+'-category-back').observe('click', function(event) {
				if(self.page > 0) {
					self.backPage();
				}
			});
		}

		if($(this.id+'-category-forward') != undefined) {
			$(this.id+'-category-forward').observe('click', function(event) {
				if(self.page < Math.ceil(self.max/self.nbPerPage) -1) {
					self.forwardPage();
				}
			});
		}

		$(this.id).select('td.category').each(function(td, i) {
			td.observe('click', function(event) {
				if($(self.id).down('a[disabled="disabled"]') != undefined) {
					self.enableCategory($(self.id).down('a[disabled="disabled"]'));
				}
				self.disableCategory(td.down('a'));
			});
		});

		this.disableCategory($(this.id).down('td.category').down('a'));
	},
	backPage : function () {

		this.page--;
		if(this.page == 0) {
			$(this.id+'-category-back').setStyle({visibility : 'hidden'});
		}
		$(this.id+'-category-forward').setStyle({visibility : 'visible'});
		this.display();

	},
	forwardPage: function() {
		this.page++;
		if(this.page >= Math.ceil(this.max/this.nbPerPage) -1 ) {
			$(this.id+'-category-forward').setStyle({visibility : 'hidden'});
		}
		$(this.id+'-category-back').setStyle({visibility : 'visible'});
		this.display();
	},

	display: function() {
		var self = this;
		var offset = this.page * this.nbPerPage;

		$(this.id).select('td.category').each(function(td, i) {
			if(i >= offset && i < offset + self.nbPerPage) {
				td.show();
			} else {
				td.hide();
			}
			td.down('a').removeClassName('disabled');
		});
	},

	disableCategory: function(a) {
		a.down('span').addClassName('disabled');
		a.writeAttribute('disabled', 'disabled');

	},
	enableCategory: function(a) {
		a.down('span').removeClassName('disabled');
		a.removeAttribute('disabled');

	}

}