
/**
 * @author Samsung
 */

var BtnImgIndex = {
	BTN_NORMAL_IMG : 0,
	BTN_NORMAL_FOCUS_IMG : 1,
	BTN_SELECTED_IMG : 2,
	BTN_SELECTED_FOCUS_IMG : 3,
	BTN_DIM_IMG : 4
};
var BtnIconIndex = {
	BTN_NORMAL_ICON : 0,
	BTN_NORMAL_FOCUS_ICON : 1,
	BTN_SELECTED_ICON : 2,
	BTN_SELECTED_FOCUS_ICON : 3,
	BTN_DIM_ICON : 4
};
var BtnTextStyleIndex = {
	BTN_TEXT_NORMAL_STYLE : 0,
	BTN_TEXT_FOCUS_STYLE : 1,
	BTN_TEXT_SELECTED_STYLE : 2,
	BTN_TEXT_SELECTED_FOCUS_STYLE : 3,
	BTN_TEXT_DIM_STYLE : 4
};

function Button(imageId, textId, flagPwd, flagDivide, iconId) {

	this.objType = "BUTTON";

	this.image_layer = null;
	this.fgImage_layer = null;
	this.left_image_layer = null;
	this.center_image_layer = null;
	this.right_image_layer = null;
	this.icon_layer = null;
	this.text_layer = null;
	this.check_box = null;
	//2013 add by minseok
	this.parent_id = null;
	this.divide_width = null;

	this.flag_Pwd = false;
	this.flag_block_space = false;
	this.flag_id_type = false;
	this.flag_visible = true;

	if(flagDivide) {
		this.flag_divide = flagDivide;
	} else {
		this.flag_divide = false;
	}

	if(imageId) {
		this.SetImageObjId(imageId);
	}

	if(iconId) {
		this.SetIconObjId(iconId);
	}

	if(textId) {
		if(flagPwd) {
			this.SetTextObjId(imageId, flagPwd);
		} else {
			this.SetTextObjId(imageId);
		}
	}

	this.BtnImg = new Array(4);
	this.BtnLeftImg = new Array(4);
	this.BtnCenterImg = new Array(4);
	this.BtnRightImg = new Array(4);

	this.initImg = 0;

	this.initIcon = 0;
	this.BtnIcon = new Array(4);

	this.MaxStringLength = 50;
	this.MinStringLength = 1;

	this.TextString = "";
	this.HelpTextString = "";
	this.HelpTextStyle = "";
	this.HelpTextShowState = false;

	this.BtnTextStyle = new Array(5);
	this.initTextStyle = 0;
	this.SetText(this.TextString);

	this.onTextChangeFunc = null;

	this.flag_highlight = false;
	this.flag_dim = false;

	this.textEditorTitle = "";
	this.textEditorMsg = "";
	//2013 add by minseok
	this.textEditorPopupTitle=null;
	//2013 add by minseok : for move button image
	this.OptionDivide = 0;

	this.helpBar = null;
	this.flag_visible_helpbar = false;

	this.onClickCallbackFunc = null;
	this.flagClickEnable = false;
	this.flagMouseOverEnable= false;

	this.onRightClickCallbackFunc = null;
	this.onMouseOutCallbackFunc= null;
	this.onMouseOverCallbackFunc= null;
	
/*8.6 add*/
	this.onImeTextEndFunc = null;
	this.marqueeStyle =  null;
}
Button.prototype.SetImeTextEndFunc = function(func) {
	if(func)
		this.onImeTextEndFunc = func;
}

Button.prototype.GetBGLayer = function() {
	return this.image_layer;
}

Button.prototype.GetLeftBGLayer = function() {
	if(this.flag_divide == true) 
		return this.left_image_layer;
}
Button.prototype.GetCenterBGLayer = function() {
	if(this.flag_divide == true) 
		return this.center_image_layer;
}
Button.prototype.GetRightBGLayer = function() {
	if(this.flag_divide == true) 
		return this.right_image_layer;
}
Button.prototype.GetTextLayer = function() {
	return this.text_layer;
}

