var chgImage = true;
var MouseInCnt = 1;
var imgPath = "images/";
var mainImgs = new Array(
						imgPath + "error.gif",
						imgPath + "mainImg.jpg",
						imgPath + "mainImg_2.jpg",
						imgPath + "mainImg_3.jpg",
						imgPath + "mainImg_4.jpg",
						imgPath + "mainImg_5.jpg"
						);
var mImageCnt = mainImgs.length - 1;
var chuckImgs = new Array(
						imgPath + "error.gif",
						imgPath + "CIB.std.jpg",
						imgPath + "CIB.trd14.jpg",
						imgPath + "CIB.trd12.jpg",
						imgPath + "CIB.trd34.jpg",
						imgPath + "CIB.trdful.jpg",
						imgPath + "CIB.marble.jpg",
						imgPath + "CIB.pipe.jpg",
						imgPath + "CIB.steel.jpg",
						imgPath + "CIB.chiprock.jpg",
						imgPath + "CIB.rustcreep.jpg",
						imgPath + "CIB.rustplate.jpg",
						imgPath + "CIB.woodpan.jpg",
						imgPath + "CIB.woodgrain.jpg"
						);
var ImageCnt = chuckImgs.length - 1;

/*
 * Change Image on mouse entry to something in the image list.
 */
function mouseImage(treadonly)
{
	if (document.images)
	{	
//alert ("Count: " + imageCnt);
		MouseInCnt++;
		if (treadonly)
			ImageCnt = 5;
		else
			ImageCnt = chuckImgs.length - 1;
		
		if (MouseInCnt > ImageCnt)
			MouseInCnt = 1;
		document.chucksbox.src = chuckImgs[MouseInCnt];
	}
}

/* Sonoran Creative promo */
function scpopup()
{
	promoWin = window.open('scpopup.html', 'SonoranCreative', 'width=250, height=400,left=250,top=250');
	promoWin.focus();
}

/* This function will set a cookie and check it every time the page is displayed.
 * If "timeDelay" has lapsed (in minutes) it will be OK to chg the main image.
 */
function ckImageChg(timeDelay)
{
	var now = new Date;
	var expireTime = (1000 * 60 * timeDelay); // minutes converted to milliseconds.
	expireDate = new Date;
	expireDate.setHours(expireDate.getHours()+24);
	dateStr = expireDate.toUTCString()

	// Get the current cookie value 
	//
	var lastVisit = new Date(cookieVal("pageVisit"));
	if (now.getTime() > (lastVisit.getTime() + expireTime))
		chgImage = true;
	else
		chgImage = false;

	// Update the current cookie (write it back to disk).
	//
	document.cookie = "pageVisit=" + now + "; expires=" + dateStr;
	return;
}

function cookieVal(cookieName)
{
	thisCookie = document.cookie.split("; ")
	for (i=0; i < thisCookie.length; i++)
	{
		if (cookieName == thisCookie[i].split("=")[0])
		{
			return (thisCookie[i].split("=")[1]);
		}
	}
	return ("1 January 1970");
}

function randomMainImage()
{
	if (document.images)
	{
		// check cookie so that the image doesn't change each day? Store random image name in cookie?
		randomNumber = Math.floor((Math.random() * mImageCnt));
		document.mainImg.src = mainImgs[randomNumber + 1];
	}
}