var mmgTabs = new Class({
	Implements: [new Events, new Options],
  options: {
    activationEvent: 'click', // you can set this to ‘mouseover’ or whatever you like
    slideDirection: 'snap',		// horizontal, vertical, anything else = snap
	  currentClass: 'current',  // change this to match your css
	  completeFunc: null,			  // function to be called after slide is complete
	  fx: null
  },  
  
  initialize: function(tabContainer, currentTab, options) {
		this.setOptions(options);
		$extend(this, {
			activationEvent: this.options.activationEvent,
			slideDirection: this.options.slideDirection,
			currentClass: this.options.currentClass,
			prevFx: this.options.fx,
			currentFx: this.options.fx,
			completeFunc: this.options.completeFunc,
			prevTab: null
		});

		$(currentTab).set('class', 'current');
		$("_"+currentTab).set('class', '');
    if (tabContainer) { this.buttons = $(tabContainer).getChildren();}

    $each(this.buttons, function(tab, index) {
    	$(tab.id).addEvent(this.activationEvent, function(e){
				if(e) e.stop();
				
				this.prevTab = currentTab;
				currentTab = tab.id;			

				if(this.prevTab != currentTab) {
					$(this.prevTab).set('class', '');
					$("_"+this.prevTab).set('class', 'mmgTabHide');
					$(currentTab).set('class', 'current');
					$("_"+currentTab).set('class', '');

					switch(this.slideDirection) {
						case 'vertical':
						case 'horizontal':
						this.prevFx = new Fx.Slide($("_"+this.prevTab), {
								mode: this.slideDirection,
								wrapper: this.element, //default is this.element
								hideOverflow: false,

								//Fx Options
								link: 'cancel',
								transition: 'sine:in',
								duration: '300',
								onComplete: function(){
									if(this.completeFunc != null) {
										eval(this.completeFunc);
									}
								}.bind(this)
						}).hide().show().hide(); //note, .hide and .show do not fire events 
						this.currentFx = new Fx.Slide($("_"+currentTab), {
								mode: this.slideDirection,
								wrapper: this.element, //default is this.element
								hideOverflow: false,

								//Fx Options
								link: 'cancel',
								transition: 'sine:in',
								duration: '300',
								onComplete: function(){
									if(this.completeFunc != null) {
										eval(this.completeFunc);
									}
								}.bind(this)
						}).hide().show().hide(); //note, .hide and .show do not fire events 
							//this.prevFx.slideOut();
							this.currentFx.slideIn();
							break;
						default: 
							eval(this.completeFunc);
					}
					$("_"+currentTab).getParent().set('styles', {'overflow':'visible', 'height':'auto'});
				}
			}.bind(this));

			if(currentTab != tab.id) {
				$("_"+tab.id).set('class', 'mmgTabHide');
			}
			$("_"+tab.id).set('styles', {'float':'left', 'width':'100%', 'height':'auto'});

    }.bind(this));
  }
});