Button.prototype.GetDivideFlag = function() {
	return this.flag_divide;
}

Button.prototype.GetObjId = function() {
	return this.parent_id;
}
Button.prototype.SetImageObjId = function(id, OptionDivide) {

	if(id) {
		//2013 add by minseok
		this.parent_id = id;
		if(OptionDivide > 0) {
			this.flag_divide = true;
			this.OptionDivide = OptionDivide;

			var LeftBtnHTML = "<div id = '" + id + "_left'></div>";
			var CenterBtnHTML = "<div id = '" + id + "_center'></div>";
			var RightBtnHTML = "<div id = '" + id + "_right'></div>";

			//alert("LeftBtnHTML  : " + LeftBtnHTML);
			//alert("CenterBtnHTML  : " + CenterBtnHTML);
			//alert("RightBtnHTML  : " + RightBtnHTML);

			//insert html
			$("#" + id).append(LeftBtnHTML);
			$("#" + id).append(CenterBtnHTML);
			$("#" + id).append(RightBtnHTML);

			var OrginWidth = $("#" + id).css('width');
			var OrginHeight = $("#" + id).css('height');

			var WidthLen = OrginWidth.indexOf("px");
			var HeightLen = OrginHeight.indexOf("px");

			var w_int = parseInt(OrginWidth.substring(0, WidthLen));
			var h_int = parseInt(OrginHeight.substring(0, HeightLen));

			//alert("w_int  : " + w_int);
			//alert("h_int  : " + h_int);

			//add style class
			$("#" + id + "_left").addClass('cButtonWithTreeObject');
			$("#" + id + "_left").css('left', '0');
			$("#" + id + "_left").css('width', OptionDivide);
			$("#" + id + "_left").css('height', h_int);
			
			$("#" + id + "_center").addClass('cButtonWithTreeObject');
			$("#" + id + "_center").css('left', OptionDivide);
			$("#" + id + "_center").css('width', w_int - (OptionDivide * 2));
			$("#" + id + "_center").css('height', h_int);
			
			$("#" + id + "_right").addClass('cButtonWithTreeObject');
			$("#" + id + "_right").css('left', w_int - OptionDivide);
			$("#" + id + "_right").css('width', OptionDivide);
			$("#" + id + "_right").css('height', h_int);

			this.left_image_layer = new ImageLayer(id + '_left');
			this.center_image_layer = new ImageLayer(id + '_center');
			this.right_image_layer = new ImageLayer(id + '_right');

		} else {
			this.image_layer = new ImageLayer(id);
		}

	} else {
		this.image_layer = null;
	}

}
Button.prototype.SetChkObjId = function(id) {
	if(id) {
		this.check_box = new ImageLayer(id);
	}
}
Button.prototype.SetIconObjId = function(id) {

	if(id) {
		this.icon_layer = new ImageLayer(id);
	} else {
		this.icon_layer = null;
	}

}

Button.prototype.SetTextObjId = function(id, flagPwd) {

	if(id) {
		this.text_layer = new TextLayer(id);
	} else {
		this.text_layer = null;
	}

	if(flagPwd) {
		this.flag_Pwd = flagPwd;
	}
}

Button.prototype.SetBgImage = function(imgIndex, bgImage) {

	if(this.flag_divide == true) {
	//	alert("bgImage : " + bgImage);
		if(bgImage != null) {
			var result = bgImage.indexOf('_center');
			var Url;
			if(result != -1) {
				Url = bgImage.substring(0, result);

			//	alert("Url : " + Url);
			}

			this.BtnLeftImg[imgIndex] = Url + '_left.png';
			this.BtnCenterImg[imgIndex] = Url + '_center.png';
			this.BtnRightImg[imgIndex] = Url + '_right.png';
		}
	} else {
		this.BtnImg[imgIndex] = bgImage;
	}

	if(this.initImg == 0 && imgIndex == 0) {
		this.initImg = 1;

		if(this.flag_divide == true) {
			this.left_image_layer.SetBgImage(this.BtnLeftImg[0]);
			this.center_image_layer.SetBgImage(bgImage);
			this.right_image_layer.SetBgImage(this.BtnRightImg[0]);
		} else {
			this.image_layer.SetBgImage(bgImage);
		}
	}
}

