﻿//array of header IDs where index = 0 is fixner and index = 5 is smoke free kids
var itemHeaders = new Array("#nav-co-quit-line", "#nav-fixnixer", "#nav-become-an-ex", "#nav-my-last-dip", "#nav-local-resources", "#nav-cigarette-is-dead", "#nav-quit-doing-it", "#nav-smoke-free-kids");
//array of div IDs where index = 0 is fixner and index = 5 is smoke free kids
var itemDivs = new Array("#path-co-quitline", "#path-fixnixer", "#path-become-an-ex", "#path-my-last-dip", "#path-local-resources", "#path-cigarette-is-dead", "#path-quit-doing-it", "#path-smoke-free");
//array of div IDs where index = 0 is fixner and index = 5 is smoke free kids
var itemImages = new Array("#image-co-quit-line", "#image-fixnixer", "#image-become-an-ex", "#image-my-last-dip", "#image-local-resources","#image-cigarette-is-dead", "#image-quit-doing-it", "#image-smoke-free-kids");
		
//holds current index, will start at 0 on page load.
var globalCurrentIndex = 0;
var autoIndex = 1;


$("document").ready(function() {
    //give the flash a second to load otherwise it won't respond
	timer = setTimeout("changeIndex(1, true)", 5000);
});

function changeIndex(index, auto) {
		//alert("changeIndex called");
		
		//check if the item is already selected
		if(index != globalCurrentIndex){
			
			//make sure the index number is within the array
			if(index < 0){
				index = 6;
			}
			if(index > 6){
				index = 0;
			}
			
			//remove class from current index
			$(itemHeaders[globalCurrentIndex]).removeClass("current");
			//add class to new index
			$(itemHeaders[index]).addClass("current");
	
			//hide curent div
			$(itemDivs[globalCurrentIndex]).hide("slow");
			//show new div
			$(itemDivs[index]).show("slow");
			
			//hide curent image
			$(itemImages[globalCurrentIndex]).hide("slow");
			//show new image
			$(itemImages[index]).show("slow");
	
			//update current item
			globalCurrentIndex = index;
			autoIndex = index + 1;
	
			togglePath(index);
			
			//if auto is set to true, set a timer to rotate everthing again, if it's false clear any timer that's already running
			if(auto == true){
				//alert("autoRotate");
				timer = setTimeout("changeIndex(autoIndex, true)", 5000);
			}else{
				//alert("timer " + timer);
				//timer = setTimeout("changeIndex(autoIndex, true)", 5000);
				clearTimeout(timer);
				//clearTimeout(flashTimer);
			}
			
		}
}

// What we might do is change ID to the swapFile URL as shown in saicoSwapImg() @ Line 34
function togglePath(ID) {
    /* Call a function registered as togglePath in the SWF named coverflow. */
  //  alert("togglePath: " + ID)
    getMovieName("coverflow").togglePath(ID);
}
/* This utility function resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}