
function gzcookie (document, name, hours, path, domain, secure) {
	this.$document = document;
	this.$name = name;
	if (hours) {
		this.$expiration = new Date((new Date()).getTime( ) + hours*3600000);
	} else {
		this.$expiration = null;
	}
	if (path) this.$path = path; else this.$path = null;
	if (domain) this.$domain = domain; else this.$domain = null;
	if (secure) this.$secure = true; else this.$secure = false;
}


/************* Start Splash Bubble Code ********************/

var max = 0;
var timeout = null;
var splashDivArray = null;
var previousIndex = 0;
var nextIndex = 0;
var currentDOMObject;
var nextDOMObject;
var firstTime=true;
var insertionIndex = 0;
var currentDiv = null;
var nextDiv = null;
var debug = false;
var disabled = false;
var firstMove = true;
var isPlaying = false;
var pauseButton = null;
var playButton = null;
var buttonsvisible = false;

/************* Player Controls ********************/

function gzplay(){
	if(disabled){
		if(debug){
			alert('play called on disabled player');
		}
		return;
	}

	if(firstTime){
		init();
	}else{
		if(isPlaying){
			progressIndices();
		}

		resetDivs();
		showNextDiv();
	}

	divTimeout();

	if(!isPlaying){
		togglePausePlay();
	}
	if(!buttonsvisible){
		gzshowButtons();
	}
}

function gzshowButtons(){
	var buttons = document.getElementById("promo-buttons");
	buttons.style.display="inline";
	buttonsvisible = true;

}

function gzpause(){
	if(disabled){
		if(debug){
			alert('pause called on disabled player');
		}
	return;
	}

	if(timeout != null){
		window.clearTimeout(timeout);
		timeout = null;
		firstMove=true;
		if(isPlaying){
			togglePausePlay();
		}
	}
}

function gzback(){
	if(disabled){
		if(debug){
			alert('back called on disabled player');
		}
		return;
	}

	gzpause();
	regressIndices();
	resetDivs();
	showNextDiv();
}

function gzforward(){
	if(disabled){
		if(debug){
			alert('forward called on disabled player');
		}
		return;
	}

	gzpause();
	progressIndices();
	resetDivs();
	showNextDiv();

}

function init(){
	firstTime=false;
	resetDivs();
	getPausePlayButtons();
}

/**************************** Splash Helper Functions ***************************/
function addSplashDiv(splashDiv){
	splashDivArray[insertionIndex] = splashDiv;
	insertionIndex++;
}

function getPausePlayButtons(){
	pauseButton = document.getElementById("pause");
	playButton = document.getElementById("play");
}

function togglePausePlay(){
	if(!isPlaying){
		pauseButton.style.display="inline";
		playButton.style.display="none";
		isPlaying = true;
	}else{
		playButton.style.display="inline";
		pauseButton.style.display="none";
		isPlaying = false;
	}
}

function progressIndices(){
	previousIndex = nextIndex;
	if((previousIndex + 1) < max){
		nextIndex = previousIndex + 1;
	}else{
		nextIndex = 0;
	}
}

function resetDivs(){
	nextDiv = splashDivArray[nextIndex];
	previousDiv = splashDivArray[previousIndex];
}

function divTimeout(){
	var delay = nextDiv.delay;
	if(isNaN(delay)){
		if(debug){
			alert('delay for timeout is not a number');
		}
		disable();
		return;
	}

	timeout = window.setTimeout("gzplay()",delay);
}

function regressIndices(){
	previousIndex = nextIndex;

	if((previousIndex - 1) >= 0){
		nextIndex = previousIndex - 1;
	}else{
		nextIndex = max -1;
	}
}

function showNextDiv(){
	var previousDivSortOrder = previousDiv.sortOrder;
	var nextDivSortOrder = nextDiv.sortOrder;

	if(isNaN(previousDivSortOrder) || isNaN(nextDivSortOrder)){
		if(debug){
			alert('sort order returned by div is not a number');
		}
		disable();
		return;
  	}

  	previousDOMObject = document.getElementById("container_" + previousDivSortOrder);
  	nextDOMObject = document.getElementById("container_" + nextDivSortOrder);

  	if(previousDOMObject == null || nextDOMObject == null){
  		if(debug){
  			alert('unable to retrieve one of the DOM Objects');
  		}
  		disable();
  		return;
  	}

    previousDOMObject.className = "left offscreen";
    nextDOMObject.className = "left";
}

function disable(){
	disabled = true;
	if(timeout != null){
		window.clearTimeout(timeout);
	}
}

/************************* Helper Object Encapsulates properties for each Div*******************/

function splashDiv(delay,sortOrder){
	var defaultDelay = 3;
	if(delay == "-1"){
		delay = defaultDelay;
	}

	this.delay = delay * 1000;
	this.sortOrder = sortOrder;
}