Button.prototype.SetBgIcon = function(iconIndex, bgIcon) {
	this.BtnIcon[iconIndex] = bgIcon;
	if(this.flag_highlight){
		if(iconIndex == 1)
			this.icon_layer.SetBgImage(this.BtnIcon[iconIndex]);
	}else{
		if(iconIndex == 0)
			this.icon_layer.SetBgImage(this.BtnIcon[iconIndex]);
	}
}
Button.prototype.SetBgCheckBox = function(url) {
	this.check_box.SetBgImage(url);
}
Button.prototype.SetTextStyle = function(styleIndex, textStyle) {

	this.BtnTextStyle[styleIndex] = textStyle;

	if(this.initTextStyle == 0 && styleIndex == 0) {
		this.initTextStyle = 1;
		this.text_layer.SetTextStyle(textStyle);
	}
}

Button.prototype.SetText = function(string) {
	// alert("Button.prototype.SetText()");
	if(string==null)
		string = "";
	this.TextString = string;
	var PwdString = "";
	this.HelpStringShowState = false;

	if(this.TextString.length == 0 && this.HelpTextString.length > 0) {
		if(this.text_layer != null) {
			this.SetReverseDisable(false);

			this.text_layer.SetText(this.HelpTextString);
			this.HelpStringShowState = true;
			if(this.HelpTextStyle.length > 0) {
				this.text_layer.SetTextStyle(this.HelpTextStyle);
			}
		}
	} else {
		if(this.HelpTextString.length > 0) {
			this.SetReverseDisable(true);
		}

		if(this.flag_Pwd == true) {
			var a = 0;
			for( a = 0; a < this.TextString.length; a++) {
				PwdString = PwdString + "*";
			}

			if(this.text_layer != null) {
				this.text_layer.SetText(PwdString);
			}
		} else {
			if(this.text_layer != null) {
				this.text_layer.SetText(this.TextString);
			}
		}

		if(this.flag_highlight == true) {
			if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE]) {
				if(this.checkforMarquee()){
					alert("&&&&&&&&&&&SSetMarQueestyle!!!!!!!!!");
					this.text_layer.SetTextStyle(this.marqueeStyle);
				}else{
					this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE]);
				}
			} else if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]) {
				
				this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]);
			}

		} else {
			if(this.flag_dim == true) {
				if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_DIM_STYLE]) {
					this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_DIM_STYLE]);
				} else if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]) {
					this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]);
				}
			} else {
				if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]) {
					this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]);
				}
			}
		}

	}

	if(this.onTextChangeFunc ) {
		this.onTextChangeFunc();
	}
}

Button.prototype.GetText = function() {
	return this.TextString;
}

Button.prototype.SetFlagPwd = function(flagPWD) {
	if(flagPwd) {
		this.flag_Pwd = flagPwd;

		this.SetText(this.TextString);
	}
}

Button.prototype.GetFlagPwd = function() {
	return this.flag_Pwd;
}

Button.prototype.SetFlagBlockSpace = function(flagBlockSpace) {
	if(flagBlockSpace) {
		this.flag_block_space = flagBlockSpace;
	}
}

Button.prototype.GetFlagBlockSpace = function() {
	return this.flag_block_space;
}

Button.prototype.SetFlagIdType = function(flagIdType) {
	if(flagIdType) {
		this.flag_id_type = flagIdType;
	}
}

Button.prototype.GetFlagIdType = function(flagIdType) {
	return this.flag_id_type;
}

