
/**
 * @author Samsung
 */

function TextLayer(id){
    
    this.textObj = id;
    this.textString = "";
    this.currentStyle = "";
	
	//Layer 클래스 상속?
	//공통 분모 뽑아내면 편리하게 쓰일 수 있다.		
	Layer.call(this,id);	
	
	this.isTextInTable =  false;	

	this.isMarqueeEnable = false;
	this.maxMarqueeWidth =0;
	
	this.marqueeEnableStyle = "";
	this.marqueeDisableStyle ="";
	
	this.flagReverseDisable=false;
	
	this.curr_text_length =0;
	
	this.isPlainText = false;
	this.AdjustFlag = false;
}


TextLayer.prototype = new Layer(); 

TextLayer.prototype.GetObjectId = function()
{
	return this.textObj;
}

TextLayer.prototype.SetText = function(string)
{
	//alert("SetText");
	this.textString=string;
	if(string != null)
	{
		this.curr_text_length = string.length;
	}
	else
	{
		this.curr_text_length = 0;
	}
			
	if(this.isMarqueeEnable ==true)
	{
		if(this.currentStyle.length>0 && this.isTextInTable==false )
		{
			alert("removeClass");
			$("#"+this.textObj).removeClass(this.currentStyle);
		}		
	}
	
	if(this.isTextInTable==false)    
	{
		if(this.isPlainText == false)
		{
			$("#"+this.textObj).html(string);
		}
		else
		{
			alert("setPlainText");
			$("#"+this.textObj).text(string);
		}
		
	}
	else
	{
		if(this.isPlainText == false)
		{
			$("div#"+this.textObj+" td:first").html(string);
		}
		else
		{
			alert("setPlainText");
			$("div#"+this.textObj+" td:first").text(string);
		}
		
	}
	
	if(this.isMarqueeEnable ==true)
	{
		if(this.isTextInTable==false)  
		{
			var curr_w = $("#"+this.textObj).css('width');
			alert("TextLayer curr width1 : "+ curr_w);
			
			var len= curr_w.indexOf("px");
			var curr_w_int = parseInt(curr_w.substring(0,len));
			alert("TextLayer curr width2: "+ curr_w_int);
			
			if(this.maxMarqueeWidth < curr_w_int)
			{
				alert("start marquee");
				$("#"+this.textObj).addClass(this.marqueeEnableStyle);
				this.currentStyle = this.marqueeEnableStyle;
			}
			else
			{
				alert("stop marquee");
				$("#"+this.textObj).addClass(this.marqueeDisableStyle);
				this.currentStyle = this.marqueeDisableStyle;
			}
			
			if(ResMgr.isReverseLanguage() && this.flagReverseDisable==false)
			{
				$("#"+this.textObj).css("direction","rtl");
			}
		}
	}
 	else
 	{
		if(ResMgr.isReverseLanguage() && this.flagReverseDisable==false)
	    {
	    	if(this.isTextInTable==false)   
	    	{
	    		$("#"+this.textObj).css("direction","rtl");
	    	}
	    	else
	    	{
	    		$("div#"+this.textObj+" td:first").css("direction","rtl");
	    	}	    	
	    }	
 	}
	this.AdjustWidth();

}

TextLayer.prototype.SetTextStyle = function(style)
{
	//alert("SetTextStyle");	
	
	if(this.isTextInTable==false)
	{
		 if(this.currentStyle.length>0)
	    {
	        $("#"+this.textObj).removeClass(this.currentStyle);
	    }
	    
	    $("#"+this.textObj).addClass(style);  
	    
	}
	else
	{
		if(this.currentStyle.length>0)
	    {
	        $("div#"+this.textObj+" td:first").removeClass(this.currentStyle);
	    }
	    
	    $("div#"+this.textObj+" td:first").addClass(style);
	    
	}
	
	
	    	
	this.currentStyle=style;
}

TextLayer.prototype.visibleObj=function()
{
    //alert("TextLayer.prototype.visibleObj()");

    $("#"+this.textObj).css("visibility","visible");
}

TextLayer.prototype.hiddenObj=function(){
    //alert("TextLayer.prototype.hiddenObj()");
   $("#"+this.textObj).css("visibility","hidden");
}

TextLayer.prototype.SetIsTextInTable = function(flagInTable)
{
    this.isTextInTable = flagInTable ;   
}

