///////////////////////////////////////////////////////////
//  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.isButtonEnable		= true;				
	this.isLocked			= false;			
	
	
	this.Group			= null;			
	this.HilightImage	= null;			
	this.DisableImage	= null;			
	
	
	this.setHilightImage	= ImageButton_setHilightImage;	
	this.setDisableImage	= ImageButton_setDisableImage;	
	this.toNormal			= ImageButton_toNormal;			
	this.toHilight			= ImageButton_toHilight;		
	this.toDisable			= ImageButton_toDisable;		
	
	this.toHover			= ImageButton_toHover;			
	this.toHoverOut			= ImageButton_toHoverOut;		
	this.ActionStart		= ImageButton_ActStart;			
	
	
	objImageEle.src = this.UpImage.src;
}


function ImageButton_setHilightImage(strHilightImage,ImgGroup)
{
	this.Group	= ImgGroup;
	this.HilightImage		= new Image;
	this.HilightImage.src	= strHilightImage;
}


function ImageButton_setDisableImage(strDisableImage)
{
	this.DisableImage		= new Image;
	this.DisableImage.src	= strDisableImage;
}


function ImageButton_toNormal()
{
	document.images[this.ImageID].src = this.UpImage.src;
	this.isButtonEnable	= true;
}


function ImageButton_toHilight()
{
	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;
			}
		}
	}
	document.images[this.ImageID].src = this.HilightImage.src;
	this.isButtonEnable	= false;
}


function ImageButton_toDisable()
{
	document.images[this.ImageID].src = this.DisableImage.src;
	this.isButtonEnable	= false;
}


function ImageButton_toHover()
{
	if (this.isButtonEnable) {
		document.images[this.ImageID].src = this.HoverImage.src;
	}
}


function ImageButton_toHoverOut()
{
	if (this.isButtonEnable) {
		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;
					}
				}
			}
			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.HilightImage.src;
	}
	else{
		document.images[imgBtn.ImageID].src = imgBtn.UpImage.src;
	}
	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, strHilightImage)
{
	
	var objGroup		= eval("document." + strGroup);
	var objImageButton	= eval("document." + strImageButton);
	var count			= objGroup.length;
	objGroup[count]		= objImageButton;
	
	if (null == strHilightImage || "" == strHilightImage) {
		objImageButton.setHilightImage(objImageButton.DownImage.src, objGroup);
	} else {
		objImageButton.setHilightImage(strHilightImage, objGroup);
	}
}


//////////////////////////////////////////////////////////
// ImageMetaData 
//
//////////////////////////////////////////////////////////

//Construction
function ImageMetaData(strSrc, strThumb, strAlt)
{
	this.src = strSrc;
	this.thumb = strThumb;
	this.alt = strAlt;
	
	this.getSrc = ImageMetaData_getSrc;
	this.getThumb = ImageMetaData_getThumb;
	this.getAlt = ImageMetaData_getAlt;
}

function ImageMetaData_getSrc() {
	return this.src;
}

function ImageMetaData_getThumb() {
	return this.thumb;
}

function ImageMetaData_getAlt() {
	return this.alt;
}

//////////////////////////////////////////////////////////////
// Flash Utilities
//
//////////////////////////////////////////////////////////////

// Get Flash object
function getSWF(movieName)
{
	if (navigator.appName.indexOf("Microsoft") >= 0) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

//////////////////////////////////////////////////////////////
// Tab switch Utilities
//
//////////////////////////////////////////////////////////////

// Tab switch
function TabSwitch(tabName, idx, tabLen, hiCls, lowCls)
{
	var i = 0;
	for (i = 1; i <= tabLen; i++) {
		var tabObj = document.getElementById(tabName + "" + i);
		if (i == idx) {
			tabObj.className = hiCls;
		} else {
			tabObj.className = lowCls;
		}
	}
}

// Tab pair switch
function TabPairSwitch(idx, tabLen, tabName, tabHiCls, tabLowCls, ctnName, ctnHiCls, ctnLowCls)
{
	TabSwitch(tabName, idx, tabLen, tabHiCls, tabLowCls);
	TabSwitch(ctnName, idx, tabLen, ctnHiCls, ctnLowCls);
}