Button.prototype.SetMaxStringLength = function(max_Length) {
	this.MaxStringLength = max_Length;
}

Button.prototype.GetMaxStringLength = function() {
	return this.MaxStringLength;
}

Button.prototype.SetMinStringLength = function(min_Length) {
	this.MinStringLength = min_Length;
}

Button.prototype.GetMinStringLength = function() {
	return this.MinStringLength;
}

Button.prototype.SetHelpText = function(helpString, helpStyle) {
	if(helpString)
		this.HelpTextString = helpString;
	if(helpStyle) {
		this.HelpTextStyle = helpStyle;
	}

	this.SetText(this.TextString);
}

Button.prototype.SetOnTextChangeFunc = function(func) {

	if(func) {
		this.onTextChangeFunc = func;
	}
}

//modify by minseok -> mood message....p.186
Button.prototype.SetTextEditorInfo = function(s_titie, s_msg, s_popupTitle) {
	if(s_titie) {
		this.textEditorTitle = s_titie;
	}
	if(s_msg) {
		this.textEditorMsg = s_msg;
	}
	if(s_popupTitle){
		this.textEditorPopupTitle=s_popupTitle;	
	}
}
Button.prototype.GetTextEditorPopupTitle = function(){
	return this.textEditorPopupTitle;
}
Button.prototype.GetTextEditorTitle = function() {
	return this.textEditorTitle;
}

Button.prototype.GetTextEditorMsg = function() {
	return this.textEditorMsg;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Button.prototype.highlight = function() {

	this.flag_highlight = true;

	if(this.flag_divide == true) {
		this.left_image_layer.SetBgImage(this.BtnLeftImg[BtnImgIndex.BTN_NORMAL_FOCUS_IMG]);
		this.center_image_layer.SetBgImage(this.BtnCenterImg[BtnImgIndex.BTN_NORMAL_FOCUS_IMG]);
		this.right_image_layer.SetBgImage(this.BtnRightImg[BtnImgIndex.BTN_NORMAL_FOCUS_IMG]);
	} else {
		this.image_layer.SetBgImage(this.BtnImg[BtnImgIndex.BTN_NORMAL_FOCUS_IMG]);
	}

	if(this.BtnIcon[BtnIconIndex.BTN_NORMAL_FOCUS_ICON])
		this.icon_layer.SetBgImage(this.BtnIcon[BtnIconIndex.BTN_NORMAL_FOCUS_ICON]);

	if(this.HelpStringShowState == true && this.HelpTextStyle.length > 0) {
		this.text_layer.SetTextStyle(this.HelpTextStyle);
	} else {
		if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE]) {
			if(this.checkforMarquee()){
					alert("&&&&&&&&&&&SSetMarQueestyle!!!!!!!!!higlight");
					this.text_layer.SetTextStyle(this.marqueeStyle);
			}else{
				this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE]);
			}
		} else if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]) {
			this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]);
		}
		
	}

	/*if( this.helpBar)
	 {
	 this.helpBar.visibleObj();
	 }*/
	//this.visibleHelpBar();

}

Button.prototype.blur = function() {

	this.flag_highlight = false;

	if(this.flag_dim == false) {
		if(this.flag_divide == true) {
			this.left_image_layer.SetBgImage(this.BtnLeftImg[BtnImgIndex.BTN_NORMAL_IMG]);
			this.center_image_layer.SetBgImage(this.BtnCenterImg[BtnImgIndex.BTN_NORMAL_IMG]);
			this.right_image_layer.SetBgImage(this.BtnRightImg[BtnImgIndex.BTN_NORMAL_IMG]);
		} else {
			this.image_layer.SetBgImage(this.BtnImg[BtnImgIndex.BTN_NORMAL_IMG]);
		}

		if(this.BtnIcon[BtnIconIndex.BTN_NORMAL_ICON])
			this.icon_layer.SetBgImage(this.BtnIcon[BtnIconIndex.BTN_NORMAL_ICON]);

		if(this.HelpStringShowState == true && this.HelpTextStyle.length > 0) {
			this.text_layer.SetTextStyle(this.HelpTextStyle);
		} else {
			if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]) {
				this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE]);
			}
		}
	}

	//this.hiddenHelpBar();
}

