/*******************************************************************************
* Project: Servalsoft 2009                                                     *
* File: servalsoft.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 Servalsoft */

////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 updateWebsiteInformation(website) 
{	
	//var callBackURL = normalURL+"our_work/printWebsite.php?website="+website;
	
	//var portfolio = document.getElementById('portfolioInformation');
	//portfolio.innerHTML = '<div style="padding-top: 200px;"><img src="../images/body/activity/spinner.gif" border="0" /></div>';
	
	// Get the current day select
	/*dojo.xhrGet({
		url: callBackURL,
		load: updateWebsiteInformationCallBack,
		error: ajaxError
	});*/
	
	var websiteArray = new Array('itsmyeverything.com', 'm-cubed.com', 'stuffspace.com', 'slatermachine.com', 'drwackys.com', 'trybeta.com', 'rooftechspecialties.com', 'cleanbreak.com', 'specialtycomfortcare.com', 'powersportsrentals.com', 'andpop.com', 'crarental.org');
	var websiteArrayLength = websiteArray.length;
	
	for(var count = 0; count < websiteArrayLength; count++)
	{
		var tempObject = document.getElementById(websiteArray[count]);
		//alert(tempObject);
		tempObject.style.display = 'none';
	}
	
	var tempObject = document.getElementById(website);
	tempObject.style.display = '';
}

function updateWebsiteInformationCallBack(data,ioArgs)
{
	var portfolio = document.getElementById('portfolioInformation');
	portfolio.innerHTML = data;
}

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

////////////////////////////////////////////////////////////////////////////////////////////////////
// Alters the uploaded file information
function updateFileUploaded(uploadID)
{
	//alert("Upload id: "+uploadID);
	
	var callBackURL = normalURL+"contact_us/getFileUploaded.php?uploadID="+uploadID;
	
	// Get the current day select
	dojo.xhrGet({
		url: callBackURL,
		load: updateFileUploadedCallBack,
		error: ajaxError
	});
}

function updateFileUploadedCallBack(data,ioArgs)
{
	var fileAttachmentPadding = document.getElementById('fileAttachmentPadding');
	var existingFiles = fileAttachmentPadding.innerHTML;
	existingFiles += data;
	fileAttachmentPadding.innerHTML = existingFiles;
	
}


