/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2009 Brand Labs LLC
 * 
 *--------------------------------------------------------------------------*/
var HomePageTabs = {
	boxesClassName: 'homepage_top_box',
	buttonContainerClassName: 'homepage_top_right_top',
	buttonClassName: 'button',
	buttonOffSuffix: '_off.jpg',
	buttonOnSuffix: '_on.jpg',
	
	initialize: function() {
		HomePageTabs.disableButtonLinks();
		HomePageTabs.observeButtons();
	},
	
	swapBoxes: function(selectedBoxIndex) {
		var boxes = $$('div.' + HomePageTabs.boxesClassName);
		
		if (null != boxes) {
			boxes.each(function(box, boxIndex) {
				if (boxIndex == selectedBoxIndex) {
					box.show();
				} else {
					box.hide();
				}
			});
		}
	},
	
	observeButtons: function() {
		var boxes = $$('div.' + HomePageTabs.boxesClassName);
		
		if (null != boxes) {
			boxes.each(function(box, boxIndex) {
				var buttons = box.getElementsBySelector('div.' + HomePageTabs.buttonContainerClassName + ' img.' + HomePageTabs.buttonClassName);
				
				if (null != buttons) {
					buttons.each(function(button, buttonIndex) {
						if (buttonIndex != boxIndex) {
							button.observe('mouseover', function(event) {
								button.src = button.src.gsub(HomePageTabs.buttonOffSuffix, HomePageTabs.buttonOnSuffix);
							});
							button.observe('mouseout', function(event) {
								button.src = button.src.gsub(HomePageTabs.buttonOnSuffix, HomePageTabs.buttonOffSuffix);
							});
						}
						button.observe('click', function(event) {
							HomePageTabs.swapBoxes(buttonIndex);
						});
					});
				}
			});
		}
	},
	
	disableButtonLinks: function() {
		var buttonLinks = $$('div.' + HomePageTabs.boxesClassName + ' div.' + HomePageTabs.buttonContainerClassName + ' a');
		
		if (null != buttonLinks) {
			buttonLinks.each(function(buttonLink) {
				buttonLink.observe('click', function(event) {
					Event.stop(event);
				});
			});
		}
	}
}

//Start once window is loaded
Event.observe(window, 'load', HomePageTabs.initialize);