Button.prototype.select = function() {

	if(this.BtnImg[BtnImgIndex.BTN_SELECTED_IMG]) {
		if(this.flag_divide == true) {
			this.left_image_layer.SetBgImage(this.BtnLeftImg[BtnImgIndex.BTN_SELECTED_IMG]);
			this.center_image_layer.SetBgImage(this.BtnCenterImg[BtnImgIndex.BTN_SELECTED_IMG]);
			this.right_image_layer.SetBgImage(this.BtnRightImg[BtnImgIndex.BTN_SELECTED_IMG]);
		} else {
			this.image_layer.SetBgImage(this.BtnImg[BtnImgIndex.BTN_SELECTED_IMG]);
		}
	}

	if(this.BtnIcon[BtnIconIndex.BTN_SELECTED_ICON]) {
		this.icon_layer.SetBgImage(this.BtnIcon[BtnIconIndex.BTN_SELECTED_ICON]);
	}

	if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_SELECTED_STYLE]) {
		this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_SELECTED_STYLE]);
	}

	//this.hiddenHelpBar();
}

Button.prototype.flagHighlight = function() {

	return this.flag_highlight;
}

Button.prototype.AppendFgImage = function(id, h_space, v_space, w, h, img_src) {

	if(h_space == null || v_space == null || w == null || h == null) {
		if(id) {
			this.fgImage_layer = new ImageLayer(id);
		} else {
			this.fgImage_layer = null;
		}
	}
	else {
		if(this.flag_divide==true){
			this.center_image_layer.AppendFgImage(id, h_space, v_space, w, h, img_src);
		}else{
			this.image_layer.AppendFgImage(id, h_space, v_space, w, h, img_src);
		}
	}
}

Button.prototype.SetFgImage = function(img_src) {

	if(this.fgImage_layer == null) {
	if(this.flag_divide==true){
		this.center_image_layer.SetFgImage(img_src);
	}else{
	this.image_layer.SetFgImage(img_src);
	}
	} else {
		this.fgImage_layer.SetBgImage(img_src);
}
}

Button.prototype.registHelpBar = function(obj) {
	if(obj) {
		this.helpBar = obj;
	}
}

Button.prototype.changeHelpBar = function(obj) {
	//alert("Button.prototype.hiddenObj()");
	if(this.helpBar == obj) {
		return;
	}

	if(this.helpBar != null) {
		this.helpBar.hiddenObj();
	}

	if(obj) {
		this.helpBar = obj;
		//if(this.flag_highlight ==true)
		if(this.flag_visible_helpbar == true) {
			this.helpBar.visibleObj();
		}
	}
}
//TEMPCODE:
Button.prototype.changeHelpBarForHiddenObj = function(obj) {
	//alert("Button.prototype.hiddenObj()");
	if(this.helpBar == obj) {
		return;
	}

	if(this.helpBar != null) {
		this.helpBar.hiddenObj();
	}

	if(obj) {
		this.helpBar = obj;
	}

}

Button.prototype.visibleHelpBar = function() {

	if(this.flag_visible_helpbar == true) {
		return;
	} else {
		this.flag_visible_helpbar = true;
		if(this.helpBar) {
			this.helpBar.visibleObj();
		}
	}
}

Button.prototype.hiddenHelpBar = function() {

	if(this.flag_visible_helpbar == false) {
		return;
	} else {
		this.flag_visible_helpbar = false;
		if(this.helpBar) {
			this.helpBar.hiddenObj();
		}
	}
}

