// By Luke Barton
// http://www.lukebarton.com
// luke@lukebarton.com

// Set default window.status
window.status = "Hamilton State Bank";
window.defaultStatus = "Hamilton State Bank";


// Header images are randomly selected (per section) through this 2D array
// The first dimension is an associative array mapping to the page
// The second dimension is an indexed array with the image name
var img_arr = new Array()

img_arr["home"] = new Array ("01_ah_01.gif", "01_ah_02.gif", "01_ah_03.gif", "01_ah_04.gif");

img_arr["personal_banking/"] = new Array ("02_hs_01.gif", "02_hs_02.gif", "02_hs_03.gif", "02_hs_04.gif");
img_arr["personal_banking/checking.htm"] = img_arr["personal_banking/"];
img_arr["personal_banking/checking_comparison.htm"] = img_arr["personal_banking/"];
img_arr["personal_banking/savings.htm"] = img_arr["personal_banking/"];
img_arr["personal_banking/loans_lines_of_credit.htm"] = new Array ("03_hd_01.gif", "03_hd_02.gif", "03_hd_03.gif");
img_arr["personal_banking/investing.htm"] = new Array ("04_mt_01.gif", "04_mt_02.gif", "04_mt_03.gif", "04_mt_04.gif");
img_arr["personal_banking/fee_schedule.htm"] = img_arr["personal_banking/"];
img_arr["personal_banking/star_club.htm"] = img_arr["personal_banking/"];

img_arr["business_banking/"] = new Array ("05_pm_01.gif", "05_pm_02.gif", "05_pm_03.gif");
img_arr["business_banking/checking.htm"] = img_arr["business_banking/"];
img_arr["business_banking/checking_comparison.htm"] = img_arr["business_banking/"]; 
img_arr["business_banking/investing.htm"] = img_arr["business_banking/"]; 
img_arr["business_banking/fee_schedule.htm"] = img_arr["business_banking/"];

img_arr["online_banking/"] = img_arr["home"];
img_arr["online_banking/security_policy.htm"] = img_arr["online_banking/"];
img_arr["online_banking/internet_security_measures.htm"] = img_arr["online_banking/"];
img_arr["online_banking/secure_browsing.htm"] = img_arr["online_banking/"];
img_arr["online_banking/terms.htm"] = img_arr["online_banking/"];

img_arr["about_us/"] = img_arr["home"];
img_arr["about_us/executive_officers.htm"] = img_arr["about_us/"];
img_arr["about_us/news.htm"] = img_arr["about_us/"];
img_arr["about_us/locations.htm"] = img_arr["about_us/"];
img_arr["about_us/contact_us.htm"] = img_arr["about_us/"];
img_arr["about_us/privacy_policy.htm"] = img_arr["about_us/"];

img_arr["calculators/loan_calculator.htm"] = img_arr["personal_banking/investing.htm"];
img_arr["calculators/mortgage_calculator.htm"] = img_arr["calculators/loan_calculator.htm"];
img_arr["calculators/investment_calculator.htm"] = img_arr["calculators/loan_calculator.htm"];
img_arr["calculators/retirement_calculator.htm"] = img_arr["calculators/loan_calculator.htm"];



// Alt tag array
// This array maps to the img_arr and provides randomly-selected alt tags for the header images
var alt_arr = new Array();

alt_arr["home"] = new Array (
							"Hamilton State Bank  Where Wall Street meets Main Street.", 
							"Hamilton State Bank brings you the services you need with the service you've earned.", 
							"Hamilton State Bank  When you bank with us, you bank with people who know you in the community.", 
							"Hamilton State Bank  We promise state-of-the-art banking and a handshake.");
							
alt_arr["about_us/privacy_policy.htm"] = alt_arr["home"];


alt_arr["personal_banking/"] = new Array (
							alt_arr["home"][1], 
							alt_arr["home"][2],
							"Hamilton State Bank  We bring you the experience of a big bank, without the 'experience' of a big bank.", 
							"Hamilton State Bank  We bring 100 years of big banking know how to you.");
							
alt_arr["personal_banking/checking.htm"] = alt_arr["personal_banking/"];
alt_arr["personal_banking/checking_comparison.htm"] = alt_arr["personal_banking/"];
alt_arr["personal_banking/savings.htm"] = alt_arr["personal_banking/"];

alt_arr["personal_banking/loans_lines_of_credit.htm"] = new Array (
							alt_arr["personal_banking/"][2], 
							"Hamilton State Bank  When you talk to your banker, you are talking to the bank.", 
							"Hamilton State Bank  We know your time is valuable so we make banking with us easy.");

alt_arr["personal_banking/investing.htm"] = new Array (
							alt_arr["personal_banking/loans_lines_of_credit.htm"][1],
							alt_arr["personal_banking/loans_lines_of_credit.htm"][2],
							"Hamilton State Bank  We are not successful if we can't help you meet your goals.",
							"Hamilton State Bank  You're a name not a number.");
							
