var Tabber = {
	count: 0,
	slider: '',
	tabs: [],
	bottom_tabs: [],
	current_index: 0,
	slide_width: 0,
	right_button: '',
	left_button: '',
	
	timeout: function(func, millis) {
	  window.setTimeout(func, millis);
	},
	
	deselectAll: function() {
		Tabber.tabs.each(function(node) {
			node.removeClassName('selected');
		});
	},
	
	move: function(number) {
		new Effect.Move(Tabber.slider, { x: number * -1 * Tabber.slide_width, y: 0, mode: 'absolute', duration: 0.5, transition: Effect.Transitions.sinoidal });
		Tabber.current_index = number;
		Tabber.tabs[number].addClassName('selected');
	},
	
	start: function() {
		Tabber.slider = $('tabber_slider');
		Tabber.tabs = $$('#menu_cont ul li a');
		Tabber.bottom_tabs = $$('#footer_right a');
		Tabber.count = Tabber.slider.childElements().length;
		Tabber.slide_width = $('tabber_slider_container').clientWidth;
		Tabber.right_button = $$('#arrow_right a')[0];
		Tabber.left_button = $$('#arrow_left a')[0];
		Tabber.current_index = 0;
		
		
		Tabber.tabs.each(function(elem,i){
			Event.observe(elem, 'click', function(e){
				Tabber.deselectAll();
				Tabber.move(i);
			});
		});
		
		Tabber.bottom_tabs.each(function(elem,i){
			Event.observe(elem, 'click', function(e){
				Tabber.deselectAll();
				Tabber.move(i);
			});
		});
		
		Event.observe(Tabber.right_button, 'click', function(e){
			if (Tabber.current_index != (Tabber.count - 1)) {
				Tabber.deselectAll();
				Tabber.move(Tabber.current_index + 1);
			}
		});
		
		Event.observe(Tabber.left_button, 'click', function(e){
			if (!Tabber.current_index == 0) {
				Tabber.deselectAll();
				Tabber.move(Tabber.current_index - 1);
			}
		});
	}
}

var ContentSwap = {
	node_count: 0,
	container: '',
	content_elements: [],
	current_num: Math.floor(Math.random()*3),
	
	timeout: function(func, millis) {
	  window.setTimeout(func, millis);
	},
	
	delayedAppear: function() {
	  window.setTimeout(ContentSwap.appear, 5000);
	},
	
	hideAll: function() {
		ContentSwap.content_elements.each(function(node) {
			node.hide();
		});
	},
	
	show: function() {
		ContentSwap.content_elements[ContentSwap.current_num].show();
	},
	
	appear: function() {
		ContentSwap.hideAll();
		ContentSwap.current_num = ContentSwap.current_num == ContentSwap.node_count ? 0 : ContentSwap.current_num + 1;
		ContentSwap.show();
		ContentSwap.delayedAppear();
	},
	
	start: function() {
		ContentSwap.node_count = $('right_content_cont').childElements().length - 1;
		ContentSwap.content_elements = $('right_content_cont').childElements();
		ContentSwap.container = $('right_content_cont');
		ContentSwap.content_elements[ContentSwap.current_num].show();
	}
}


Event.onReady(function() {
	
	Tabber.start();
	ContentSwap.start();
	
	//Add behavior to the login form
	Event.addBehavior({
		'input.login_login:focus' : function(e) {
			this.parentNode.style.background = "url(/images/layout/login/field_bg.jpg) 0px 0px no-repeat";
		}
	});
});

function show_michael() {
	hide_moe();
	$('michael').show();
	$('michael_more').hide();
}

function hide_michael() {
	$('michael').hide();
	$('michael_more').show();
}

function show_moe() {
	hide_michael();
	$('moe').show();
	$('moe_more').hide();
}

function hide_moe() {
	$('moe').hide();
	$('moe_more').show();
}