//these are the images that the user will be able to scroll through.
var imgs = new Array("images/mainimg/mainimg1.png", 
					 "images/mainimg/mainimg2.jpg", 
					 "images/mainimg/mainimg3.png");
//these are the bigger texts that will appear when a user scrolls through them.  They are in HTML,
//and they correspond with the 'imgs' array.
var bigTexts = new Array("<a href='http://site.cimasg.com/rightstor-1' class='banhead'>RightStor</a>",
						 "<a href='http://site.cimasg.com/business-continuity' class='banhead'>Resiliency</a>",
						 "<a href='http://site.cimasg.com/clouds' class='banhead'>Cloud Computing</a>");
//these are like bigTexts, but it's the italics part instead.  Note that 'ʺ' is not the same as '"'.
var littleTexts = new Array("ʺ...It’s about knowing the most efficient and cost effective place to put your data...ʺ",
							"ʺ...The best way to recover from an IT outage is to avoid having one in the first place...ʺ",
							"ʺ...It’s time to get out of the server business and get in to the service business...ʺ");

//this is the current index of the scrollable images.
var imgIndex = 0;
//the interval ID of the slide show.
var intervalID;

/**
 * Begins a slide show of the images.
 */
function beginSlideShow() {
	intervalID = setInterval("slideRight()", 10000);
}

/**
 * Causes the main area to scroll to the previous image.
 * If there is a slide show happening, then this stops the slide show.
 */ 
function leftArrow() {
	clearInterval(intervalID);
	imgIndex--;
	if (imgIndex < 0) {
		imgIndex = imgs.length - 1;
	}
	setMainImage();
}

/**
 * Preloads the main images for scrolling.
 */
function preloadMainImages() {
	for (var i = 0; i < imgs.length; i++) {
		var img = new Image(958, 508);
		img.src = imgs[i];
	}
	//set the main image just for fun.
	setMainImage();
}
 
/**
 * Causes the user to be signed up for the mailing list.
 */
function newslettersignup() {
	var email = document.getElementById("txtEmailSignup").value;
	var paramarray = new Array();
	paramarray["address"] = email;
	var response = cajax.GetText("php/mailinglistcb.php", paramarray);
	switch (response) {
		case "noemail":
			alert("You must provide your email address.");
			break;
		case "invalidemail":
			alert("The email address you provided was not valid.  Please provide an emal address.");
			break;
		case "no":
			alert("We're sorry, but there was an error signing you up for the mailing list.  If this happens repeatedly, please call us so we can serve you better.");
			break;
		case "yes":
			alert("Thank you for signing up for the mailing list!  We appreciate your interest.");
			document.getElementById("txtEmailSignup").value = "";
			break;
		default:
			alert("There was an unknown error.  Sorry for the inconvenience.");
			break;
	}
}

/**
 * Links to their facebook account.
 */
function fbButton() {
	window.location = "http://www.facebook.com/pages/Dallas-TX/Cima-Solutions-Group/125167377537333";
}

/**
 * Causes the main area to scroll to the next image.
 * If there is a slide show happening, then this stops the slide show.
 */
function rightArrow() {
	clearInterval(intervalID);
	slideRight();
}

/**
 * Sets the main image based upon the current image index.
 */
function setMainImage() {
	document.getElementById("mainimage").style.backgroundImage = 'url(' + imgs[imgIndex] + ')';
	document.getElementById("transbluebigtext").innerHTML = bigTexts[imgIndex];
	document.getElementById("transbluelittletext").innerHTML = littleTexts[imgIndex];
}

/**
 * Slides right.
 */
function slideRight() {
	imgIndex++;
	if (imgIndex > imgs.length - 1) {
		imgIndex = 0;
	}
	setMainImage();
}

/**
 * Links to their twitter account.
 */
function twButton() {
	window.location = "http://twitter.com/cimasg";
}

preloadMainImages();
beginSlideShow();
