	// Our default page title
	var page_title = "Starks Building Directory | Louisville KY";
	
	function directory_request(id, new_bold){
   		// Turn on our spinner while we do work.
   		spinner(1);
   		
   		// Disable the bold on the old element and turn it on for our newly selected element
   		newBold(document.var_holder.currently_selected_business_id.value, new_bold, 'currently_selected_business_id');
   		
   		// Make our AJAX call
       http( 'get' , '../cfcs/directory.cfc?method=pullBusinessInfo&listingid=' + id , directory_response , id ); 
   }
   
   function directory_response(obj){ 
   	// Populate the DIVs below with this new company's information
   	  update_display(obj.business_name, obj.website, obj.phone, obj.address, obj.floor, obj.description);
   	  
   	  // Update the page title
   	  document.title = obj.business_name + ' | Floor ' + obj.floor + ' | ' + page_title;
   	  
   	  // Update the floor image to match the floor of this item
	  updateFloorImage(obj.floor);
      
      // Turn our spinner off
      spinner(0);
   }
   
   function switch_floor(floor) {
   		// Let's roll our spinner
   		spinner(1);
   		
   	    // Update the page title
    	document.title = page_title;
   		
   		// Update the menu on the left hand side to show our new floor
  		updateFloorImage(floor);
   		
   		// Make this floor bold
   		newBold(document.var_holder.currently_selected_floor.value, 'floor_' + floor, 'currently_selected_floor');
   		
   		// Empty the business display box except display the new floor
   		update_display('', '', '', '', floor, '');
   		
   		// Delete all items in the current list
   		removeChildren(document.getElementById('business_list'));
   		
   		// We must set the currently_bolded item to blank since we have a new set of listings now
   		document.var_holder.currently_selected_business_id.value = '';
   		
   		// Pull our listing of businesses for this floor
        http( 'get' , '../cfcs/directory.cfc?method=listBusinesses&floor=' + floor , switch_floor_response , floor ); 		   		
   }
   
   function switch_floor_response(obj) {
   		// If there's only one result dump that into our search box and also display the details in green below.
   		if (obj['listingid'].length == 1) {
			addLI(obj['listingid'][0], obj['business_name'][0]);
			directory_request(obj['listingid'][0], 'listing_' + obj['listingid'][0])
  		// Loop over our recordset									   			
   		} else if (obj['listingid'].length) {
			for (var rowNum = 0; rowNum < obj['listingid'].length; rowNum++) {
				addLI(obj['listingid'][rowNum], obj['business_name'][rowNum]);						
			} 
   		} else {
   			addLI(0, '<a>No records found. Please try a different criteria.</a>');						
   		}

   		// Turn off our spinner
   		spinner(0);
   }
   
   // Just like switch floor above except it's A-Z
   function switch_az(az) {
   		// Let's roll our spinner
   		spinner(1);
   		
   		// Update the menu on the left hand side to show a blank floor
   		updateFloorImage('0');
   		
   	    // Update the page title
    	document.title = page_title;

   		// Make this AZ bold
   		newBold(document.var_holder.currently_selected_az.value, 'az_' + az, 'currently_selected_az');
   		
   		// Empty the business display box except display the new floor
   		update_display('', '', '', '', '0', '');
   		
   		// Delete all items in the current list
   		removeChildren(document.getElementById('business_list'));
   		
   		// We must set the currently_bolded item to blank since we have a new set of listings now
   		document.var_holder.currently_selected_business_id.value = '';
   		
   		// Pull our listing of businesses for this floor
        http( 'get' , '../cfcs/directory.cfc?method=listBusinesses&floor=' + az , switch_floor_response , az ); 		   		
   }
   
   // Searches businesses for a certain string
   function search(term) {
   		// Let's roll our spinner
   		spinner(1);
   		
   		// Update the menu on the left hand side to show a blank floor
   		updateFloorImage('0');
   		
   		// Unbold AZ and 1-15
   		unBoldAll();
  		
   		// Empty the business display box except display the new floor
   		update_display('', '', '', '', '0', '');
   		
   		// Delete all items in the current list
   		removeChildren(document.getElementById('business_list'));
   		
   		// We must set the currently_bolded item to blank since we have a new set of listings now
   		document.var_holder.currently_selected_business_id.value = '';
   		
   		// Pull our listing of businesses for this floor
        http( 'get' , '../cfcs/directory.cfc?method=listBusinesses&floor=' + term , switch_floor_response , term ); 
   		
   }
   
   // Either turns on or off the spinner logo
   function spinner(status){
   		// Turn spinner on
   		if (status) {
			document.getElementById('ajax_spinner_115').style.display = 'block';
			document.getElementById('ajax_spinner_az').style.display = 'block';
   		// Turn it off
   		} else {
			document.getElementById('ajax_spinner_115').style.display = 'none';
			document.getElementById('ajax_spinner_az').style.display = 'none';
   		}
   }
   
	function addLI(listingid, bname){
		var Parent = document.getElementById('business_list');
		var newLI = document.createElement("LI");
		
		// Assign this new entry a valid ID so that we can reference it later
		newLI.setAttribute('id','listing_' + listingid);
		
		// Content of the new value (only display a full link if it has a valid listingid
		if (listingid != 0) {
			newLI.innerHTML = "<a href='javascript:void(0)' onclick=\"directory_request('" + listingid + "', 'listing_" + listingid + "')\">" + bname + "</a>";
		} else {
			newLI.innerHTML = "<a\">" + bname + "</a>";
		}

		// Add it to our list
		Parent.appendChild(newLI);
	}
	
	// Function that removes elements from our list		
	function removeChildren(s)
	{
		while (s.hasChildNodes()) {
			s.removeChild(s.childNodes[0]);
		}
	}
	
	// Turns off the bold on an old item and turns it back on for a new item
	function newBold(cur, new_bold, var_store) {
   		current_bold = cur;
   		
   		if (current_bold.length) {
	   		document.getElementById(current_bold).style.fontWeight='400';
   		}
   		
   		// Enable bold on this element
   		document.getElementById(new_bold).style.fontWeight='800';
   		
   		// Make note of the new bolded id
   		document.getElementById(var_store).value = new_bold;
	}
	
	// Updates the green display box
	function update_display(name, url, phone, addr, fl, desc) {
	      // If we have a blank name, we need to enter intro text so that someone knows what to do
	      if (name.length == 0) {
			  document.getElementById('name').innerHTML = 'Please select a business above.';	
		      document.getElementById('city').innerHTML = '';	
	      } else {
			  document.getElementById('name').innerHTML = name;
			  document.getElementById('city').innerHTML = 'Louisville, KY 40202';							  
	      }
	      document.getElementById('url').innerHTML = url;
	      document.getElementById('addy').innerHTML = phone;
	      document.getElementById('st').innerHTML = addr;
	      document.getElementById('fnum').innerHTML = fl;
	      document.getElementById('green_sr_desc').innerHTML = desc;
	}
	
   // Turns AZ or floors 1-15 to visible
   function turnOnAZ(yesno){
   		// Turn AZ on 
   		if (yesno) {
			document.getElementById('az_1-15_selector').style.display = 'none';
			document.getElementById('az_selector').style.display = 'block';
   			
   			// Turn on AZ background image
   			document.getElementById('az_1-15_button').style.backgroundImage = "url(../images/1_15.jpg)";
   			
   		// Turn it off
   		} else {
			document.getElementById('az_1-15_selector').style.display = 'block';
			document.getElementById('az_selector').style.display = 'none';
			
			// Turn on 1-15 background image
   			document.getElementById('az_1-15_button').style.backgroundImage = "url(../images/A_Z.jpg)";
   		}
   }
   
   // Updates the image on the left side to be of a certain floor
   function updateFloorImage(floor) {
   		if (isNaN(floor) == false) {
	   		document.getElementById('content_leftd').style.backgroundImage  = "url(../images/content_left" + floor + "_bg.jpg)";
   		}
   	}
   	
   // Unbold AZ and 1-15
   function unBoldAll() {
   	var cur_az = document.var_holder.currently_selected_az.value;
   	var cur_115 = document.var_holder.currently_selected_floor.value;
   	
	if (cur_az.length) {
   		document.getElementById(cur_az).style.fontWeight='400';
	}
	
	if (cur_115.length) {
   		document.getElementById(cur_115).style.fontWeight='400';
	}
   	
   }
   	