
// This function changes the nav bar images depending on whatsection you are in. //

// Written By: Dustin Macdonald //
// url: macdonalddesign.com //

// *********** Define global variables ************* //

var myurl = location.href;

var i = 2;

// *********** Define sections and pages arrays *****************//

// this defines the different section arrays

sections = new Array ( 
	"homeSection",
	"companySection",
	"selectorSection",
	"testimonialsSection",
	"faqSection","resultsSection",
	"videosSection","productsSection",
	"racingSection",
	"cartSection",
	"companySectionCGI")

//		These define the pages within each section
//		EXAMPLE:
//		arraySection[0] = section/image name ==> NOTE: this is the name of the nav image
//		arraySection[1] = image url relative to the page calling the script like: ../images/example.jpg
//		arraySection[...] = pages within that section like: '../directory/example.html'

homeSection = new Array ("home",
	"images/tmpl/nav-home-up.jpg",
	"index.html");

companySection = new Array ("company",
	"images/tmpl/nav-company-up.jpg",
	"news-and-press.html",
	"guarantee.html",
	"reseller.html",
	"privacy-policy.html")

selectorSection = new Array ("selector",
	"../images/tmpl/nav-selector-up.jpg",
	"cgi-local/product-selector.cgi",
	"cgi-local/product-selector-install.cgi")

testimonialsSection = new Array ("testimonials",
	"images/tmpl/nav-testimonials-up.jpg",
	"testimonials.html")

faqSection = new Array ("faq",
	"images/tmpl/nav-faq-up.jpg",
	"dimensions-and-wiring.html",
	"e-boost-basics.html",
	"faq.html",
	"technical-overview.html")

resultsSection = new Array ("results",
	"images/tmpl/nav-results-up.jpg",
	"test-results.html")

videosSection = new Array ("videos",
	"images/tmpl/nav-pics-video-up.jpg",
	"pics-and-videos.html",
	"pics-racing.html",
	"gallery-good-old-days.html",
	"gallery-nopi-nationals-05.html",
	"gallery-pro-racing-pictures.html",
	"gallery-sema-cars.html",
	"gallery-sema-girls.html",
	"videos-racing.html",
	"install-examples.html")

productsSection = new Array ("products",
	"images/tmpl/nav-products-up.jpg",
	"products-accessories.html",
	"products-eram.html",
	"products-super-eram.html",
	"products.html")

racingSection = new Array ("racing",
	"images/tmpl/nav-racing-up.jpg",
	"racing-911-cab.html",
	"racing-car-club-links.html",
	"racing-club-racing.html",
	"racing-cost-of-addiction.html",
	"racing-first-time.html",
	"racing-go-racing.html",
	"racing-scca-links.html",
	"racing-track-links.html",
	"racing.html")

cartSection = new Array ("cart",
	"../images/tmpl/nav-cart-up.jpg",
	"cgi-local/cart.cgi",
	"cgi-local/checkout.cgi",
	"cgi-local/order_status.cgi")

companySectionCGI = new Array ("company",
	"../images/tmpl/nav-company-up.jpg",
	"cgi-local/contact.cgi")


// ****************** EXECUTE THE FUNCTION ****************** //


// Searched for the URL containing the page name //

var j = 0;

while ( j < sections.length ) {

	sectioner( eval ( sections[j] ) );
		
	j++;

}

//  ******************* Functions ********************** //

function sectioner ( myArray ) {

	i = 2;

	while ( i < myArray.length ) {
	
	if ( myurl.indexOf( myArray[i] ) > 0 ) {
			
			chgImg( myArray[0] , myArray[1] );
	
	}
	
	i++;
	
	}
	
}

//  NO index.html PAGE FIX //

	var startName = myurl.lastIndexOf('/');

	var endName = myurl.lastIndexOf('.');
	
	if (startName > endName ) { 
	
		chgImg( homeSection[0] , homeSection[1] ); 

	}


//  Image changing function //

function chgImg( theTitle , theImage ) {

document[theTitle].src = theImage;

}


