Navi = function() {
 this.naviStack;
 this.naviTimerId;
}

Navi.prototype.init = function(divId){
  this.naviStack = new Array();
  this.pushArray(divId);
}

Navi.prototype.pushArray = function(divId){
 if(divId != null ){
  var arr = divId.split(",");
  for(var i=0; i<arr.length; i++) {
   this.naviStack.push(arr[i]);
  }
 }
}

Navi.prototype.add = function(divId){
 this.naviStack.push(divId);
}

Navi.prototype.del = function(cnt){
 if(cnt){
  for(var index=0; index < cnt; index++) {
   this.naviStack.pop();
  }
 }
}

/*
 * Go Navigation
 */
Navi.prototype.goWithDelay = function(divId, milsecs , refreshYN)
{
	this.go(divId, refreshYN,milsecs);
}

Navi.prototype.go = function(divId,refreshYN,milsecs)
{
	if(!this.naviStack) return; // Unclickable if not initialized

	if(globals.isRunning) return;
	globals.isRunning = true;

	//setScroll(false);

	divOld = document.getElementById(this.naviStack[this.naviStack.length-1]);
	if (divOld) divOld.style.display = "none";
	this.naviStack.push(divId);
	document.getElementById(divId).style.display = "block";
	//resizeWindow(divWidths[divId],divHeights[divId]);
	
	if(milsecs){
		this.naviTimerId = setTimeout(function () { navi.go2(divId, refreshYN); },milsecs);//running timer kill
	}else{
		
		//setScroll(true);
		var initMethod = eval("divInitMethod."+divId);
		globals.isRunning = false;
		if(initMethod !=''){
			eval(initMethod)('GO');
		}		
	}
}

Navi.prototype.go2 = function(divId,refreshYN)
{
	if(this.naviTimerId){
		clearTimeout(this.naviTimerId);
		this.naviTimerId = null;
	}	
		
	//setScroll(true);

	var initMethod = eval("divInitMethod."+divId);
	globals.isRunning = false;
	if(initMethod !=''){
		eval(initMethod)('GO');
	}
}


/*
 * Back Navigation
 */
Navi.prototype.backWithDelay = function(milsecs,refreshYN)
{
	this.back(refreshYN,milsecs);
}

Navi.prototype.back = function(refreshYN,milsecs)
{
	if (globals.isRunning) return;

	globals.isRunning = true;

	//setScroll(false);
		
	var curId = this.naviStack.pop();
	var backId = this.naviStack[this.naviStack.length-1];

	document.getElementById(curId).style.display = "none";	
	//resizeWindow(divWidths[backId],divHeights[backId]);	
	document.getElementById(backId).style.display = "block";
	if(milsecs){
		this.naviTimerId = setTimeout(function () { navi.back2(refreshYN,backId); },milsecs);//running timer kill
	}else{
		//setScroll(true);
		var initMethod = eval("divInitMethod."+backId);
		globals.isRunning = false;
		if(initMethod !=''){
			eval(initMethod)('BACK');
			//resizeMe(backId);
		}		
	}
}

Navi.prototype.back2 = function(refreshYN,backId) 
{
	if(this.naviTimerId){
		clearTimeout(this.naviTimerId);
		this.naviTimerId = null;
	}
		
	//setScroll(true);
	
	var initMethod = eval("divInitMethod."+backId);
	if(initMethod !=''){
		globals.isRunning = false;
		eval(initMethod)('BACK');
		//resizeMe(backId);
	}
}

var navi = new Navi();//go, back