

// -------------------------------------------------------------------------------------------------------------------
// Randomly displays a different "Featured Project" (based on one of Dawson's specialization's) every time the User 
// navigates to the home page. The corresponding specialization is highighted as well to the left.


// Create a "record" for each category's featured project, including project title, image URL, and URL to the project page in the Portfolio section
// Project images are already named according to the Project ID numbers

var project_1 =  { title: "Academic Instructional Center, WWU",imageURL: "/images/home/specializeImg_1.jpg", projectURL: "/projects/index.php?CategoryID=2&ID=63" };
var project_2 =  { title: "The Laurel Building", imageURL: "/images/home/specializeImg_2.jpg", projectURL: "/projects/index.php?CategoryID=3&ID=70" };
var project_3 =  { title: "Denali Eielson Visitor Center", imageURL: "/images/home/specializeImg_3.jpg", projectURL: "/projects/index.php?CategoryID=4&ID=10" };
var project_4 =  { title: "Central Peninsula General Hospital", imageURL: "/images/home/specializeImg_4.jpg", projectURL: "/projects/index.php?CategoryID=5&ID=55" };
var project_5 =  { title: "Laube Hotel", imageURL: "/images/home/specializeImg_5.jpg", projectURL: "/projects/index.php?CategoryID=6&ID=69" };
var project_6 =  { title: "Mt. Baker Theatre Renovations Phase II", imageURL: "/images/home/specializeImg_6.jpg", projectURL: "/projects/index.php?CategoryID=7&ID=93" };
var project_7 =  { title: "WoodStone", imageURL: "/images/home/specializeImg_7.jpg", projectURL: "/projects/index.php?CategoryID=8&ID=6" };
var project_8 =  { title: "Douglas Harbor Uplands And Moorage Expansion Phase III", imageURL: "/images/home/specializeImg_8.jpg", projectURL: "/projects/index.php?CategoryID=9&ID=85" };
var project_9 =  { title: "Chuckanut Residence", imageURL: "/images/home/specializeImg_9.jpg", projectURL: "/projects/index.php?CategoryID=10&ID=90" };
var project_10 = { title: "Ketchikan General Hospital - Emergency Cladding and Window Repairs", imageURL: "/images/home/specializeImg_10.jpg", projectURL: "/projects/index.php?CategoryID=11&ID=36" };
var project_11 = { title: "Port Townsend City Hall Improvements and Annex Addition", imageURL: "/images/home/specializeImg_11.jpg", projectURL: "/projects/index.php?CategoryID=12&ID=43" };


// Number of total projects/specializations (see above) that might be displayed on page load.
var totalProjects = 11;

// Generate the random ID number of the project to be displayed on this page load
var now = new Date();
var projectID = Math.round(totalProjects * Math.cos(now.getTime()));
if (projectID < 0) projectID = - projectID; if (projectID == 0) projectID++;


// Assemble and output HTML for the Featured Project content 
function insertProject() {
		
	// Use the random ID mumber to write out the HTML necessary to display project image, project title (caption), and the URL to jump to Project Detail page
	document.write( "<DIV ID=\"imageBlock\">" );
	document.write( "<IMG SRC=\"" + eval("project_" + projectID + ".imageURL") + "\" ID=\"mainImg\">");
	document.write( "<DIV ID=\"caption\">" + eval("project_" + projectID + ".title") + "</DIV>");
	document.write( "<DIV ID=\"projectLink\">|&nbsp;&nbsp;<A HREF=\"" + eval("project_" + projectID + ".projectURL") + "\">view project</A> &nbsp;<IMG SRC=\"/images/shared/greenArrow.gif\" WIDTH=\"5\" HEIGHT=\"7\"></DIV>");
	document.write( "</DIV>");
}







// -------------------------------------------------------------------------------------------------------------------
// Preloads and manages rollovers for all "Specialization Text" subnav items 


function preloadSpecTxt() {
	if (document.images) {
			if (typeof(document.specTxt) == 'undefined'){
      document.specTxt = new Object();
    	}
    	document.specTxt.loadedImages = new Array();
    	document.specTxt.loadedImages[0] = new Image();
    	document.specTxt.loadedImages[0].src = '/images/home/specializeText_1_over.gif';
    	document.specTxt.loadedImages[1] = new Image();
    	document.specTxt.loadedImages[1].src = '/images/home/specializeText_2_over.gif';
    	document.specTxt.loadedImages[2] = new Image();
    	document.specTxt.loadedImages[2].src = '/images/home/specializeText_3_over.gif';
    	document.specTxt.loadedImages[3] = new Image();
    	document.specTxt.loadedImages[3].src = '/images/home/specializeText_4_over.gif';
		document.specTxt.loadedImages[4] = new Image();
    	document.specTxt.loadedImages[4].src = '/images/home/specializeText_5_over.gif';
		document.specTxt.loadedImages[5] = new Image();
    	document.specTxt.loadedImages[5].src = '/images/home/specializeText_6_over.gif';
		document.specTxt.loadedImages[6] = new Image();
    	document.specTxt.loadedImages[6].src = '/images/home/specializeText_7_over.gif';
		document.specTxt.loadedImages[7] = new Image();
    	document.specTxt.loadedImages[7].src = '/images/home/specializeText_8_over.gif';
		document.specTxt.loadedImages[8] = new Image();
    	document.specTxt.loadedImages[8].src = '/images/home/specializeText_9_over.gif';
		document.specTxt.loadedImages[9] = new Image();
    	document.specTxt.loadedImages[9].src = '/images/home/specializeText_10_over.gif';
	}	
}


