
var DEFAULT_SEARCH_DATA = { 
 
    SkypName		:   " ",
    FullName		:   " ",
    Country			:   " ",
    AvatarPath		:   " "
}


function SearchItem () {

    //this.BoxLayerIndex		= -1;	
    //this.AvataLayerIndex		= -1;    
 	this.FullNameLayerIndex		= -1;
    this.SkypeNameLayerIndex	= -1;	
	this.CountryLayerIndex		= -1;
	
    //this.BoxStyle			= new Array(ITEM_STATE.MAX);   
    //this.AvataStyle			= new Array(ITEM_STATE.MAX);	
    this.FullNameStyle		= new Array(ITEM_STATE.MAX);	
	this.SkypeNameStyle		= new Array(ITEM_STATE.MAX);
    this.CountryStyle		= new Array(ITEM_STATE.MAX);

	this.SkypeName 			= null;
	this.FullName 			= null;
	this.Country 			= null;
	//this.AvatarType			= null;
	
	this.eID	= null;

	
    ListItem.call(this);
}

SearchItem.prototype = new ListItem(); 


SearchItem.prototype.Create = function(eName, divide_option) {
    
    alert("SearchItem.Create()");

    this.CreateBG(eName, divide_option); 
	this.CreateFullName(eName);	
    this.CreateSkypeName(eName);	
    this.CreateCountry(eName);		
    //this.CreateBox(eName);    
    //this.CreateAvata(eName);
   
   	this.eID = eName;

    /*if(this.ItemID % 2 == 0){		
    	
		this.SetBgImage(ITEM_STATE.NORMAL,g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_NORMAL_BG_1);
    }
    else {
		
        this.SetBgImage(ITEM_STATE.NORMAL,' ');
    }*/
    this.SetBgImage(ITEM_STATE.NORMAL,' ');
	this.SetBgImage(ITEM_STATE.HIGHLIGHT,g_Image.IMAGE_LIST_MAIN_CALL_COUNTR_FLAG_LIST_ITEM_HIGHLIGHT_BG);
	alert("id+normal : "+eName+"Normal");	
	// this.SetBgStyle(ITEM_STATE.NORMAL, eName + "Normal");
	this.LayerArray[this.BGLayerIndex].SetStyle(eName + "Normal");
	
	/*this.SetBgStyle(ITEM_STATE.NORMAL_UP, eName + "NormalUp");
	this.SetBgStyle(ITEM_STATE.NORMAL_DOWN, eName + "NormalDown");
	this.SetBgStyle(ITEM_STATE.HIGHLIGHT, eName + "Highlight");*/
	
	
	this.SetFullNameStyle(ITEM_STATE.NORMAL, "cSearchItem_FullName_Normal");
	this.SetFullNameStyle(ITEM_STATE.HIGHLIGHT, "cSearchItem_FullName_Highlight");
	
	this.SetSkypeNameStyle(ITEM_STATE.NORMAL, "cSearchItem_SkypeName_Normal");
	this.SetSkypeNameStyle(ITEM_STATE.HIGHLIGHT, "cSearchItem_SkypeName_Highlight");

	this.SetCountryStyle(ITEM_STATE.NORMAL, "cSearchItem_Country_Normal");
	this.SetCountryStyle(ITEM_STATE.HIGHLIGHT, "cSearchItem_Country_Highlight");
	
	//this.SetAvataStyle(ITEM_STATE.NORMAL, "cItem_Avata_Normal");
	//this.SetAvataStyle(ITEM_STATE.HIGHLIGHT, "cItem_Avata_Highlight");
			
	//this.SetBoxStyle(ITEM_STATE.NORMAL, "cItem_Box_Normal");
	//this.SetBoxStyle(ITEM_STATE.HIGHLIGHT, "cItem_Box_Highlight");

}

SearchItem.prototype.CreateSkypeName = function(eRootName) {

    var ElementStr = eRootName + "SkypeName";
    
    this.SkypeNameLayerIndex = this.LayerArray.length;  
    this.AddTextLayer(ElementStr);
    this.LayerArray[this.SkypeNameLayerIndex].SetReverseDisable(true);
    this.LayerArray[this.SkypeNameLayerIndex].SetIsPlainText(true);
             
}

SearchItem.prototype.CreateFullName = function(eRootName) {

    var ElementStr = eRootName + "FullName";

    this.FullNameLayerIndex = this.LayerArray.length;    
    this.AddTextLayer(ElementStr);    
    this.LayerArray[this.FullNameLayerIndex].SetReverseDisable(true);
    this.LayerArray[this.FullNameLayerIndex].SetIsPlainText(true);    
  
}

SearchItem.prototype.CreateCountry = function(eRootName) {

    var ElementStr = eRootName + "Country";
	alert("SearchItem.CreateCountry = " + ElementStr);
	
    this.CountryLayerIndex = this.LayerArray.length;    
    this.AddTextLayer(ElementStr);    
    this.LayerArray[this.CountryLayerIndex].SetReverseDisable(true);
    this.LayerArray[this.CountryLayerIndex].SetIsPlainText(true);     
  
}