Button.prototype.SetFlagDim = function(b_dim) {

	if(this.flag_dim == b_dim || this.flag_highlight == true) {
		return;
	}

	this.flag_dim = b_dim;

	if(this.flag_dim == true) {
		//2013 modify by minseok
		//because flag_divide : true -> BtnImg array is null
			if(this.flag_divide == true) {
			if(this.BtnCenterImg[BtnImgIndex.BTN_DIM_IMG]) {
				this.left_image_layer.SetBgImage(this.BtnLeftImg[BtnImgIndex.BTN_DIM_IMG]);
				this.center_image_layer.SetBgImage(this.BtnCenterImg[BtnImgIndex.BTN_DIM_IMG]);
				this.right_image_layer.SetBgImage(this.BtnRightImg[BtnImgIndex.BTN_DIM_IMG]);
			}
			} else {
			if(this.BtnImg[BtnImgIndex.BTN_DIM_IMG]) {
				this.image_layer.SetBgImage(this.BtnImg[BtnImgIndex.BTN_DIM_IMG]);
			}
		}

		if(this.BtnIcon[BtnIconIndex.BTN_DIM_ICON]) {
			this.icon_layer.SetBgImage(this.BtnIcon[BtnIconIndex.BTN_DIM_ICON]);
		}

		if(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_DIM_STYLE]) {
			this.text_layer.SetTextStyle(this.BtnTextStyle[BtnTextStyleIndex.BTN_TEXT_DIM_STYLE]);
		}

		this.DisableOnClick();
		//added 2.5
		this.DisableOnMouseOver();
	} else {
		this.blur();

		this.EnableOnClick();
		// added 2.5
		this.EnableOnMouseOver();
	}
}

Button.prototype.GetFlagDim = function() {
	return this.flag_dim;
}
Button.prototype.visibleChkBox = function() {
	if(this.check_box)
		this.check_box.visibleObj();
}
Button.prototype.hiddenChkBox = function() {
	if(this.check_box)
		this.check_box.hiddenObj();
}
Button.prototype.visibleObj = function() {
	// alert("Button.prototype.visibleObj()");
	if(this.image_layer) {
		this.image_layer.visibleObj();
	}else if(this.flag_divide == true){
		this.left_image_layer.visibleObj();
		this.center_image_layer.visibleObj();
		this.right_image_layer.visibleObj();
	}

	if(this.icon_layer) {
		this.icon_layer.visibleObj();
	}

	if(this.text_layer) {
		this.text_layer.visibleObj();
	}
	this.EnableOnClick();
	this.EnableOnMouseOver();

    this.flag_visible = true;

}

Button.prototype.hiddenObj = function() {
	//alert("Button.prototype.hiddenObj()");
	if(this.image_layer) {
		this.image_layer.hiddenObj();
	}else if(this.flag_divide == true){
		this.left_image_layer.hiddenObj();
		this.center_image_layer.hiddenObj();
		this.right_image_layer.hiddenObj();
	}

	if(this.icon_layer) {
		this.icon_layer.hiddenObj();
	}

	if(this.text_layer) {
		this.text_layer.hiddenObj();
	}
	this.DisableOnClick();
	this.DisableOnMouseOver();
    this.flag_visible = false;	
}

Button.prototype.GetFlagVisible= function(){
    return this.flag_visible;
}

Button.prototype.SetIsTextInTable = function(flagInTable) {

	this.text_layer.SetIsTextInTable(flagInTable);

}
//2013 modify by minseok : for move image & divide button
Button.prototype.SetLeft = function(left_value) {
	alert("Button change left : "+left_value);
	if(this.flag_divide==true){
		$("#" + this.parent_id).css('left', left_value+'px');
	}else{
		var image_id = this.image_layer.GetObjectId();
		$("#" + image_id).css('left', left_value);
	}
}
Button.prototype.SetTop = function(top_value) {
	alert("Button change top : "+top_value);
	if(this.flag_divide==true){
		// var image_id_left = this.left_image_layer.GetObjectId();
		// var image_id_center = this.center_image_layer.GetObjectId();
		// var image_id_right = this.right_image_layer.GetObjectId();
// 		
		// $("#" + image_id_left).css('top', top_value+'px');
		// top_value+=this.OptionDivide;
		// $("#" + image_id_center).css('top', top_value+'px');
		// top_value+=this.OptionDivide;
		// $("#" + image_id_right).css('top', top_value);
		$("#" + this.parent_id).css('top', top_value+'px');
	}else{
		var image_id = this.image_layer.GetObjectId();
		$("#" + image_id).css('top', top_value);
	}
}

