if(!Life.Flash) Life.Flash = {};
/**
* GNB상단 장소찾기 버튼
*/
Life.Flash.focus = function(){	
	this.context.focus();
};
Life.Flash.PlaceSearchButton = {
	swf : "http://localimg.daum-img.net/life/images/swf/searchbtn.swf",
	
	callBackFunc : function(){		
		if(!Life.Flash.PlaceSearch.inited){
			Life.Flash.PlaceSearch.draw("LifeTopSearch", this.context_path || "");    			
		}			
		
		var page_location = location.pathname;
		var hide_flag = page_location.indexOf("PlaceList.do") != -1 || page_location.indexOf("ThemeList.do") != -1; 
		
		if(Life.Flash.PlaceSearch.opened){
			daum.Element.setPosition(daum.$("LifeTopSearch"), -10000, -10000);
			Life.Flash.PlaceSearch.opened = false;
			
			if(daum.Browser.ff && daum.Browser.ua.indexOf("firefox/3.0") > -1){
				if(daum.$("life_ams") && hide_flag) daum.$("life_ams").style.visibility = "visible";
			}
		}else{
			daum.Element.setPosition(daum.$("LifeTopSearch"), 0, 127);
			
			Life.Flash.PlaceSearch.opened = true;
			
			if(daum.Browser.ff && daum.Browser.ua.indexOf("firefox/3.0") > -1){
				var page_location = location.pathname;
				
				if(daum.$("life_ams") && hide_flag) daum.$("life_ams").style.visibility = "hidden";
			}
		}
	},
	
	draw : function(btnid){
		this.panel = daum.$(btnid);
		this.context = daum.showFlash(this.swf, "30", "70 " , btnid, { flashVars : "clickFunc=Life.Flash.PlaceSearchButton.callBackFunc" });
		this.panel.onmouseover = Life.Flash.focus.bind(this);
	}
};
/**
* 장소찾기 (전체)
*/
Life.Flash.PlaceSearch = {
	//swf : "http://localimg.daum-img.net/life/images/swf/life_search_091210.swf?v=091211",
	swf : "http://localimg.daum-img.net/life/images/swf/place_search.swf",
	mapUrl : "http://place.daum.net/api/RegionAPI.do",
	subMapUrl : "http://place.daum.net/api/RegionAPI.do?rdepth=1&regionid=",
	cateUrl : "http://place.daum.net/api/CategoryAPI.do?lcateid=0",
	subCateUrl : "http://place.daum.net/api/CategoryAPI.do?lcateid=",
	progressBarUrl : "http://localimg.daum-img.net/life/images/swf/Loader.swf",
	draw : function(panelid, context_path){
		this.panelId = panelid;
		this.context_path = context_path || "";
		var closeFlag = "isCloseBtn=false";
		if(this.panelId == "LifeTopSearch") closeFlag = "isCloseBtn=true";		

		this.context = daum.showFlash(this.swf, "978", "270 " , this.panelId, { flashVars : closeFlag +"&amp;mapUrl="+encodeURIComponent(this.mapUrl)+"&amp;subMapUrl="+encodeURIComponent(this.subMapUrl)+"&amp;cateUrl="+encodeURIComponent(this.cateUrl)+"&amp;subCateUrl="+encodeURIComponent(this.subCateUrl)+"&amp;callBackFunc=Life.Flash.PlaceSearch.onSearch&amp;closeFunc=Life.Flash.PlaceSearch.close&progressBarUrl="+ encodeURIComponent(this.progressBarUrl) });
		this.inited = true;
		
		this.panel = daum.$(this.panelId);
		this.panel.onmouseover = Life.Flash.focus.bind(this);
	},
	
	onSearch : function(obj){
		var data = eval("("+ obj +")");
		location.href = this.context_path + "/PlaceList.do?cateid="+ data.cateid +"&pcateid="+ data.pcateid +"&tcateid="+ data.tcateid +"&depth=2&rdepth="+ data.rdepth +"&regionid="+ data.regionid;
	},
	
	close : function(){
		daum.Element.setPosition(daum.$("LifeTopSearch"), -10000, -10000);
		this.opened = false;
		
		if(daum.Browser.ff && daum.Browser.ua.indexOf("firefox/3.0") > -1){
			daum.$("life_ams").style.visibility = "visible";
		}
	}
};
/**
* 많이 찾은 맛집 (카테고리탑)
*/
Life.Flash.BestPlaceList = function(panelId, options){
	this.panel = daum.$(panelId);
	
	this.options = {
		lifetop : false,
		//swf : "http://localimg.daum-img.net/life/images/swf/life_ranking_091210.swf?v=091214",
		swf : "http://localimg.daum-img.net/life/images/swf/place_bestplace.swf?v=091215",
		width : 250,
		height : 245,
		flashvars : {}
	};
	
	daum.extend(this.options, options || {});
	if(this.options.lifetop){
		daum.extend(this.options, {
			//swf : "http://localimg.daum-img.net/life/images/swf/life_rankingTop_091211.swf?v=091215",
			swf : "http://localimg.daum-img.net/life/images/swf/place_bestplace_top.swf",
			width : 250,
			height : 310
		});
	}
	
	this.draw();
};
Life.Flash.BestPlaceList.prototype = {
	draw : function(){
		this.context = daum.showFlash(this.options.swf, this.options.width, this.options.height, this.panel, {
			flashvars : this.getFlashVars()
		});
		this.panel.onmouseover = Life.Flash.focus.bind(this);
	},
	
	getFlashVars : function(){
		var fvars = [];
		
		for(var p in this.options.flashvars) if(this.options.flashvars.hasOwnProperty(p)){
			fvars.push(p+"="+this.options.flashvars[p]);
		}
		
		return fvars.join("&amp;");
	}
};
/**
* 테마리스트바 (카테고리탑)
*/
Life.Flash.ListBar = function(panelId, options){
	this.panel = daum.$(panelId);
	
	this.options = {		
		flashvars : {}
	};
	
	daum.extend(this.options, options || {});
	
	if(this.options.paging){
		this.options.flashvars["pagingFunc"] = this.options.paging+".setPage";
		this.options.flashvars["pageSizeFunc"] = this.options.paging+".setPageSize";
	}
	
	this.initPaging();
	this.draw();
};
Life.Flash.ListBar.prototype = {
	//swf : "http://localimg.daum-img.net/life/images/swf/life_tab_091211.swf?v=091212",
	swf : "http://localimg.daum-img.net/life/images/swf/place_listbar.swf",
	
	initPaging : function(){
		if(!this.options.paging) return false;
		
		this.iconPaging = window[this.options.paging];
		this.iconPaging.onInitialize = this.bindGoFlashPage.bind(this);		
	},
	
	draw : function(){		
		this.context = daum.showFlash(this.swf, 711, 42, this.panel, {
			flashvars : this.getFlashVars()
		});
		this.panel.onmouseover = Life.Flash.focus.bind(this);
	},
	
	bindGoFlashPage : function(){
		for(var i=0,cnt=this.iconPaging.target.length;i<cnt;++i){
			var target = this.iconPaging.target[i];
			daum.addEvent(target,"click",this.goFlashPage.bind(this,i));
		}
	},

	goFlashPage : function(idx){
		this.context.setPaging(idx+1);
	},
	
	getFlashVars : function(){
		var fvars = [];
		
		for(var p in this.options.flashvars) if(this.options.flashvars.hasOwnProperty(p)){
			fvars.push(p+"="+this.options.flashvars[p]);
		}
		
		return fvars.join("&amp;");
	}
};
/**
* 핫쇼핑스트리트 (라이프탑)
*/
Life.Flash.ThemeList = function(panelid, data, tUrl, mapApp, name, tcateid, themecateid, bigElement){
	this.panel = daum.$(panelid);
	this.data = data;
	this.name = name;
	this.mapApp = mapApp;
	this.tcateid = tcateid;
	this.themecateid= themecateid;
	this.bigmapElement=bigElement;
	
	this.tUrl = tUrl || this.tUrl;
	this.placeMarkers = [];
	
	this.draw();
};
Life.Flash.ThemeList.prototype = {
	//swf : "http://localimg.daum-img.net/life/images/swf/life_hotshopping_091210.swf?v=091211",
	swf : "http://localimg.daum-img.net/life/images/swf/place_themelist.swf",
	tUrl : "api/TopSectionThemeAPI.do",
	
	setThemeData : function(data, className){
		this.clear();
		if(this.context){
			this.context.setTData(data);
			if(className=="foodStreet"){
				this.tcateid = 1;
				this.themecateid = 237;
			}
			else{
				this.tcateid = 3;
				this.themecateid = 239; 
			}
		}
	},
	
	getCropImage : function(url){
		url = daum.String.trim(url);		
		if(url.indexOf("/image/") > -1){
			return url.replace("/image/", "/C76x66/");
		}else{
			if(url == ""){
				url = "http://localimg.daum-img.net/life/images/common/noimg_76_66.gif";
			}
			
			return url;
		}
	},
	
	getLocalDatas : function(data, seq){		
		this.clear();
		var parsed = eval(data);
		
		this.data = parsed;
		var points = [];
		this.bigmapElement.href="theme/MapTop.do?tcateid="+this.tcateid+"&cateid="+this.tcateid+"&themecateid="+this.themecateid+"&themeid="+seq+"&sort=update"+"&cpage="+this.cpage;

		for(var i=0,loop=this.data.length; i<loop; i++){
			var dpoint = new DPoint(this.data[i].pointX, this.data[i].pointY);
			this.data[i].placeurl = "place/Top.do?confirmid="+ this.data[i].confirmid;
			this.data[i].point = dpoint;
			this.data[i].enc_placename = escape(this.data[i].placename);
			this.data[i].placename = daum.String.cutString(this.data[i].placename, 22, "..");
			this.data[i].photourl = this.getCropImage(this.data[i].photourl);			
			this.data[i].summaryshort = daum.String.cutString(this.data[i].summary, 26, "..");
			this.data[i].pointurl = "place/PointView.do?confirmid="+ this.data[i].confirmid;
			this.data[i].photolisturl = "place/PhotoList.do?confirmid="+ this.data[i].confirmid;
			
			var mark = new PlaceMarker(dpoint, {
				icon : MapApplication.Icons["PLACE_SMALL"],
				data : this.data[i],
				baseLevel : 3,
				placeWindowTemplate : MapApplication.Icons["PLACE_WINDOW_PHOTO"],
				templateOffset : new DPoint(-135, -141)
			});

			mark.drawMark(this.mapApp.maps);
			mark.hotShopObserver = DEvent.addListener(mark.mark, "click", this.onPlaceMarkClick.bind(this, i));
			
			points.push(dpoint);
			this.placeMarkers.push(mark);
			
			//daum.$("loadingMap").style.display = "none";
		};

		this.getClickIndex(0);
		this.context.selectSubMenuText(0);
	},
	getClickIndex : function(idx){
		this.placeMarkers[idx].onMarkClick();
	},
	
	onPlaceMarkClick : function(i){
		this.context.selectSubMenuText(i);		
	},
	
	draw : function(){
		this.context = daum.showFlash(this.swf, "262", "373", this.panel, {
			flashVars : "localFunc="+this.name+".getClickIndex&localsFunc="+this.name+".getLocalDatas&tdata="+this.data+"&tUrl="+this.tUrl
		});
		this.panel.onmouseover = Life.Flash.focus.bind(this);
		
	},
	
	clear : function(){
		if(this.placeMarkers){
			for(var i=0,loop=this.placeMarkers.length; i<loop; i++){
				DEvent.removeListener(this.placeMarkers[i].mark, "click", this.placeMarkers[i].mark.hotShopObserver); 
				this.placeMarkers[i].destroy();
			}
			this.placeMarkers = [];
		}
		
		this.data = [];		
	}
};
