/*
Carrousel pour Moto85
Copyright(c) 2009, Skalpel.

Author : Michael
michael@skalpel.fr

Note : 
	-
ToDo :
	- 
*/

/* 
Class : SKjs.Tabs
	Gestion d'onglets
	
Arguments : 
	container {String} - Id du conteneur
	tabs {String} - Id ou Selecteur des onglets
	panel {String} - Id ou Selecteur des "panneaux"
	options {object} - Objet Options
	
Options :
	indexToShow {Integer} - 
*/
SKjs.Tabs = new Class ({
	Implements: [Events, Options],
	options: {
		indexToShow: 0,
		
		// Events
		onClick: $empty,
		onComplete: $empty
	},
	
	/*
	Property :
		Initialisation de la Class
	*/
	initialize: function(container, tabs, panel, options) {
		this.setOptions(options);
		
		// DOM
		this.container = $(container);
		this.tabs = ($type(tabs) == 'array') ? tabs : this.container.getElements(tabs);
		this.panel = ($type(panel) == 'array') ? panel : this.container.getElements(panel);
		
		// Constantes
		this.index = -1;
		
		// Reset
		this.tabs.each(function (e) {
			e.removeClass(SKjs.activeCls);
		});
		this.panel.each(function (e) {
			e.removeClass(SKjs.activeCls);
		});
		
		
		// Events
		this.tabs.each(function(tab, index) {
			tab.addEvent('click', this.goTo.bindWithEvent(this, [index]));
		}, this);
		
		// Launch
		/*this.tabs[this.options.indexToShow].addClass(SKjs.activeCls);
		this.panel[this.options.indexToShow].addClass(SKjs.activeCls);*/
		this.goTo(false, this.options.indexToShow);
		this.fireEvent('complete');
	},
	
	/*
	Property :
	*/
	goTo: function(e, index) {
		if(e) var e = new Event(e).stop();
		if(index != this.index) {
			this.tabs[index].addClass(SKjs.activeCls);
			this.panel[index].addClass(SKjs.activeCls);
			if(this.tabs[this.index]) this.tabs[this.index].removeClass(SKjs.activeCls);
			if(this.panel[this.index]) this.panel[this.index].removeClass(SKjs.activeCls);
			this.index = index;
			this.fireEvent('click');
		} 
	}
});
