$(document).ready(function(){
	totalFitNav();
	subTabs();
	componentsOfFit();
});

function totalFitNav() {

	$.address.init(function(e) {

		$('.productnav a.item').click(function()
		{				
			$.address.value($(this).attr("href"));

			$(this).parent().find('a').each(function(e){
				$(this).removeClass('selected');
			});

			$(this).addClass("selected");
			
			if( $(this).attr('rel') == '88-points-of-fit' )
			{
				$('#88-points-of-fit').show();
				$('#creating-your-fit').hide();
				$('#research-and-development').hide();
				$('#testing-the-philosophy').hide();
				$('#technology-and-fit').hide();
				$('#fit-for-health').hide();
				$('#the-execution-of-fit').hide();
				$('#glossary-of-fit').hide();
			} 
			else if( $(this).attr('rel') == 'creating-your-fit' )
			{
				$('#88-points-of-fit').hide();
				$('#creating-your-fit').show();
				$('#research-and-development').hide();
				$('#testing-the-philosophy').hide();
				$('#technology-and-fit').hide();
				$('#fit-for-health').hide();
				$('#the-execution-of-fit').hide();
				$('#glossary-of-fit').hide();
			}
			else if( $(this).attr('rel') == 'research-and-development' )
			{
				$('#88-points-of-fit').hide();
				$('#creating-your-fit').hide();
				$('#research-and-development').show();
				$('#testing-the-philosophy').hide();
				$('#technology-and-fit').hide();
				$('#fit-for-health').hide();
				$('#the-execution-of-fit').hide();
				$('#glossary-of-fit').hide();
			}
			else if( $(this).attr('rel') == 'testing-the-philosophy' )
			{
				$('#88-points-of-fit').hide();
				$('#creating-your-fit').hide();
				$('#research-and-development').hide();
				$('#testing-the-philosophy').show();
				$('#technology-and-fit').hide();
				$('#fit-for-health').hide();
				$('#the-execution-of-fit').hide();
				$('#glossary-of-fit').hide();
			}
			else if( $(this).attr('rel') == 'technology-and-fit' )
			{
				$('#88-points-of-fit').hide();
				$('#creating-your-fit').hide();
				$('#research-and-development').hide();
				$('#testing-the-philosophy').hide();
				$('#technology-and-fit').show();
				$('#fit-for-health').hide();
				$('#the-execution-of-fit').hide();
				$('#glossary-of-fit').hide();
			}
			else if( $(this).attr('rel') == 'fit-for-health' )
			{
				$('#88-points-of-fit').hide();
				$('#creating-your-fit').hide();
				$('#research-and-development').hide();
				$('#testing-the-philosophy').hide();
				$('#technology-and-fit').hide();
				$('#fit-for-health').show();
				$('#the-execution-of-fit').hide();
				$('#glossary-of-fit').hide();
			}
			else if( $(this).attr('rel') == 'the-execution-of-fit' )
			{
				$('#88-points-of-fit').hide();
				$('#creating-your-fit').hide();
				$('#research-and-development').hide();
				$('#testing-the-philosophy').hide();
				$('#technology-and-fit').hide();
				$('#fit-for-health').hide();
				$('#the-execution-of-fit').show();
				$('#glossary-of-fit').hide();
			}
			else if( $(this).attr('rel') == 'glossary-of-fit' )
			{
				$('#88-points-of-fit').hide();
				$('#creating-your-fit').hide();
				$('#research-and-development').hide();
				$('#testing-the-philosophy').hide();
				$('#technology-and-fit').hide();
				$('#fit-for-health').hide();
				$('#the-execution-of-fit').hide();
				$('#glossary-of-fit').show();
			}
			
			sIFR.replace(gotham, {
				wmode: 'transparent',
				selector: 'h2.sifr-red',
				preventWrap: false,
				forceWidth: true,
				fitExactly: true,
				forceSingleLine: true,
				css: [ '.sIFR-root {color: #D20E18;}' ]
			});
			
			sIFR.replace(gotham, {
				wmode: 'transparent',
				selector: 'h2.sifr-black',
				preventWrap: false,
				forceWidth: true,
				fitExactly: true,
				forceSingleLine: true,
				css: [ '.sIFR-root {color: #000000;}' ]
			});
			
			return false;
		});

	}).change(function(e) {

		var pathNames = $.address.pathNames();
		var navItem;

		// set the navigation element
		if (pathNames.length == 0) {
			navItem = $(".productnav a.item[rel=88-points-of-fit]");
		} else if (pathNames.length == 1) {
			navItem = $('.productnav a.item[rel=' + pathNames[0] + ']');
		}

		var title = navItem.text();

		// define scripts for each section
		var sectionScripts = {
			'88-points-of-fit': "",
			'creating-your-fit': "",
			'research-and-development': "",
			'testing-the-philosophy': "",
			'technology-and-fit': "",
			'fit-for-health': "",
			'the-execution-of-fit': "",
			'glossary-of-fit': ""
		};

		var scriptName = sectionScripts[navItem.attr("rel")];
		var contentId = "#content-" + navItem.attr("rel");

		// switch selected element
		navItem.siblings('.selected').removeClass('selected');
		navItem.addClass('selected');

		if( $(navItem).attr('rel') == '88-points-of-fit' )
		{
			$('#88-points-of-fit').show();
			$('#creating-your-fit').hide();
			$('#research-and-development').hide();
			$('#testing-the-philosophy').hide();
			$('#technology-and-fit').hide();
			$('#fit-for-health').hide();
			$('#the-execution-of-fit').hide();
			$('#glossary-of-fit').hide();
		} 
		else if( $(navItem).attr('rel') == 'creating-your-fit' )
		{
			$('#88-points-of-fit').hide();
			$('#creating-your-fit').show();
			$('#research-and-development').hide();
			$('#testing-the-philosophy').hide();
			$('#technology-and-fit').hide();
			$('#fit-for-health').hide();
			$('#the-execution-of-fit').hide();
			$('#glossary-of-fit').hide();
		}
		else if( $(navItem).attr('rel') == 'research-and-development' )
		{
			$('#88-points-of-fit').hide();
			$('#creating-your-fit').hide();
			$('#research-and-development').show();
			$('#testing-the-philosophy').hide();
			$('#technology-and-fit').hide();
			$('#fit-for-health').hide();
			$('#the-execution-of-fit').hide();
			$('#glossary-of-fit').hide();
		}
		else if( $(navItem).attr('rel') == 'testing-the-philosophy' )
		{
			$('#88-points-of-fit').hide();
			$('#creating-your-fit').hide();
			$('#research-and-development').hide();
			$('#testing-the-philosophy').show();
			$('#technology-and-fit').hide();
			$('#fit-for-health').hide();
			$('#the-execution-of-fit').hide();
			$('#glossary-of-fit').hide();
		}
		else if($(navItem).attr('rel') == 'technology-and-fit' )
		{
			$('#88-points-of-fit').hide();
			$('#creating-your-fit').hide();
			$('#research-and-development').hide();
			$('#testing-the-philosophy').hide();
			$('#technology-and-fit').show();
			$('#fit-for-health').hide();
			$('#the-execution-of-fit').hide();
			$('#glossary-of-fit').hide();
		}
		else if( $(navItem).attr('rel') == 'fit-for-health' )
		{
			$('#88-points-of-fit').hide();
			$('#creating-your-fit').hide();
			$('#research-and-development').hide();
			$('#testing-the-philosophy').hide();
			$('#technology-and-fit').hide();
			$('#fit-for-health').show();
			$('#the-execution-of-fit').hide();
			$('#glossary-of-fit').hide();
		}
		else if( $(navItem).attr('rel') == 'the-execution-of-fit' )
		{
			$('#88-points-of-fit').hide();
			$('#creating-your-fit').hide();
			$('#research-and-development').hide();
			$('#testing-the-philosophy').hide();
			$('#technology-and-fit').hide();
			$('#fit-for-health').hide();
			$('#the-execution-of-fit').show();
			$('#glossary-of-fit').hide();
		}
		else if( $(navItem).attr('rel') == 'glossary-of-fit' )
		{
			$('#88-points-of-fit').hide();
			$('#creating-your-fit').hide();
			$('#research-and-development').hide();
			$('#testing-the-philosophy').hide();
			$('#technology-and-fit').hide();
			$('#fit-for-health').hide();
			$('#the-execution-of-fit').hide();
			$('#glossary-of-fit').show();
		}
		
		sIFR.replace(gotham, {
			wmode: 'transparent',
			selector: 'h2.sifr-red',
			preventWrap: false,
			forceWidth: true,
			fitExactly: true,
			forceSingleLine: true,
			css: [ '.sIFR-root {color: #D20E18;}' ]
		});
		
		sIFR.replace(gotham, {
			wmode: 'transparent',
			selector: 'h2.sifr-black',
			preventWrap: false,
			forceWidth: true,
			fitExactly: true,
			forceSingleLine: true,
			css: [ '.sIFR-root {color: #000000;}' ]
		});
		
		return false;

	});
}