// This function is called on page load after the page builds on. It checks to see what the randomly selected
// specialization/featured project is and updates the "Specialization Text" subnav to indicate this.

function updateSpecTxt (currentSpec) {
	var currentSpec_img = '/images/home/specializeText_' + currentSpec + '_on.gif';
	document.getElementById('nav_' + currentSpec).src = currentSpec_img;	
}


// This function swaps "Specialization Text" images when user rolls over them

function swapSpecTxt ( currentSpec, swapSpecTxt) {
		// If User is not mousing over the "Specialization Text" Button for the randomly selected specialization/featured project,
		// swap the "off state" for the "on state" of the "Specialization Text" Button that the User is mousing over.
		if (swapSpecTxt != currentSpec) {
				var swapSpecTxt_img = '/images/home/specializeText_' + swapSpecTxt + '_over.gif'
				document.getElementById('specText_' + swapSpecTxt).src = swapSpecTxt_img;	
			}
 }
 
 
// This function swaps "Specialization Text" images back when user rolls back out

function swapSpecTxtBack ( currentSpec, swapBackSpecTxt) {
		
		// If User is not mousing out of the "Specialization Text" Button for the randomly selected specialization/featured project,
		// swap the "on state" back to the "off state" of the "Specialization Text" Button that the User is mousing out of.
		if (swapBackSpecTxt != currentSpec) {
				var swapBackSpecTxt_img = '/images/home/specializeText_' + swapBackSpecTxt + '_off.gif';
				document.getElementById('specText_' + swapBackSpecTxt).src = swapBackSpecTxt_img;
			}
}



// Use the random ID mumber to write out the HTML necessary to display the specialization list
function insertSpecialization() {	
	
	// Insert headline
	document.write( "<h1><img src=\"images/home/h_specialization.gif\" alt=\"SPECIALIZING IN:\" width=\"137\" height=\"11\"></h1>" );
	// Begin list
	document.write( "<ul>" );

	for ( counter = 1; counter <= totalProjects; counter++) {
		// Adjust for category numbering in the databases
		categoryID = (counter +1);
		// Set the image state for this round. If the image in this round matches the current randomly selected spec/featured project, set the image to "on" state 
		imgState = "off";
		if (counter == projectID) {
			imgState = "on";
		}		
		
		document.write( "<li><a href=\"/projects/index.php?CategoryID=" + categoryID + "\" onMouseOver=\"swapSpecTxt(projectID, '" + counter + "')\" onMouseOut=\"swapSpecTxtBack(projectID, '" + counter + "')\"><img src=\"images/home/specializeText_" + counter + "_" + imgState + ".gif\" name=\"specText_" + counter + " border=\"0\" id=\"specText_" + counter + "\"></a></li>" );

	}
	
	// End list
	document.write( "</ul>" );
	
}








// -------------------------------------------------------------------------------------------------------------------
// Randomly displays a different Testimonial every time the user navigates to the home page.


// Number of total testimonials that might be displayed on page load.
// Has to be kept under 10 Testimonials
var totalTestimonials = 3;
	

function insertTestimonial() {
	// Generate the random ID number of the testimonial to be displayed on this page load
	var now = new Date();
	var testimonialID = Math.round(totalTestimonials * Math.cos(now.getTime()));
	if (testimonialID < 0) testimonialID = - testimonialID; if (testimonialID == 0) testimonialID++;
		
	// Use the random ID mumber to write out the HTML necessary to display testimonial image
	document.write( "<DIV ID=\"testimonial\"><IMG SRC=\"/images/home/testimonial_0" + testimonialID + ".gif\"></DIV>");

}




// -------------------------------------------------------------------------------------------------------------------
// Called at the bottom of the home page along with the global pageInit() script, handles specific home page initialization after document loads

function pageInit_home() {
	// preload rollover images for "Specialization Text"
	preloadSpecTxt();	
}