Button.prototype.SetOnClickCallbackFunc = function(func) {
	if(WndMgr.MouseClickEnable == false) {
		return;
	}

	alert("Button.SetOnClickCallbackFunc() set on image_layer");

	this.onClickCallbackFunc = func;
	this.EnableOnClick();
}

Button.prototype.SetOnRightClickCallbackFunc = function(func) {
	if(WndMgr.MouseClickEnable == false) {
		return;
	}

	alert("Button.SetOnRightClickCallbackFunc() set on image_layer");

	this.onRightClickCallbackFunc = func;
	if(this.flagClickEnable == true) {
		this.EnableOnRightClick();
	}
}

Button.prototype.EnableOnClick = function() {
	if(WndMgr.MouseClickEnable == false) {
		return;
	}

	if(this.flagClickEnable == false && this.flag_dim == false) {
		var this_ = this;
		document.getElementById(this.parent_id).onclick = function() {
			this_.onClickCallbackFunc(this_);
		};
		if(this.onRightClickCallbackFunc != null) {
			this.EnableOnRightClick();
		}
		this.flagClickEnable = true;
		$("#" + this.parent_id).css({
			'cursor' : 'pointer'
		});
	}
}

Button.prototype.DisableOnClick = function() {
	if(WndMgr.MouseClickEnable == false) {
		return;
	}

	if(this.flagClickEnable == true) {
		document.getElementById(this.parent_id).onclick = null;
		if(this.onRightClickCallbackFunc != null) {
			this.DisableRightOnClick();
		}
		this.flagClickEnable = false;
		$("#" + this.parent_id).css({
			'cursor' : ''
		});
	}
}

Button.prototype.EnableOnRightClick = function() {

	//var object = this.image_layer.GetObjectId();
	var this_ = this;

	document.getElementById(this.parent_id).onmousedown = function() {
		if(event.button == 2) {
			this_.onRightClickCallbackFunc(this_);
		}
	};
	//document.getElementById(object).onmousedown = function(){if(event.button==2){this_.onRightClickCallbackFunc(this_);} };

}

Button.prototype.DisableRightOnClick = function() {
	//this.parent_id
	if(this.flagClickEnable == true) {
		//var object = this.image_layer.GetObjectId();
		document.getElementById(this.parent_id).onmousedown = null;
	}
}

Button.prototype.SetOnMouseOverCallbackFunc = function(func){
	if(WndMgr.MouseClickEnable==false)
	{
		return;	
	}
	if(this.parent_id != null)
	{
		alert("Button.SetOnMouseOverCallbackFunc() set on image_layer");
		
		this.onMouseOverCallbackFunc = func;
		this.EnableOnMouseOver();			
	}
}

Button.prototype.EnableOnMouseOver = function(){
	var object = this.parent_id;
	var this_ = this;
	if(this.onMouseOverCallbackFunc==null){
		return;
	}
	if(this.flagMouseOverEnable == false && this.flag_dim == false) {
		document.getElementById(object).onmouseover = function(){this_.onMouseOverCallbackFunc(this_);};
		this.flagMouseOverEnable=true;
	}
}
Button.prototype.DisableOnMouseOver = function(){
	var object = this.parent_id;
	if(this.flagMouseOverEnable == true) {
		document.getElementById(object).onmouseover = null;
		this.flagMouseOverEnable = false;
	}
}