/*
SearchItem.prototype.CreateBox = function(eRootName) {

    var ElementStr = eRootName + "Box";

    this.BoxLayerIndex = this.LayerArray.length;    
    this.AddJPGImageLayer(ElementStr);
		                
}

SearchItem.prototype.CreateAvata = function(eRootName) {

    var ElementStr = eRootName + "Avata";

    this.AvataLayerIndex = this.LayerArray.length;    
    this.AddJPGImageLayer(ElementStr);    
             
}

SearchItem.prototype.SetBoxStyle = function(ItemStateIndex, Style){
    	
	this.BoxStyle[ItemStateIndex] = Style;
    
}

SearchItem.prototype.SetAvataStyle = function(ItemStateIndex, Style){
    	
	this.AvataStyle[ItemStateIndex] = Style;
    
}

*/

SearchItem.prototype.SetFullNameStyle = function(ItemStateIndex, Style){
    	
	this.FullNameStyle[ItemStateIndex] = Style;
    
}

SearchItem.prototype.SetSkypeNameStyle = function(ItemStateIndex, Style){
    	
	this.SkypeNameStyle[ItemStateIndex] = Style;
    
}

SearchItem.prototype.SetCountryStyle = function(ItemStateIndex, Style){
    	
	this.CountryStyle[ItemStateIndex] = Style;
    
}

SearchItem.prototype.GetSkypeName = function(){
    	
    return this.SkypeName;
}

SearchItem.prototype.Normal = function() {
	this.State = ITEM_STATE.NORMAL;
	this.ChangeBG();
	this.ChangeLayerForNormal();
}
/*
SearchItem.prototype.UpNormal = function() {
	
    this.State = ITEM_STATE.NORMAL_UP;
	this.ChangeBG();
	this.ChangeLayerForNormal();
}

SearchItem.prototype.DownNormal = function() {
	
    this.State = ITEM_STATE.NORMAL_DOWN;
	this.ChangeBG();
	this.ChangeLayerForNormal();
}
*/
SearchItem.prototype.Highlight = function() {
	
	this.State = ITEM_STATE.HIGHLIGHT;
	this.ChangeBG();
	this.ChangeLayerForHighlight();
	
}

SearchItem.prototype.ChangeLayerForHighlight = function() {
	
	alert("SearchItem.ChangeLayerForHighlight()");

	//this.LayerArray[this.BoxLayerIndex].SetStyle(this.BoxStyle[ITEM_STATE.HIGHLIGHT]);
	//this.LayerArray[this.BoxLayerIndex].SetImage(g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_HIGHLIGHT_THUMBNALE_BOX);
	//this.LayerArray[this.AvataLayerIndex].SetStyle(this.AvataStyle[ITEM_STATE.HIGHLIGHT]);		
    //this.SetBigDefaultAvata();
	if(this.CheckMarquee(this.SkypeName)>98){
		this.LayerArray[this.SkypeNameLayerIndex].SetStyle("cSearchItem_SkypeName_Highlight_Marquee");
	}else{
		this.LayerArray[this.SkypeNameLayerIndex].SetStyle(this.SkypeNameStyle[ITEM_STATE.HIGHLIGHT]);	
	}
	if(this.CheckMarquee(this.FullName)>76){
		this.LayerArray[this.FullNameLayerIndex].SetStyle("cSearchItem_FullName_Highlight_Marquee");
	}else{
		this.LayerArray[this.FullNameLayerIndex].SetStyle(this.FullNameStyle[ITEM_STATE.HIGHLIGHT]);	
	}
	if(this.CheckMarquee(this.Country)>126){
		this.LayerArray[this.CountryLayerIndex].SetStyle("cSearchItem_Country_Highlight_Marquee");
	}else{
		this.LayerArray[this.CountryLayerIndex].SetStyle(this.CountryStyle[ITEM_STATE.HIGHLIGHT]);		
	}
		
    
    
		
}

