var curSaleType = "S"; 	
var topSaleTypeClick = function(thisObj, type){
	var aType = ['S', 'L']; 
	var obj = thisObj.parentNode.getElementsByTagName('a'); 
	for( var i=0; i<obj.length; i++){
		obj[i].className = obj[i].className.replace('_on', '');
	}
 
	thisObj.className = thisObj.className + '_on'; 
	
	for( var i=0; i<aType.length; i++){
		UI.$(aType[i]+ "_siseRate1").style.display = "none"; 
		UI.$(aType[i]+ "_siseRate2").style.display = "none";
	}

	if( type!="R"){
		UI.$(type+ "_siseRate1").style.display = "block"; 
		UI.$(type+ "_siseRate2").style.display = "block";
	}
	if( type !="S"){
		UI.$("BTypeDisabled").className = "B1 B1_off";
		UI.$("CTypeDisabled").className = "C5 C5_off";
	}else{
		UI.$("BTypeDisabled").className = "B1";
		UI.$("CTypeDisabled").className = "C5";
	}
	curSaleType = type;
	dummyUrlCall('topNavi'); 
}

var maemulNaviGo = function(type, catecode){
	if( catecode == "B1"){
		if( UI.$("BTypeDisabled").className.indexOf('_off') != -1){
			return false;
		}
	}else if( catecode=="C9"){
		if( UI.$("CTypeDisabled").className.indexOf('_off') != -1){
			return false;
		}
	}
	var code2 = catecode ;
	if( catecode == 'A1'){
		code2 = 'A1A3A4'; 
	}
	if( type == 'area'){
		document.location.href = "/maemul/area/*/" + catecode + "/"+ code2 +"/"+curSaleType+"/summary";
	}else{
		document.location.href = "/maemul/subway/" + catecode + "/A1/A1A3A4/"+curSaleType+"/*/summary";
	}	
}

var subwayNaviGo = function(thisObj, type){
	document.location.href = "/maemul/subway/"+type+"/A1/A1A3A4/"+curSaleType+"/*/summary";
}	

var siseNaviGo = function(catecode){
	var code2 = catecode ;
	if( catecode == 'A1'){
		code2 = 'A1A3A4'; 
	}
	document.location.href = "/maemul/area/*/"+ catecode + "/" + code2 +"/"+curSaleType+"/localinfo?&nil_profile=estatetop&nil_localtap=sise"; 
}

var flashTopRate = function(count,date,rateTotal,rateSeoul,rateMetro,rateNewtown){
	var url = location.href;
	DaumFlash("http://fn.daum-img.net/flash/estate/2008/top/GraphWeeklySise2009june30.swf",count + date + rateTotal+ rateSeoul + rateMetro + rateNewtown,223,158,"TopMaemulChartLayer");
}

var themeTooltip =  function(theme, area){
	this.themeLabel = theme.label; //UI.$("themeName");
	this.themeLayer = theme.layer; //UI.$("themeListOuter");
	this.areaLabel = area.label; //UI.$("themeName");
	this.areaLayer = area.layer;// UI.$("themeAreaListOuter");
}

/* 테마로 찾는 매물 - 검색 레이어 */
themeTooltip.prototype = {
	showThemeList : function(){
		if( this.themeLayer.style.display == "none"){
			this.block( this.themeLayer, this.themeLabel);
			this.none( this.areaLayer, this.areaLabel);
		}else{
			this.none( this.themeLayer, this.themeLabel);
		}
	}, 
	
	showAreaList : function(){
		if( this.areaLayer.style.display == "none"){
			this.block( this.areaLayer, this.areaLabel);
			this.none( this.themeLayer, this.themeLabel);
		}else{
			this.none( this.areaLayer, this.areaLabel);
		}
	}, 
		
	none: function(obj, label){
		obj.style.display = "none"; 
		label.style.backgroundPosition = "right 0";
	}, 
	
	block : function(obj, label){
		obj.style.display = "block"; 
		label.style.backgroundPosition = "right -33px";
	}
}	

/* 테마로 찾는 매물 - 테마및 지역 변경시 매물 재검색  */
var homeThemeMaemul = function(_data ,_index)
{
	this.data = _data;
	this.index = _index;
	that = this;
};
 
