function initNav() {
	var currentPage = getCurrentPage();
	var currentPath = getCurrentPath();
	
	var nav = new Array();
	nav["/ca/paypass/mobile/"] = "home";
	nav["/ca/paypass/mobile/sitemap.html"] = "home";
	nav["/ca/paypass/mobile/about/"] = "aboutTrial";
	nav["/ca/paypass/mobile/phone_payments.html"] = "aboutPhonePay";

	nav["/ca/personal/en/technologies/paypass/merchant_search.html"] = "paypassLocations";
        	nav["/ca/paypass/mobile/help/faqs.html"] = "faq";
        	nav["/ca/personal/en/general/privacy_policy.html"] = "mcPrivacy";
        	nav["http://www.citicards.ca/canada/homepage/english/privacy.jsp"] = "citiPrivacy";
	
	var currentClass = "";

	if( nav[ currentPath + currentPage ] ) {
		currentClass = nav[ currentPath + currentPage ];
	} else if( nav[ currentPath ] ) {
		if( nav[ currentPath ] != "home" ) {
			currentClass = nav[ currentPath ];
		}
	}

	if( currentClass != "" ) {
		var theEle = gETAC( "div", currentClass, gE("mainNav") );
		removeClass( theEle[0], currentClass );
		addClass( theEle[0], currentClass + "On" );
	}
}

function initSubNav() {
	var navEle = gE("subNav");
	if( navEle ) {
		var currentPath = getCurrentPath();
		var currentPage = getCurrentPage();

		var subNav = new Array();
		subNav["/ca/paypass/mobile/about/"] = "aboutMain";
		subNav["/ca/paypass/mobile/about/contactless_payments.html"] = "aboutContact";
		subNav["/ca/paypass/mobile/about/how_safe.html"] = "aboutHowSafe";
		subNav["/ca/paypass/mobile/about/how_to_tap.html"] = "aboutHow";
		subNav["/ca/paypass/mobile/about/participation_terms.html"] = "aboutTerms";
		subNav["/ca/paypass/mobile/about/trial_sponsers.html"] = "aboutSponsers";
		subNav["/ca/paypass/mobile/about/where_to_use.html"] = "aboutWhere";
		subNav["/ca/paypass/mobile/phone_payments.html"] = "aboutPhonePay";		
		subNav["/ca/paypass/mobile/help/faqs.html"] = "faqMain";
		subNav["/ca/paypass/mobile/help/contact_us.html"] = "contactUs";

		subNav["/ca/personal/en/technologies/paypass/merchant_search.html"] = "paypassLoc";
		
		subNav["/ca/personal/en/general/privacy_policy.html"] = "mastercardPP";
		
		subNav["http://www.citicards.ca/canada/homepage/english/privacy.jsp"] = "citiPP";
		
		subNav["/ca/trademarks.html"] = "websiteTOU";

		subNav["/ca/personal/en/mastercardsecurity/zero_liability.html"] = "nokiaPP";
		
		if( gE( subNav[currentPath + currentPage] ) ){ 
			addClass( gE( subNav[currentPath + currentPage] ), "active" );		
		} else {
			if( gETAC( "div", "paypassLoc", gE("subNav") ) ) {
				addClass( gE( subNav[currentPath] ), "active" )	;
			}
		}
	}
}

function getCurrentPage() {
	
	var currentPage = getFileName( window.location.href );
	var currentPath = window.location.href;
	currentPath = currentPath.substr( 7 );
	currentPath = currentPath.substr( currentPath.indexOf( "/" ) )
	
	// whether or not the page is there
	if( currentPage != "" && hasIndexOf( currentPath, currentPage ) ) {
		currentPath = currentPath.substr( 0, ( currentPath.length - currentPage.length ) );
	}

	if( hasIndexOf( currentPage, "#" ) ) {
		currentPage = currentPage.substr( 0, currentPage.indexOf( "#" ) );
	}

	if( currentPage == "index.html" ) {
		currentPage = "";
	}
	return currentPage;
}

function getCurrentPath() {
	var currentPage = getFileName( window.location.href );
	var currentPath = window.location.href;
	currentPath = currentPath.substr( 7 );
	currentPath = currentPath.substr( currentPath.indexOf( "/" ) )
	
	// whether or not the page is there
	if( currentPage != "" && hasIndexOf( currentPath, currentPage ) ) {
		currentPath = currentPath.substr( 0, ( currentPath.length - currentPage.length ) );
	}

	return( currentPath );
}

function goToPage( flag, tLP ) {
	theLocation = getCurrentPath() + tLP;
	
	if( flag == "page" ) {
		 goToPath = theLocation + ".html";
	} else if( flag == "category" ) {
		goToPath = theLocation + "/";
	}

	window.location.href = goToPath;
}

windowObject.addLoadFunction( initNav, initSubNav );
