//this function creates new image objects for rollovers
function CreateRolloverImages(image_name, off_image_source, on_image_source) {
	//create the new off image
	window[image_name + "_off"] = new Image();
	
	//assign the off image source
	window[image_name + "_off"].src = off_image_source;
	
	//create the new on image
	window[image_name + "_on"] = new Image();
	
	//assign the on image source
	window[image_name + "_on"].src = on_image_source;
}

//this function rolls the image on
function ImageOver(image_name) {
	if (document.images[image_name] && window[image_name + "_on"]) {
		document.images[image_name].src = window[image_name + "_on"].src;
	}
}

//this function rolls the image off
function ImageOut(image_name) {
	if (document.images[image_name] && window[image_name + "_off"]) {
		document.images[image_name].src = window[image_name + "_off"].src;
	}
}

//this shows the left and right nav pipes for the current main section
function SetMainSection(image_name) {
	//set the off image source to the on image source
	if (window[image_name + "_off"] && window[image_name + "_on"]) {
		window[image_name + "_off"].src = window[image_name + "_on"].src;
	}
	
	//roll over the image
	ImageOver(image_name);
	
	//set the main nav carrot for this section if the carrot exists
	//NOTE: it won't exist for utility pages and the home page
	if (document.images[image_name + "_at_carrot"]) {
		document.images[image_name + "_at_carrot"].src = "/images/nav_primary_at_carrot.gif";
	}
}

//this function rolls over the current sub section and keeps it on (active)
function SetSecondarySection(image_name) {
	//set the off image source to the on image source
	if (window[image_name + "_off"] && window[image_name + "_on"]) {
		window[image_name + "_off"].src = window[image_name + "_on"].src;
	}
	
	//roll over the image
	ImageOver(image_name);
}

//this is called to enlarge an image on the home page
function EnlargeImage(image_number) {
	if (document.images["enlarged_image"] && window["view_larger_" + image_number]) {
		document.images["enlarged_image"].src = window["view_larger_" + image_number].src;
	}
}

//this is called to preload the main navigation images
function PreloadMainNavigation() {
	//main sections
	CreateRolloverImages("about", "/images/nav_about_off.gif", "/images/nav_about_on.gif");
	CreateRolloverImages("challenge", "/images/nav_challenge_off.gif", "/images/nav_challenge_on.gif");
	CreateRolloverImages("resources", "/images/nav_resources_off.gif", "/images/nav_resources_on.gif");
	CreateRolloverImages("faq", "/images/nav_faq_off.gif", "/images/nav_faq_on.gif");
	CreateRolloverImages("discussion", "/images/nav_discussion_off.gif", "/images/nav_discussion_on.gif");
	CreateRolloverImages("contact", "/images/nav_contact_off.gif", "/images/nav_contact_on.gif");
	CreateRolloverImages("scratch", "/images/nav_scratch_off.gif", "/images/nav_scratch_on.gif");
	
	//utility sections
	CreateRolloverImages("home", "/images/nav_home_off.gif", "/images/nav_home_on.gif");
	CreateRolloverImages("site_requirements", "/images/nav_site_req_off.gif", "/images/nav_site_req_on.gif");
	CreateRolloverImages("privacy", "/images/nav_privacy_off.gif", "/images/nav_privacy_on.gif");
	CreateRolloverImages("copyright", "/images/nav_copyright_off.gif", "/images/nav_copyright_on.gif");
	CreateRolloverImages("legal", "/images/nav_legal_off.gif", "/images/nav_legal_on.gif");
	CreateRolloverImages("sitemap", "/images/nav_sitemap_off.gif", "/images/nav_sitemap_on.gif");
}

//this is called to preload the secondary navigation images
function PreloadSecondaryNavigation(section_name) {
	switch(section_name) {
		case "about":
			CreateRolloverImages("window_cleaning", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("glass_restoration", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("consultation", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			
			break;
		case "challenge":
			CreateRolloverImages("window_protection", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("window_cleaning", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("glass_quality", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("industry_position", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("next_steps", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			
			break;
		case "resources":
			CreateRolloverImages("articles", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("videos", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("packets", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("waivers", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("links", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("glossary", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			
			break;
		case "faq":
			
			break;
		case "discussion":
			CreateRolloverImages("view_topics", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("add_topic", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("signup", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("edit_profile", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("logout", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("login", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			
			break;
		case "contact":
			
			break;
		case "scratch":
			CreateRolloverImages("available_systems", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("parts_list", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("scratch_faq", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("troubleshooting_tips", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			CreateRolloverImages("companies", "/images/shim.gif", "/images/nav_secondary_at_carrot.gif");
			
			break;
	}
}

//this is called to preload the home thumbnail images
function PreloadHomeThumbnails() {
	//main sections
	CreateRolloverImages("home_1", "/images/home_1_off.jpg", "/images/home_1_on.jpg");
	CreateRolloverImages("home_2", "/images/home_2_off.jpg", "/images/home_2_on.jpg");
	CreateRolloverImages("home_3", "/images/home_3_off.jpg", "/images/home_3_on.jpg");
	CreateRolloverImages("home_4", "/images/home_4_off.jpg", "/images/home_4_on.jpg");
	CreateRolloverImages("home_5", "/images/home_5_off.jpg", "/images/home_5_on.jpg");
	CreateRolloverImages("home_6", "/images/home_6_off.jpg", "/images/home_6_on.jpg");
	CreateRolloverImages("home_7", "/images/home_7_off.jpg", "/images/home_7_on.jpg");
}

//this function creates new image objects for "View Larger" on the home page
function PreloadViewLargerImages() {
	for (var image_number = 1; image_number <= 7; image_number++) {
		//create the new image
		window["view_larger_" + image_number] = new Image();
		
		//assign the image source
		window["view_larger_" + image_number].src = "/images/home_" + image_number + "_large.jpg";
	}
}

//this preloads images needed for the popup window
function PreloadPopupImages() {
	CreateRolloverImages("close_window", "/images/close_window_off.gif", "/images/close_window_on.gif");
}
