Cufon.replace('.menu-bar a', { hover: true, 'font-weight': 'bold' });

/********************************************************************************/
/***** SUB PAGE SWITCHER *******************************************************/
/******************************************************************************/

	var tabValue;
	var activeTab;
	
	function rewriteURL() {
		var pathname	= window.location.pathname;
		var href		= window.location.href;
			tabCheck	= href.split('#subpages');
			tabCheck	= tabCheck[1];
			tabValue = 1;
			if(tabCheck) {
				tabValue	= tabCheck;
			}
			activeTab 	= tabValue;
	}
	rewriteURL();

	$(document).ready(function() {
		
		var transition	= 'off';
		var speedSwitch	= 500;
		var speedOpen	= 750;
		var speedClose	= 750;
		var allowClose	= 'false';
		var shell 		= $('#switcher-shell');

	// finds all of the sections on the page and hides them
		var sections = $(shell).find('.subpages');
		
	// Identify the open section on page load (default is 1)
		var cell1 	= $('.subpages'+tabValue);
		$(cell1).show();
		
	// finds all of the sections on the page and hides them
		var sections = $(shell).find('.subpages');
	
	// Assign events to the links
		var links = $('.menu-bar li a');
		$(links).each(function(i) {
			i = i%sections.length;
			var i2 = i+1;
			new events(this,i2);
		});
		$(links[activeTab-1]).addClass('active');
		$(sections).each(function(i) {
			var section = $(sections[i]);
			$(section).attr({'id':''});
		});

		function events(link,newTab) {
			$(link).click(function(event) {
				if(transition == 'off') {
				// If the link is active, dont run the script
					if($(link).attr('class') != 'active') {
						transition = 'on';
						
						$(links[activeTab-1]).removeClass('active');
						$(links[newTab-1]).addClass('active');

					// Change the active URL to reflect the active section
						var url = document.location.href;
						var splitter	= url.split('#');
						document.location.href = splitter[0] + '#subpages' + newTab;
					
					// Sets the class for the clicked link while the fade is occurring
						$(link).addClass('transition');
						
						var cell1 = $('.subpages'+activeTab);
						var cell2 = $('.subpages'+newTab);
						$(shell).append($(cell2));
						
						$(cell2).css({'opacity':0});
						$(cell2).show();
						
						var height1 = $(cell1).height();
						var height2	= $(cell2).height();

					// Set the starting height of the container
						$(shell).css({'height':height1+'px'});
					
					// Make all sections position:absolute, preparing for the fade
						$(sections).each(function(i) {
							var section = $(sections[i]);
							$(section).attr({'id':''}).css({'position':'absolute'});
						});

					// Animate //
						new switcherAction(cell1,cell2,shell,height1,height2,newTab);
					}
				}
				event.preventDefault();
			});
		}
		
		function switcherAction(cell1,cell2,shell,height1,height2,newTab) {
			var animate1	= $(shell).animate({'height': height2 + 'px'}, speedSwitch, 'linear');
			var animate2	= $(cell1).animate({'opacity':0}, speedSwitch);
			var animate3	= $(cell2).animate({'opacity':0.999}, speedSwitch, function() {
				$(cell1).hide();
				activeTab = newTab;
				transition = 'off';
			});

			if(height1 != height2) {
				animate = $(animate2).add(animate3);
			} else {
				animate = $(animate1).add(animate2).add(animate3);
			}
		}
	});