function subTabs()
{
	$('#creating-your-fit .subtabs .nav a').click(function()
	{				
		$(this).parent().find('a').each(function(e){
			$(this).removeClass('selected');
		});

		$(this).addClass("selected");
		
		if( $(this).attr('rel') == 'lengths' )
		{
			$('.lengths').show();
			$('.width').hide();
			$('.lasts').hide();
			$('.insoles').hide();
		} 
		else if( $(this).attr('rel') == 'width' )
		{
			$('.lengths').hide();
			$('.width').show();
			$('.lasts').hide();
			$('.insoles').hide();
		}
		else if( $(this).attr('rel') == 'lasts' )
		{
			$('.lengths').hide();
			$('.width').hide();
			$('.lasts').show();
			$('.insoles').hide();
		}
		else if( $(this).attr('rel') == 'insoles' )
		{
			$('.lengths').hide();
			$('.width').hide();
			$('.lasts').hide();
			$('.insoles').show();
		}

		return false;
	});

}


function componentsOfFit()
{
	$('#glossary-of-fit ul li a').each(function(){
		
		if($(this).hasClass('selected'))
		{
			$(this).prepend("&lt; ");
		}
	});
	
	
	$('#glossary-of-fit ul li a').click(function(){
		
		
		$('#glossary-of-fit ul li a').each(function(){

			if($(this).hasClass('selected'))
			{
				var newString = $(this).html().split("&lt; ");
				$(this).html(newString[1]);
				$(this).removeClass('selected');
			}
		});
		
		$(this).addClass('selected');
		$(this).prepend("&lt; ");
		
		$('#glossary-of-fit .leftInfo').each(function()
		{
			$(this).addClass('none');
		});
		
		var rel = $(this).attr('rel');
				
		$('#glossary-of-fit #' + rel + '.leftInfo').removeClass('none');
		
		return false;
		
	});
	
	
}