Button.prototype.SetOnMouseOutCallbackFunc = function(func){
	if(WndMgr.MouseClickEnable==false)
	{
		return;	
	}
	if(this.parent_id != null)
	{
		alert("Button.SetOnMouseOutCallbackFunc() set on image_layer");
		
		this.onMouseOutCallbackFunc = func;
		this.EnableOnMouseOut();			
	}
}
Button.prototype.EnableOnMouseOut = function(){
	var object = this.parent_id;
	var this_ = this;
	if(this.onMouseOutCallbackFunc==null){
		return;
	}
	document.getElementById(object).onmouseout = function(){this_.onMouseOutCallbackFunc(this_);};
}
Button.prototype.DisableOnMouseOut = function(){
	var object = this.parent_id;
	document.getElementById(object).onmouseout = null;
}





Button.prototype.SetReverseDisable = function(flag) {
	this.text_layer.SetReverseDisable(flag);
}
Button.prototype.SetOverflowMarquee = function(marqueestyle){
	this.marqueeStyle = marqueestyle;
	
}
Button.prototype.checkforMarquee = function(){
	//alert("checkforMarquee ----------------------");
	if(this.marqueeStyle==null){
		return ;
	}
	var textMaxWidth = $("#"+this.text_layer.GetObjectId()).width()+1;
	var fontsize = $("#"+this.text_layer.GetObjectId()).css("font-size");
	$("body").append("<div id='tmpid'></div>");
	$('#tmpid').css({
		'position':'absolute',
	    'left': '0px',  
	    'font-size':fontsize, 
		'visibility': 'hidden'
		});
		$('#tmpid').text(this.TextString);
	var width = $("#tmpid").width()+1;
	//alert("width is "+width);
	//alert("textMaxWidth is "+textMaxWidth);
	$("#tmpid").remove();
	if(width>textMaxWidth){
		return true;
	}else{
		return false;
	}
}

Button.prototype.SetIsPlainText= function(flag)
{
    this.text_layer.SetIsPlainText(flag);   
}
Button.prototype.ResizeButton = function(dir,text_minwidth) {
	alert("Button.ResizeButton()");
	if(this.OptionDivide==null)
		return ;
	var btn_orileft=0, btn_oriwidth = 0,btn_width = 0,btn_left = 0,text_minwidth,text_left = 0;
	btn_orileft = parseInt($("#"+this.parent_id).css("left").replace(/[^-\d\.]/g, ''));
	btn_oriwidth = parseInt($("#"+this.parent_id).css("width").replace(/[^-\d\.]/g, ''))+1;
	text_left = this.text_layer.GetLeft();
	
	if(text_minwidth==null){
		text_minwidth = this.text_layer.GetTextMinWidth();
	}
	if(text_left<20)
		text_left = 20;
	btn_width = text_minwidth+text_left*2;
	if(btn_width < btn_oriwidth)
		return ;
	btn_left = 0;
	switch(dir){
		case "L":
			btn_left = btn_orileft - (btn_width-btn_oriwidth);
			break;
		case "C":
			btn_left = btn_orileft - (btn_width-btn_oriwidth)/2;
			break;
		case "R":
			btn_left=btn_orileft;
			break;
	}

	if(this.icon_layer)
	{
		text_minwidth = text_minwidth - $("#" + this.icon_layer.GetObjId()).width() - parseInt($("#"+this.icon_layer.GetObjId()).css("right").replace(/[^-\d\.]/g, ''));
	}
	$("#" + this.parent_id).css('left',btn_left);
	$("#" + this.parent_id).css('width',btn_width);
	var textObj_id = this.text_layer.GetObjId();
	$("#" + textObj_id).css('left',text_left);
	$("#" + textObj_id).css('width',text_minwidth);
	$("#" + this.parent_id + "_center").css('width', btn_width - (this.OptionDivide * 2));
	$("#" + this.parent_id + "_right").css('left', btn_width - this.OptionDivide);
}
