// create a function to pick a random stage based on the start array
function randomStage() {
	if (randomstart == 1) {
		startmode = start[Math.floor(Math.random()*start.length)];
	} else {
		startmode = start[0]; 												
	}
}

// create a function to swap the main image on the stage
function swapImage(filename) {

	// hide the current image
	$("td#stage img").hide();

	// jQuery swap
	$("td#stage img").attr("src",filename).fadeIn(fadeintime);

}

// create a function to set the stage
function setstage(stagename) {

	$("td").hide();													// hide all td tags
	$("td." + stagename).fadeIn("slow");							// show logotype thumbs
	$("td#stage").fadeIn("slow");									// show the stage
	$("div#topnav a").css("color",readycolor);						// reset color of nav links
	$("div#topnav a").css("background-image","none"); 				// remove urhere image from nav links

	$("div#topnav a." + stagename).css("background-image","url('_img/urhere_arrow.png')");
	$("div#topnav a." + stagename).css("color","#fff");				// set color of active gallery link

	$("div#topnav a.contact").css("color",contactcolor);			// set color of contact link

	swapImage("_gallery/" + stagename + "/05.jpg");					// display featured image on entry

}

// create a function to set page as contact form
function setcontact() {

	$("td").hide();													// hide all td tags
	$("td#contact").fadeIn("slow");									// show contact form
	$("div#topnav a").css("color",readycolor);						// reset color of nav links
	$("div#topnav a").css("background-image","none");				// remove all urhere images

	$("div#topnav a.contact").css("background-image","url('_img/urhere_arrow.png')");

	$("div#topnav a.contact").css("color","#fff");					// set color of active gallery link

}

//
// configuration
//

randomstart = 1;													// random start switch
start = ["cgi","logotype","print"];									// array with possible startmodes
randomStage();														// generate random startmode
startimage = "_gallery/" + startmode + "/05.jpg";					// builds path to start image
fadeintime = 500;													// time (ms) image fadein transition
readycolor = "#777";												// hex color for inactive nav links
activecolor = "#FCFCFC";											// hex color for the active nav link
contactcolor = "#FA9265";  											// hex color for the contact nav link

// wait for DOM ready
$(document).ready(function(){

	// setup page based on search string cases
	// from variable "pgset" from url.js
	switch(pgset) {
		case "CONTACT":
			setcontact();
			break;
		
		case "RETRY":
			setcontact();
			break;
		
		case "LOGOTYPE":
			setstage("logotype");
			break;

		case "CGI":
			setstage("cgi");
			break;
			
		case "PRINT":
			setstage("print");
			break;
		
		// if no matches, just setup based on startmode config
		default:
			setstage(startmode);
			break;
	}

	//+							+//
	//+ click events for nav	+//
	//+							+//

	// click event for logotype nav link
	$("div#topnav a.logotype").click(function () { setstage("logotype"); });

	// click event for print nav link
	$("div#topnav a.print").click(function () { setstage("print"); });

	// click event for 3D nav link
	$("div#topnav a.cgi").click(function () { setstage("cgi"); });

	// click event for contact nav link
	$("div#topnav a.contact").click(function () { setcontact();	});

});
