// JavaScript Document
	
/*** SHOWCASE FUNCTIONS v1.0 (c) 2009 Allardice Group ---tim[at]allardice(dot)com(dot)au--- ***/

var IV = 0; //Establish Interval variable
var current = 0; //This variable represents the currently active showcase item
var items = new Array("First","Second","Third","Fourth"); // Load ID's of showcase DIV's in to array


function NextItem() { // Skips to next item in the showcase
		
	document.getElementById(items[current]).className = "inactive"; // Change current showcase list item class to "inactive"
	if (current < 3){			//If current item is not the last item in showcase
		current = current + 1;		//Mark next item as the current item 
		} else {		//else (if last item was current) 
			current = 0;		//mark first item as current item
			}//end if else
	document.getElementById(items[current]).className = "active"; // Change new current showcase list item's class to "active"
	} //end NextItem
	
	
function SetAct(Item) { // Set's an item as active on hover and marks all others as inactive
	t = 0;
	while(t < 4) {		// test each showcase item individually until total loops = total items in showcase
		if (items[t] != Item) { // if item is not currently hovered
			document.getElementById(items[t]).className = "inactive"; // change that item's class to inactive
			}
		t = t + 1; // Move to next item on next loop
		}
	document.getElementById(Item).className = "active"; //Set hovered item's class to "active"
	}//end SetAct


function StopShowcase(Item) { //stops automation of showcase
	if (IV != 0) {
		window.clearInterval(IV); //Clear the timer
		}//end if
	}//end StopShowcas


function PlayShowcase() { //Start automation of the showcase
	if (document.getElementById("Showcase")) { // If Automated Showcase Exists on current page
		IV = window.setInterval("NextItem()",10000); // Set a timer to automatically skip to next item every 10 seconds
		}//end if
	}//end PlayShowcase

/*** END SHOWCASE FUNCTIONALITY ***/


/*** GALLERY FUNCTIONS v1.0 (c) 2009 Allardice Group ---tim[at]allardice(dot)com(dot)au--- ***/

function ShowGalImage(atag) { // Show the full size image when the user clicks on a gallery thumbnail
	window.open(atag.href, "GalImage","height=600,width=800"); //Launch popup window containing URL assigned in the thumbnail's <a> tag (eg. The full sized image)
	GalImage.focus(); // Bring the popup window to the front of the screen
	}//end ShowGalImage
	
	
function SetClickHandlers() { // Set's click handlers for all <a> tags contained inside the Gallery

	if (document.getElementById("Gallery")) { // If Gallery Exists on current page
		atags = document.getElementById('Gallery').getElementsByTagName('a');  // Create array of all <a> tags inside the Gallery div
		for(k = 0; k < atags.length; k++) { //for each tag in the array
			atags[k].target="GalImage"; //set window target to popup window (Prevent's link from being opened in main window if the return false command below isn't executed quickly enough
			atags[k].onclick = function (){ShowGalImage(this);return false;}; //set onclick handler to launch ShowGalImage function and cancel link execution of <a> tag itself
			}//end for		
		}//end if		
	}//end SetClickHandlers

/*** END GALLERY FUNCTIONALITY ***/

function InitScripts() { // Initialise scripts to be executed on every page
	
	SetClickHandlers(); //Initialise Gallery
	PlayShowcase();		//Initialise Showcase
	
	}//end InitScripts