TextLayer.prototype.SetMarqueeEnable = function(maxWidth, enableStyle, disableStyle)
{
	this.isMarqueeEnable = true;
	
	this.maxMarqueeWidth = maxWidth;
	this.marqueeEnableStyle = enableStyle;
	this.marqueeDisableStyle =disableStyle;
	
}
TextLayer.prototype.CheckTextLength = function(CheckerEID,CheckerText)
{
	alert("CheckTextLength");

	$("#"+CheckerEID).removeClass('cItem_Name_checker');	  // only widht
	$("#"+CheckerEID).text(CheckerText); 
 	
 	var curr_w = $("#"+CheckerEID).css('width');
	//alert("CheckTextLength curr width1 : "+ curr_w);
	
	var len= curr_w.indexOf("px");
	var curr_w_int = parseInt(curr_w.substring(0,len));
	//alert("CheckTextLength curr width2: "+ curr_w_int);

	$("#"+CheckerEID).addClass('cItem_Name_checker');

	return curr_w_int;
}

TextLayer.prototype.SetReverseDisable = function(flag)
{
	var back_flag = this.flagReverseDisable;
	this.flagReverseDisable=flag;
	
	if(this.flagReverseDisable==true && ResMgr.isReverseLanguage() && this.flagReverseDisable!=back_flag)
	{
		if(this.curr_text_length>0)
		{
	    	if(this.isTextInTable==false)   
	    	{ 
	    		$("#"+this.textObj).css("direction","ltr");
	    	}
	    	else
	    	{
	    		$("div#"+this.textObj+" td:first").css("direction","ltr");
	    	}
		}
	}
}

TextLayer.prototype.SetIsPlainText= function(flagPlainText)
{
    this.isPlainText = flagPlainText ;   
}

TextLayer.prototype.GetLeft= function()
{
	return parseInt($("#"+this.textObj).css("left").replace(/[^-\d\.]/g, ''));
}
TextLayer.prototype.GetWidth= function()
{
	return $("#"+this.textObj).width()+1;
}
TextLayer.prototype.SetAdjustFlag = function(flag){
	 this.AdjustFlag = flag ;   
}
TextLayer.prototype.AdjustWidth= function(){
	if(this.AdjustFlag == false)
		return;
	var minwidth = this.GetTextMinWidth();
	var currentwidth = $("#"+this.textObj).width()+1;
	if(minwidth-currentwidth <= 10 && minwidth-currentwidth > 0){
		$("#"+this.textObj).css("width",minwidth+'px');
	}
}
TextLayer.prototype.GetTextMinWidth= function()
{
	$("body").append("<div id='tempdiv'></div>");
	var fontsize = $("#"+this.textObj).css("font-size");
	$("#tempdiv").css({
		'position':'absolute',
	    'left': '0px',
	    'font-size':fontsize, 
		'visibility': 'hidden'
	});
	$("#tempdiv").text(this.textString);
	var minwidth = $("#tempdiv").width()+1;
	$("#tempdiv").remove();
	/*
	alert("-----------------------------------------------------------");
		alert(this.textObj+" minwidth = "+minwidth);*/
	
	return minwidth;
}
TextLayer.prototype.GetTextMinHeight= function()
{
	$("#"+this.textObj).append("<div id='H_tempdiv'></div>");
	var fontsize = $("#"+this.textObj).css("font-size");
	var line_height = $("#"+this.textObj).css("line-height");
	$("#H_tempdiv").css({
		'position':'absolute',
	    'left': '0px',
	    'top':'0px',
	    'font-size':fontsize, 
	    'line-heihgt':line_height,
		'visibility': 'hidden'
	});
	$("#H_tempdiv").text(this.textString);
	var minheight = $("#H_tempdiv").height();
	$("#H_tempdiv").remove();
	/*
	alert("-----------------------------------------------------------");
		alert(this.textObj+" minheight = "+minheight);*/
	
	return minheight;
}

TextLayer.prototype.GetMaxWidthTextArray = function() {
	$("body").append("<div id='tempdiv'></div>");
	var fontsize = $("#" + this.textObj).css("font-size");
	var minwidth = 0,temp=0;
	$("#tempdiv").css({
		'position' : 'absolute',
		'left' : '0px',
		'font-size' : fontsize,
		'visibility' : 'hidden'
	});
	for(var i = 0; i < arguments.length; i++) {

		$("#tempdiv").text(arguments[i]);
		temp = $("#tempdiv").width() + 1;
		//alert(arguments[i] + " "+temp);
		if(temp > minwidth )
			minwidth = temp;
	}
	//alert(this.textObj + " minwidth = " + minwidth);
	$("#tempdiv").remove();
	return minwidth;
}