/*******************************************************************************
* Project: Slater Machine & Tool 1.0                                           *
* File: slater.js (JavaScript)                                                 *
* Author: Cody Garvin                                                          *
*                                                                              *
********************************************************************************
* Date: 09/21/09                                                               *
* Version: 0.1                                                                 *
* History:                                                                     *
*  09/21/09 - Initial script created.                                          *
*  Taken from ItsMyEverything.com                                              *
*******************************************************************************/
/* Javascript For EAC */

////////////////////////////////////////////////////////////////////////////////////////////////////
// Returns the last element from a split
function getLastFromSplit(indicator, source)
{
	var splitSource = source.split(indicator);
	var lastItem = splitSource[splitSource.length-1];
	return lastItem;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Preloads all images in the images array
function imagePreloader() 
{
     // counter
     var i = 0;

     // create object
     imageObj = new Image();

     // set image list
     images = new Array();
     images[0] = normalURL+"images/menu/home_over-trans.png";
     images[1] = normalURL+"images/menu/design_process_over-trans.png";
     images[2] = normalURL+"images/menu/services_over-trans.png";
     images[3] = normalURL+"images/menu/equipment_over-trans.png";     
     images[4] = normalURL+"images/menu/contactus_over-trans.png";
     images[5] = normalURL+"images/menu/photo_gallery_over-trans.png";
     images[6] = normalURL+"images/backgrounds/background1.jpg";
     images[7] = normalURL+"images/backgrounds/background2.jpg"
     images[8] = normalURL+"images/backgrounds/background3.jpg";
     images[9] = normalURL+"images/backgrounds/background4.jpg";

     // start preloading
     for(i = 0; i <= (images.length-1); i++) 
     {
          imageObj.src=images[i];
     }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Swaps the menu items to glows
function menuSwapToHover(menuItem) {
	var currentItem = menuItem.id;
	currentItem = currentItem.split("_")[1];
	var splitSource = menuItem.src.split("_");
	var lastItem = splitSource[splitSource.length-1];
	//alert(lastItem);
	if(lastItem == "normal-trans.png")
	{
		lastItem = "over-trans.png";
		splitSource[splitSource.length-1] = lastItem;
		menuItem.src = splitSource.join("_");
	}
	else
	{
		if(currentItem != currentMenu)
		{
			lastItem = "normal-trans.png";
			splitSource[splitSource.length-1] = lastItem;
			menuItem.src = splitSource.join("_");
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Changes the background of the page
function changeBackground(index) 
{	
	document.getElementById('Body').className="background"+index;	
	var callBackURL = normalURL+"setBackground.php?backgroundIndex="+index;
	
	// Get the current day select
	dojo.xhrGet({
		url: callBackURL,
		load: changeBackgroundCallBack,
		error: ajaxError
	});	
}

function changeBackgroundCallBack(data,ioArgs)
{
	//alert('changed');
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Build a basic error handler
function ajaxError(data, ioArgs) 
{
	//alert('Error when retrieving data from the server! -- Comment me out for productions');
	return false;
}