// JavaScript Document
/**
 * @author Warren Krewenki
 * @version $Id$
 * @copyright Virtual Design House, Inc.,  4 June, 2007
 * @package PageBuilderPlus
 **/

/**
 *	Nested Accordian Menu
 *	Requires jQuery 
 *
 **/
 

$(document).ready(function() {
	// Initally, hide all ul's within the menu
	$("#menu").find("ul").hide();
	
	$("#menu a").each(function(){	
			
	//var Hoster = "http://www.airco.com";
	
	var Hoster = "http://" + window.location.hostname;
	
	if ( (Hoster == "http://m.airco.com") //|| (Hoster == "http://airco.appsys.us") 
	) {
	  Hoster = "nobodyDomain";
	}
	
	  //document.write(Hoster)
				//company info
				//var localT = location.href;
				//document.write(localT);	
				
				if( 
					location.href == Hoster + '/fort-worth-heating-air-conditioning-company/' || 
					location.href == Hoster + '/heating-and-air-conditioning-service-areas/' || 
					location.href == Hoster + '/contact-fort-worth-air-conditioning-heating/' || 
					location.href.match(Hoster + '/contact-(.*)-air-conditioning-heating-company/') || 
					location.href == Hoster + '/hvac-jobs-employment-fort-worth-arlington-tx/' || 
					location.href == Hoster + '/best-air-conditioning-heating-company-top-rated-fort-worth/' || 
					location.href == Hoster + '/air-conditioner-sales-fort-worth-air-conditioning-and-heating-sales-fort-worth/' || 
					location.href.match(Hoster + '/air-conditioner-sales-(.*)-air-conditioning-and-heating-sales-(.*)/') ||
					location.href.match(Hoster + '/best-heating-and-air-conditioning-company-(.*)/') 
					
				) {
				  var localT = location.href + '/company-info/';
					
				} 		

				//customer support
				else if( 
						location.href.match(Hoster + '/heating-air-conditioning-system-free-replacement-estimate-(.*)/') || 
						location.href.match(Hoster + '/heating-air-conditioning-system-service-call-(.*)/') || 
						location.href.match(Hoster + '/heating-air-conditioning-system-tune-up-(.*)/') || 
						location.href == Hoster + '/city-inspection-heating-air-conditioning-fort-worth-arlington-tx/' || 
						location.href == Hoster + '/new-construction-warranty-registration-furnace-heat-pump-air-conditioner/' 
					){
				  var localT = location.href + '/customer-support/';
					
				}
				
				
				//products and services
				else if( 
						location.href.match(Hoster + '/trane-dealer-(.*)/') ||
						//trane catch all
						location.href.match(Hoster + '/trane-air-conditioner-(.*)/')  ||
						location.href.match(Hoster + '/trane-heat-pump-(.*)/')  ||
						location.href.match(Hoster + '/trane-gas-furnace-(.*)/')  ||
						//location.href.match(Hoster + '/trane-furnace-(.*)/')  ||
						location.href.match(Hoster + '/trane-air-handler-(.*)/')  ||
						location.href.match(Hoster + '/trane-air-cleaner-(.*)/')  ||
						location.href.match(Hoster + '/trane-thermostat-(.*)/')  ||
						//rheem catch all
						location.href.match(Hoster + '/rheem-air-conditioner-(.*)/')  ||
						location.href.match(Hoster + '/rheem-heat-pump-(.*)/')  ||
						location.href.match(Hoster + '/rheem-furnace-(.*)/')  ||
						location.href.match(Hoster + '/rheem-air-handler-(.*)/')  ||
						location.href.match(Hoster + '/home-air-cleaners-(.*)-rheem/')  ||
						//amana catch all
						location.href.match(Hoster + '/amana-air-conditioner-(.*)/')  ||
						location.href.match(Hoster + '/amana-heat-pump-(.*)/')  ||
						location.href.match(Hoster + '/amana-furnace-(.*)/')  ||
						location.href.match(Hoster + '/amana-air-handler-(.*)/')  ||
						location.href.match(Hoster + '/home-air-cleaners-(.*)-amana/')  ||
						//services
						location.href.match(Hoster + '/air-conditioning-(.*)/') || 
						location.href.match(Hoster + '/heating-(.*)/') || 
						
						location.href.match(Hoster + '/new-air-conditioning-replace-(.*)/') || 
						location.href.match(Hoster + '/new-construction-air-conditioning-system-installation-(.*)/') || 
						
						location.href.match(Hoster + '/new-heating-system-replace-(.*)/') || 
						location.href.match(Hoster + '/new-construction-heating-system-installation-(.*)/') || 
						
						location.href.match(Hoster + '/commercial-heating-system-installation-repair-sales-service-(.*)/') ||
						
						location.href.match(Hoster + '/air-conditioning-heating-discounts-specials-tax-rebates-tax-credits-(.*)/') ||
						
						location.href.match(Hoster + '/trane-air-conditioning-systems-(.*)-trane-heating-systems-(.*)/') ||
						location.href.match(Hoster + '/indoor-air-quality-filtration-solutions-(.*)/')
						
			
					){
				  var localT = location.href + '/products-and-services/';

				} 
				
								//products and services
				else if( 
						location.href.match(Hoster + '/trane-furnace-(.*)/') 
				){
				  var localT = location.href + '/products-and-services/gas-furnace/';

				}
					
				else {
				  var localT = location.href;
				  //document.write(localT);	
				  
				}
								
		//now match link //		
		if(localT.match(this.innerHTML.replace(/ /g,'-').toLowerCase())){
			//console.log($(this).next());
		
			if($(this).next()){
				$(this).next().show();
			}
			if($(this).parent().find("ul").length===0){
				$(this).addClass("active");
				
			}
		}
	});
	
	
	
	// Find all li's with children and apply a class
	$("#menu > li:has(>ul)").addClass("submenu1");
	$("#menu > li > ul > li:has(>ul)").addClass("submenu2");
	$("#menu > li > ul > li > ul > li:has(>ul)").addClass("submenu3");
	$("#menu > li > ul > li > ul > li > ul > li:has(>ul)").addClass("submenu4");

	// Menu functions
	$("#menu > li > a").not($("#menu > li:first > a")).click(function() {
		$("#menu ul:visible").slideUp();
		$(this).parent().find("ul").not($("#menu > li > ul > li > ul")).slideUp();
		$(this).parent().find("ul").not($("#menu li ul li ul")).not($("ul:visible")).slideDown();
	});
	$("#menu > li > ul > li > a").click(function() {
		$("#menu ul li ul:visible").slideUp();										 
		$(this).parent().find("ul").not($("#menu > li > ul > li > ul > li > ul")).slideUp();
		$(this).parent().find("ul").not($("#menu li ul li ul li ul")).not($("ul:visible")).slideDown();
	});
	$("#menu > li > ul > li > ul > li > a").click(function(){
		$("#menu ul li ul li ul:visible").slideUp();													   
		$(this).parent().find("ul").not($("#menu > li > ul > li > ul > li > ul > li > ul")).slideUp();
		$(this).parent().find("ul").not($("#menu li ul li ul li ul li ul")).not($("ul:visible")).slideDown();
	});
	$("#menu > li > ul > li > ul > li > ul > li > a").click(function(){
		$("#menu ul li ul li ul li ul:visible").slideUp();															 
		$(this).parent().find("ul").not($("#menu > li > ul > li > ul > li > ul > li > ul > li > ul")).slideUp();
		$(this).parent().find("ul").not($("#menu li ul li ul li ul li ul li ul")).not($("ul:visible")).slideDown();
	});
});
