///////////////////////////////////////////////////////////
//  Constants
//
///////////////////////////////////////////////////////////

BUTTON_DELAY_TIME	= 300;

///////////////////////////////////////////////////////////
//	Image button
//
///////////////////////////////////////////////////////////

//Construction
function ImageButton(strImageID, strUpImage, strDownImage, strHoverImage, strFunction)
{
	objImageEle	= document.images[strImageID];	
	
	
	this.ImageID			= strImageID;		
	this.UpImage			= new Image;		
	this.UpImage.src		= strUpImage;
	this.DownImage			= new Image;		
	this.DownImage.src		= strDownImage;
	this.HoverImage			= new Image;		
	this.HoverImage.src		= strHoverImage;
	this.FuncString			= strFunction;	
	this.isHighlight			= false;	
	this.isButtonEnable		= true;
	this.isLocked			= false;			
	
	
	this.Group			= null;			
	this.HighlightImage	= null;			
	this.DisableImage	= null;			
	
	
	this.setHighlightImage	= ImageButton_setHighlightImage;	
	this.setDisableImage	= ImageButton_setDisableImage;	
	this.toNormal			= ImageButton_toNormal;			
	this.toHighlight			= ImageButton_toHighlight;		
	this.toDisable			= ImageButton_toDisable;		
	
	this.toHover			= ImageButton_toHover;			
	this.toHoverOut			= ImageButton_toHoverOut;		
	this.ActionStart		= ImageButton_ActStart;			
	
	
	objImageEle.src = this.UpImage.src;
}


function ImageButton_setHighlightImage(strHighlightImage,ImgGroup)
{
	this.Group	= ImgGroup;
	this.HighlightImage		= new Image;
	this.HighlightImage.src	= strHighlightImage;
}


function ImageButton_setDisableImage(strDisableImage)
{
	this.DisableImage		= new Image;
	this.DisableImage.src	= strDisableImage;
}


function ImageButton_toNormal()
{
	document.images[this.ImageID].src = this.UpImage.src;
	this.isHighlight		= false;
	this.isButtonEnable	= true;
}


function ImageButton_toHighlight()
{
	if(this.Group){
		var len = this.Group.length;
		for(i=0;i<len;i++){
			if(this.Group[i].isButtonEnable){
				document.images[this.Group[i].ImageID].src = this.Group[i].UpImage.src;
				this.Group[i].isHighlight = false;
			}
		}
	}
	document.images[this.ImageID].src = this.HighlightImage.src;
	this.isHighlight = true;
}


function ImageButton_toDisable()
{
	document.images[this.ImageID].src = this.DisableImage.src;
	this.isButtonEnable	= false;
	this.isHighlight = false;
}


function ImageButton_toHover()
{
	if (this.isButtonEnable && (this.isHighlight == false)) {
		document.images[this.ImageID].src = this.HoverImage.src;
	}
}


function ImageButton_toHoverOut()
{
	if (this.isButtonEnable && (this.isHighlight == false)) {
		document.images[this.ImageID].src = this.UpImage.src;
	}
}


function ImageButton_ActStart()
{
	if(this.isButtonEnable){
		if(this.isLocked){
			return false;
		}
		else{
			this.isLocked = true;
			if(this.Group){
				var len = this.Group.length;
				for(i=0;i<len;i++){
					if(this.Group[i].isButtonEnable){
						this.Group[i].isLocked = true;
						document.images[this.Group[i].ImageID].src = this.Group[i].UpImage.src;
						this.Group[i].isHighlight = false;
					}
				}
			}
			document.images[this.ImageID].src = this.DownImage.src;
			refBuffer = this;
			setTimeout("ImageButton_ActDone(refBuffer)",BUTTON_DELAY_TIME);
			return true;
		}
	}
	else{
		return false;
	}
}

//------------------------------------------------------------------------------------------------



function ImageButton_ActDone(imgBtn)
{
	if(imgBtn.Group){
		document.images[imgBtn.ImageID].src = imgBtn.HighlightImage.src;
		imgBtn.isHighlight = true;
	}
	else{
		document.images[imgBtn.ImageID].src = imgBtn.UpImage.src;
		imgBtn.isHighlight = false;
	}
	eval(imgBtn.FuncString);
	
	if(imgBtn.Group){
		var len = imgBtn.Group.length;
		for(i=0;i<len;i++){
			if(imgBtn.Group[i].isButtonEnable){
				imgBtn.Group[i].isLocked = false;
			}
		}
	}
	imgBtn.isLocked	= false;
}


function CreateImgBtn(strBtnName, strImageID, strUpImage, strDownImage, strHoverImage, strFunction)
{
	var args = "'" + strImageID + "',";
	args = args + "'" + strUpImage + "',";
	args = args + "'" + strDownImage + "',";
	args = args + "'" + strHoverImage + "',";
	args = args + "\"" + strFunction + "\"";
	eval("document." + strBtnName + " = new ImageButton(" + args + ");");
	
	document.images[strImageID].onmouseover = new Function("document." + strBtnName + ".toHover()");
	document.images[strImageID].onmouseout = new Function("document." + strBtnName + ".toHoverOut()");
	document.images[strImageID].onmousedown = new Function("document." + strBtnName + ".ActionStart()");
}


//////////////////////////////////////////////////////////
// ImageButtonGroup 
//
//////////////////////////////////////////////////////////


function CreateImgBtnGroup(strGroupName)
{
	eval("document." + strGroupName +"	= new Array()");
}


function AddImgBtnToGroup(strGroup, strImageButton, strHighlightImage)
{
	
	var objGroup		= eval("document." + strGroup);
	var objImageButton	= eval("document." + strImageButton);
	var count			= objGroup.length;
	objGroup[count]		= objImageButton;
	
	if (null == strHighlightImage || "" == strHighlightImage) {
		objImageButton.setHighlightImage(objImageButton.DownImage.src, objGroup);
	} else {
		objImageButton.setHighlightImage(strHighlightImage, objGroup);
	}
}

