﻿/*
swapimage.js
JavaScript functions to swap images on the home page.

2009 Goodman Enterprises, by Shane Goodman
http://www.goodmanEnt.com

Created	September 29, 2008
Revised	September 30, 2008

Function List:
	Image			internal	a template for the array object
	auto_run		external	check which browser the user is running
	fade			internal	Internet Explorer
	refresh			internal	All other browsers

Bugs and Known Issues:
*/
var t;
var i = 1;
var img = new Array();

img[0] = new Image("photos/mcallen_inside.jpg","McAllen Convention Center",187,197);
img[1] = new Image("photos/beach_inside.jpg","Long Beach California",187,197);
img[2] = new Image("photos/spree_inside.jpg","New York Shopping Spree!",187,197);
img[3] = new Image("photos/pepsi_inside.jpg","Pepsi-Cola Promotion",187,197);
img[4] = new Image("photos/fox_inside.jpg","Foxploration",187,197);
img[5] = new Image("photos/projector_inside.jpg","DLP Pocket Projector",187,197);
img[6] = new Image("photos/renaissance_inside.jpg","The Renaissance Grand Hotel",187,197);
img[7] = new Image("photos/art_inside.jpg","Art's Up!",187,197);
img[8] = new Image("photos/squaw_inside.jpg","The Village at Squaw Valley",187,197);
img[9] = new Image("photos/sears_inside.jpg","Sears Tower",187,197);
/*
Caller:	new operator
*/
function Image(inputsrc, inputalt, inputwidth, inputheight) {
	// the 'src' might preload the images
	this.src = inputsrc;
	this.alt = inputalt;
	this.width = inputwidth;
	this.height = inputheight;
}

/*
Caller:	onload() event
calls:	fade or refresh, depending on the browsing
*/
function auto_run() {
	if (document.all) {
		fade();
	}
	else {
		refresh();
	}
}

/*
Caller:	auto_run() function
*/
function fade() {
	var divid = document.getElementById("mydiv");
	var imgid = document.getElementById("imageid");
	var h = (img[9].height - img[i].height) / 2;
	var h = h + "px";

	// freeze the div
	divid.filters(0).Apply();
	// change the image source
	imgid.src = img[i].src;
	imgid.alt = img[i].alt;
	imgid.width = img[i].width;
	imgid.height = img[i].height;
	imgid.style.top = h;
	// invoke the transition
	divid.filters(0).Play();
	i++;
	if (i==10) {
		i = 0;
	}
	divid.onfilterchange = function() {
		t = window.setTimeout("fade()",3000);
	}
}

function refresh() {
	var imgid = document.getElementById("imageid");
	var h = (img[9].height - img[i].height) / 2;
	var h = h + "px";

	// change the image source
	imgid.src = img[i].src;
	imgid.alt = img[i].alt;
	imgid.width = img[i].width;
	imgid.height = img[i].height;
	imgid.style.top = h;
	i++;
	if (i==10) {
		i = 0;
	}
	// wait two seconds
	t = window.setTimeout("refresh()",3000);
}

function pause() {
	clearTimeout(t);
}

function resume() {
	if (document.all) {
		fade();
	}
	else {
		refresh();
	}
}