homeThemeMaemul.prototype = {
	load: function (_dataurl, themeIdx)
	{
		this.index = themeIdx-1;
		var dataloader = new FN.Ajax({url:_dataurl, onComplete:this.onDataLoadComplete});
		dataloader.send();
	},
	onDataLoadComplete: function (req)
	{
		var arr = eval("("+req.responseText+")" );
		that.refreshData(arr);
	
	},
	refreshData: function (_data){	
		this.target = UI.$('danjiList');		
		this.target.innerHTML = "";
 
		var str = ""; 
 
		if(_data.length > 0){
    		for(var i = 0; i < _data.length; i++){			
    			if( i< 5){
		    		if( i == 4){
		    			str += '<li class="last">';
		    		}else {
		    			str += '<li>';
		    		}
	    			if(_data[i].danjiname.length > 8)
	    				var danjiname = _data[i].danjiname.slice(0,8)+"..";
	    			else
	    				var danjiname = _data[i].danjiname;
	    								 
					str += '<span class="danji"><a href="/maemul/detail/'+ _data[i].mid + '?' + themeNilTag[this.index] + 'maemul">'+danjiname+'</a></span>'; 
					str += ' <span class="fs_small gray_b1 ls_m1">' + _data[i].area + '</span> <br>'; 
					str += '<span title="' + calcPeung(_data[i].size) + '">' + _data[i].size + '㎡</span> <em class="bar">|</em> ' + UI.addComma(_data[i].cost) + '만원</li>';
				}	
			}	
			this.target.innerHTML = str;
	 	}else{	
			this.target.innerHTML = "<li style='border:none;'>관련 테마매물이 없습니다.</li>";
		}
	}
}; 

function changeThemeIndex(type, vactor ){
	var loadurl = "";
	if( type == 'a'){
		UI.$('themeListOuter').style.display = "none";	
		
		themeIndex = vactor-1;
		UI.$("themeName").innerHTML = themeData[themeIndex].themeaname;
		UI.$("themeName").style.backgroundPosition = "right 0";
	}else{
		UI.$('themeAreaListOuter').style.display = "none";
		areaIndex = vactor; 
		UI.$("areaName").style.backgroundPosition = "right 0";
		for( var i=0; i< areaData.length; i++){
			if( areaData[i].code == areaIndex ){
				UI.$("areaName").innerHTML = areaData[i].name; 
				break;
			} 
		}
		}
		UI.$('themeMoreLink').href = "/maemul/area/"+areaIndex+"/"+themeData[themeIndex].catecode+"/"+themeData[themeIndex].catecode+"/"+themeData[themeIndex].saletypecode+"/maemullist?themeId=" + themeData[themeIndex].themeId; 
	
	loadurl = "/maemul/MaemulTopThemeMaemulList.daum?catecode="+themeData[themeIndex].catecode+"&themeId="+themeData[themeIndex].themeId+"&saletype="+themeData[themeIndex].saletype+"&areacode="+areaIndex+ "&" + themeNilTag[themeIndex];
	themeSearch.load(loadurl, themeIndex);
}

function getAreaList(ele){
	var obj = UI.$(ele);
	
	var str = '';
	for( var i=0; i<areaData.length; i++){
		str += '<li onmouseover="bgOver(this, \'#efeff1\');" onmouseout="bgOver(this,\'#fff\');"  onclick=\'changeThemeIndex("b", "'+ areaData[i].code +'");return false;\'><a href="#" class="" >'+ areaData[i].name +'</a></li>';
	}
	obj.innerHTML = str; 
	//document.write(str);
}

var themeNilTag = ['nil_profile=estatetop&nil_estatetop=3yearmaemul', 'nil_profile=estatetop&nil_estatetop=subway500mmaemul','nil_profile=estatetop&nil_estatetop=cheapofficemaemul',
				   'nil_profile=estatetop&nil_estatetop=quickReconstructionmaemul', 'nil_profile=estatetop&nil_estatetop=newlywedhomemaemul', 'nil_profile=estatetop&nil_estatetop=universityoneroonmaemul',
				   'nil_profile=estatetop&nil_estatetop=jumpomaemul', 'nil_profile=estatetop&nil_estatetop=freedomlandmaemul']; 

function goThemeLink(url, idx){
	document.location.href = url + "?" + themeNilTag[idx];
}

function bgOver(thisObj, color){
	thisObj.style.background = color;
}

function themeClose(event){
	var e = event ? event : window.event;
	var element = e.target || e.srcElement;
	while(element && element.tagName != "BODY"){
		if( element == UI.$('themeListOuter') || element == UI.$('themeName') || element == UI.$('themeAreaListOuter') || element == UI.$('areaName') ){
			return;
		}
		element = element.parentNode; 
	}
	UI.$('themeListOuter').style.display = "none";
	UI.$("themeName").style.backgroundPosition = "right 0";
	UI.$('themeAreaListOuter').style.display = "none";
	UI.$("areaName").style.backgroundPosition = "right 0";
}