alt_arr["personal_banking/fee_schedule.htm"] = alt_arr["personal_banking/"];							

alt_arr["personal_banking/star_club.htm"] = alt_arr["personal_banking/"];

alt_arr["business_banking/"] = new Array (
							alt_arr["personal_banking/investing.htm"][2],
							alt_arr["personal_banking/investing.htm"][3],
							alt_arr["personal_banking/"][3], 
							alt_arr["home"][3]);

alt_arr["business_banking/checking.htm"] = alt_arr["business_banking/"];
alt_arr["business_banking/checking_comparison.htm"] = alt_arr["business_banking/"]; 
alt_arr["business_banking/investing.htm"] = alt_arr["business_banking/"];
alt_arr["business_banking/fee_schedule.htm"] = alt_arr["business_banking/"];

alt_arr["online_banking/"] = alt_arr["home"];
alt_arr["online_banking/security_policy.htm"] = alt_arr["online_banking/"];
alt_arr["online_banking/internet_security_measures.htm"] = alt_arr["online_banking/"];
alt_arr["online_banking/secure_browsing.htm"] = alt_arr["online_banking/"];
alt_arr["online_banking/terms.htm"] = alt_arr["online_banking/"];						

alt_arr["about_us/"] = alt_arr["home"];
alt_arr["about_us/executive_officers.htm"] = alt_arr["about_us/"];
alt_arr["about_us/news.htm"] = alt_arr["about_us/"];
alt_arr["about_us/locations.htm"] = alt_arr["about_us/"];
alt_arr["about_us/contact_us.htm"] = alt_arr["about_us/"];
alt_arr["about_us/privacy_policy.htm"] = alt_arr["about_us/"];

alt_arr["calculators/loan_calculator.htm"] = alt_arr["personal_banking/investing.htm"];
alt_arr["calculators/mortgage_calculator.htm"] = alt_arr["calculators/loan_calculator.htm"];
alt_arr["calculators/investment_calculator.htm"] = alt_arr["calculators/loan_calculator.htm"];
alt_arr["calculators/retirement_calculator.htm"] = alt_arr["calculators/loan_calculator.htm"];


// Set defaults
var img_rand  = 1;
var img_path = "/_img/headers/";
var img_selected = img_path + img_arr["home"][1];

// Splice the document.location string

var current_url = new String (document.location);


// Get a random number between lo and hi
function rand_val(lo, hi)
{
	do {rand_num = Math.round(Math.random(1)*10);}
	while (rand_num < lo || rand_num > hi);
	return rand_num
}


// Splice the URL to get the array reference
// Check if do_img == true so that added pages don't break the system 
if (do_img == true)
{
	// Set default string offset for slicing up url string
	var string_offset = 5;
	
	// Set current page per slice string (".com/") and string_offset	
	var current_page = current_url.slice(current_url.lastIndexOf(".com/") + string_offset, current_url.length);
	
	// Adjust for homepage
	if (current_page == "" || current_page == "default.htm") current_page = "home";

	img_rand = rand_val(0, img_arr[current_page].length-1);
	img_selected = img_path + img_arr[current_page][img_rand];
}


// Image preload array is a concatenation of 5 image arrays from above
var img_preload_arr = new Array();
img_preload_arr = img_preload_arr.concat(	img_arr["home"],
					 					 	img_arr["personal_banking/"],  
											img_arr["personal_banking/"], 
											img_arr["personal_banking/loans_lines_of_credit.htm"],
											img_arr["personal_banking/investing.htm"],
											img_arr["business_banking/"]);

// This array will store the actual images											
var img_arr = new Array();

			
// Image preloader
function image_preload()
{
	// BRUTE FORCE PRELOADER: THIS IS NOT A SMART LOOP
	// THIS IS NOT THAT BAD BECAUSE THE EARLY IMAGES GET USED THE MOST
	
	// HACK: THIS MIGHT BE CAUSING A PROBLEM ON MAC OS 9 SO IT HAS BEEN REMOVED
	var agt     = navigator.userAgent.toLowerCase();
	var is_mac  = (agt.indexOf("mac") != -1);
	var is_mac10= (is_mac && ((agt.indexOf("os x") != -1) || (agt.indexOf("osx") != -1)));
	var is_mac9 = (is_mac && !is_mac10);	

	if (!is_mac9)
	{
		for (var i = 0; i < img_preload_arr.length; i++) 
		{
			img_arr[i] = new Image(); 
			img_arr[i].src = img_path + img_preload_arr[i];
		}
	}
	
	// Reset default window.status
	window.status = "Hamilton State Bank";
	window.defaultStatus = "Hamilton State Bank";
}					


// Drop down navigation code
function do_nav(item)
{
	if (item.value == "personal") {window.location.href = "https://www.ebankhost.net/hamilton/";}
	else if (item.value == "business") {window.location.href = "https://www.ebankhost.net/hamilton/ecorp/";}
	else if (item.value == "first") {window.location.href = "https://www.ebankhost.net/hamilton/ftu/";}
}