SearchItem.prototype.ChangeLayerForNormal = function() {

    alert("SearchItem.ChangeLayerForNormal()");    
	
	//this.LayerArray[this.BoxLayerIndex].SetStyle(this.BoxStyle[ITEM_STATE.NORMAL]);	
	//this.LayerArray[this.BoxLayerIndex].SetImage(g_Image.IMAGE_LIST_MAIN_CONTACT_LIST_ITEM_NORMAL_THUMBNALE_BOX);
	//this.LayerArray[this.AvataLayerIndex].SetStyle(this.AvataStyle[ITEM_STATE.NORMAL]);
	//this.SetSmallDefaultAvata();
    this.LayerArray[this.FullNameLayerIndex].SetStyle(this.FullNameStyle[ITEM_STATE.NORMAL]);	
    this.LayerArray[this.SkypeNameLayerIndex].SetStyle(this.SkypeNameStyle[ITEM_STATE.NORMAL]); 		
	this.LayerArray[this.CountryLayerIndex].SetStyle(this.CountryStyle[ITEM_STATE.NORMAL]);
		

}
SearchItem.prototype.CheckMarquee = function(string) {
	var tempHTML = "<div id='checkmarquee' style='position:absolute'></div>";
	$("#"+this.eID).append(tempHTML);
	$("#checkmarquee").removeClass();
	$("#checkmarquee").html(string);
	var width = $("#checkmarquee").css('width');
	var len= width.indexOf("px");
	var curr_w_int = parseInt(width.substring(0,len));
	alert(string+" : " + width); 
	$("#checkmarquee").remove();
	return curr_w_int;
	
}



SearchItem.prototype.SetItem = function(SearchDataObject) {
	
	alert("SearchItem.SetItem()");

	var Name;


	if(SearchDataObject.SkypeName) {
		
		Name = SearchDataObject.SkypeName;
	}
	else {
		
		Name = DEFAULT_SEARCH_DATA.SkypName;
	}	
	this.SkypeName = SearchDataObject.SkypeName;
	
	this.LayerArray[this.SkypeNameLayerIndex].SetText(Name);
	
	var FullName;

	if(SearchDataObject.FullName) {
		
		FullName = SearchDataObject.FullName;
	}
	else {
		
		FullName = DEFAULT_SEARCH_DATA.FullName;
	}	
	this.FullName = FullName;
	
	this.LayerArray[this.FullNameLayerIndex].SetText(FullName);	
	
	
	var Location;
	var Country;
	var City;
	Country = SearchDataObject.Country;
	City = 	SearchDataObject.City
	if(Country){
		if(City){
			Location = Country + " / " + City;
		}
		else{
			Location = Country;
		}
		
	}
	else{
		if(City){
			Location = City;			
		}
		else{
			Location = "";
		}
	}
	this.Country = Location;	
	this.LayerArray[this.CountryLayerIndex].SetText(Location);	

		
	/*	
	var Avatar;

	if(SearchDataObject.AvataPath) {
		
		Avatar = SearchDataObject.AvataPath;
		this.AvatarType = ENUM_CONTACT_AVATA_TYPE.ONES_IMAGE;
	}
	else {
		
		Avatar = SearchDataObject.AvataPath;
		this.AvatarType = ENUM_CONTACT_AVATA_TYPE.ONES_IMAGE;
	}	
	
	this.LayerArray[this.AvataLayerIndex].SetImage(Avatar);		
	
	*/
	this.ExistData = true;
}


/*
SearchItem.prototype.SetSmallDefaultAvata = function() {
	
	
	if(this.AvataType == CONTACT_AVATA_TYPE.ONES_IMAGE_TYPE){
		return;
	}
	
	var Avata;
	
	switch(this.AvataType) {

		case CONTACT_AVATA_TYPE.PSTN_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_PSTN;	
			break;
		
		case CONTACT_AVATA_TYPE.MALE_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_MALE;	
			break;

		case CONTACT_AVATA_TYPE.FEMALE_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_FEMALE;	
			break;
		
		case CONTACT_AVATA_TYPE.NO_GENDER_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_NO_GENDER;	
			break;
			
		case CONTACT_AVATA_TYPE.TEST_CALL_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_TEST_CALL;	
			break;			

		case CONTACT_AVATA_TYPE.MYSELF_TYPE:		
		default :
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_TEST_CALL;	
			break;	
			
	}
	
	this.LayerArray[this.AvataLayerIndex].SetImage(Avata);
	
}

SearchItem.prototype.SetBigDefaultAvata = function() {
	
	if(this.AvataType == CONTACT_AVATA_TYPE.ONES_IMAGE_TYPE){
		return;
	}
	
	var Avata;
	
	switch(this.AvataType) {

		case CONTACT_AVATA_TYPE.PSTN_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_PSTN_BIG;	
			break;
		
		case CONTACT_AVATA_TYPE.MALE_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_MALE_BIG;	
			break;

		case CONTACT_AVATA_TYPE.FEMALE_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_FEMALE_BIG;	
			break;
		
		case CONTACT_AVATA_TYPE.NO_GENDER_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_NO_GENDER_BIG;	
			break;
			
		case CONTACT_AVATA_TYPE.TEST_CALL_TYPE:
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_TEST_CALL_BIG;	
			break;			

		case CONTACT_AVATA_TYPE.MYSELF_TYPE:		
		default :
			Avata = g_Image.IMAGE_LIST_MAIN_HISTORY_LIST_ITEM_DEFAULT_AVATA_TEST_CALL_BIG;	
			break;	
			
	}
	
	this.LayerArray[this.AvataLayerIndex].SetImage(Avata);
	
}

*/