/* Button Objects */
function button3Parts()
{
	this.swapBGs = function(_oldState,_newState)
	{
		colCells = this.rows[0].cells;
		for (var x=0;x<colCells.length;x++)
		{
			try{
			colCells[x].style.backgroundImage = this.getStyle(colCells[x],"background-image").replace(_oldState,_newState);
			}catch(e){}
			try{
			colCells[x].getElementsByTagName("IMG")[0].src = colCells[x].getElementsByTagName("IMG")[0].src.replace(_oldState,_newState);
			}catch(e){}
			/* For IE6 Only */
			try{
			colCells[x].style.filter = colCells[x].currentStyle.filter.replace(_oldState,_newState);
			}catch(e){}
		}
	}
	this.onmouseover = function (){
		if( this.rows[0].className.match("Disabled")==null )
		{
			this.swapBGs("_idle","_hover");
			this.rows[0].className = "Over";
		}
	}
	this.onmouseout = function (){
		if( this.rows[0].className.match("Disabled")==null )
		{
			this.swapBGs("_hover","_idle");
			this.swapBGs("_down","_idle");
			this.rows[0].className = "";
		}
	}
	this.onmousedown = function ()
	{
		if( this.rows[0].className.match("Disabled")==null )
		{
			this.swapBGs("_hover","_down");
			this.rows[0].className = "Down";
		}
		
	}
	this.onmouseup = function (){
		if( this.rows[0].className.match("Disabled")==null )
		{
			this.swapBGs("_down","_hover");
			this.rows[0].className = "Over";
		}
	}
	this.ondragend = function (){
		if( this.rows[0].className.match("Disabled")==null )
		{
			this.swapBGs("_down","_idle");
			this.rows[0].className = "";		
		}
	}
	this.disableButton = function()
	{
		this.swapBGs("_down","_disabled");
		this.swapBGs("_hover","_disabled");
		this.swapBGs("_idle","_disabled");
		this.rows[0].className = "Disabled";
		this.disabled = true;
	}
	this.enableButton = function()
	{
		this.disabled = false;
		this.rows[0].className = "";
		this.swapBGs("_disabled","_idle");
	}
	this.setLabel = function(strLabel)
	{
		this.rows[0].cells[1].innerHTML = strLabel;
	}
	//image preload
	this.imgPreload = function()
	{
		this.swapBGs("_idle","_hover");
		this.swapBGs("_hover","_down");
		this.swapBGs("_down","_disabled");
		this.swapBGs("_disabled","_idle");
	}
}
button3Parts.prototype = new guiObject;
function createButton3Parts(_id,_theme,_label,_function)
{
	oBtn = document.createElement("TABLE");
	oBtn.id = _id;
	oBtn.onclick = _function;
	
	oBtnTBODY = document.createElement("TBODY");
	oBtnTBODY.className = _theme;
	
	oBtnTR = document.createElement("TR");
	
	oBtnTD_First = document.createElement("TD");
	oBtnTD_First.className="ButtonFirst";
	
	oBtnTD_Center = document.createElement("TD");
	oBtnTD_Center.className="ButtonLabel";
	oBtnTD_Center.innerHTML = _label;
	
	oBtnTD_Last = document.createElement("TD");
	oBtnTD_Last.className="ButtonLast";
	
	oBtn.appendChild(oBtnTBODY);
	oBtnTBODY.appendChild(oBtnTR);
	oBtnTR.appendChild(oBtnTD_First);
	oBtnTR.appendChild(oBtnTD_Center);
	oBtnTR.appendChild(oBtnTD_Last);
	
	inheritFrom(oBtn,new button3Parts);
	
	return oBtn;
}
function imgBtn()
{
	this.swapBGs = function(_oldState,_newState)
	{
		this.src = this.src.replace(_oldState,_newState);
	}
	this.onmouseover = function (){
		if(this.className.search("WithHover") != -1){
			this.swapBGs("_idle","_hover");
		}
	}
	this.onmouseout = function (){
		this.swapBGs("_hover","_idle");
		this.swapBGs("_down","_idle");
	}
	this.onmousedown = function (){
		this.swapBGs("_hover","_down");
		this.swapBGs("_idle","_down");
	}
	this.onmouseup = function (){
		if(this.className.search("WithHover") != -1){
			this.swapBGs("_down","_hover");
		}else{
			this.swapBGs("_down","_idle");	
		}
	}
	this.ondragend = function (){
		
		this.swapBGs("_down","_idle");
	}
	this.disableButton = function()
	{
		this.disabled = true;
		this.swapBGs("_down","_disabled");
		this.swapBGs("_hover","_disabled");
		this.swapBGs("_idle","_disabled");
		this.rows[0].className = "Disabled"
	}
	this.enableButton = function()
	{
		this.disabled = false;
		this.rows[0].className = ""
	}
	this.imgPreload = function()
	{
		this.swapBGs("_idle","_hover");
		this.swapBGs("_hover","_down");
		this.swapBGs("_down","_disabled");
		this.swapBGs("_disabled","_idle");
	}
}
imgBtn.prototype = new guiObject;

function allButtonsInit()
{
	allButtons3Parts = getElementsByClass("Button3Parts",document.body);
	allButtons3Parts = allButtons3Parts.concat(getElementsByClass("ButtonSet_Button"));
	allButtons3Parts = allButtons3Parts.concat(getElementsByClass("SidePanel_Item"));
	
	for(var i=0;i<allButtons3Parts.length;i++)
	{
		inheritFrom(allButtons3Parts[i],new button3Parts);
		allButtons3Parts[i].imgPreload();
		try
		{
			allButtons3Parts[i].rows[0].cells[1].unselectable = true;
		}
		catch(e){}
		if(allButtons3Parts[i].disabled == true || allButtons3Parts[i].getAttribute("disabled") == "true")
		{
			allButtons3Parts[i].disableButton();
		}
	}
	allImgButtons = getElementsByClass("ImgBtn",document.body);
	for(var i=0;i<allImgButtons.length;i++)
	{
		inheritFrom(allImgButtons[i],new imgBtn);
		/*debugger;
		if(allImgButtons[i].nameProp=="btn_inviteFriend_idle.gif")
		{
			debugger;
		}*/
		allImgButtons[i].imgPreload();
	}
}


try
{
	allButtonsInit();
}
catch(e)
{
	addLoadEvent(allButtonsInit);
}

function changeButtonState(button, buttonName, state) {
	button.className = buttonName + state;
}