// JavaScript Document
if(typeof txmap=='object'){
}else{
	var txmap={};
}
function tx_map(param){//构造函数
	_this = this;	

	//配置参数, roolTime->滚动间隔时间,为0则不滚动, first_index->第一个下标, 如果需要添加用户的位置,则给用户配置'-1'下标. max_zoom->最大缩放级别, 在bound自伸缩的时候,最好设置一个最大伸缩级别,防止过大很盲目, fixed_zoom 固定缩放级别, "error_dom_id"显示错误的Dom, "all_markers"地图所有的点, setmark_key用来设置显示all_markers下的哪些下标里的内容, no_icon是否需要地图默认标点, default_status:中心的默认的状态
	_this.config = {"rollTime": 5000, //滚动间隔时间,设置为0后不滚动
		"first_index":0, //第一个点的下标,在一些情况下,个人当前位置也要在地图显示,但是在处理逻辑的时候不会随其他点一起处理
		"max_zoom":15, //最大缩放级别,因为有些时候缩放级别过大也不是一件好事
		"min_zoom":2,
		"default_center":[39.917, 116.397], //默认中心点,当错误数据或者没有中心点时候
		"map_dom_id":"map_container", //初始化地图的标签ID
		"map_search_list_id":"map_search_list", //搜索结果在哪个标签里列出
		"add_panel":{"distance":false, "tray":false, "local_parse":true}, //添加哪些面板
		"fixed_zoom":0,	//是否固定缩放级别
		"error_dom_id":"error_txmap", //显示错误的标签
		"all_markers":{}, //地图所有点
		"setmark_key":["latitude", "longitude", "label", "view"], //当运行set_markers_on_map的时候,提取数据的对应下标
		"no_icon":false, //是否需要地图上的标记点
		"default_status":{"view":"暂无内容"},//中心点的基本属性
		"markers_extend":true,//是否需要自动包括所有点,计算缩放级别
		"enable_wheel_zoom":false,
		"HierarchicalMap":true,
		"db_status_total":10 //当前条件数据总数
	};
	//如果存在all_markers的一个全局函数,则存入_this.config.all_markers
	if (window.all_markers) _this.config.all_markers = window.all_markers;
	//alert(param.)
	for (var k in param) {
		if (param[k]!='undefined') {
			_this.config[k] = param[k];
		}
	}	
	if (_this.config.default_center[0]=='' || _this.config.default_center[1]=='' || Math.abs(_this.config.default_center[0])>90 || Math.abs(_this.config.default_center[1])>180) {
		_this.config.default_center = [39.917, 116.397];
	}
	_this.now_marker = _this.config.first_index;
	_this.markers_on_map = []; //当前所有点信息存储于此数组
	_this.page = 1;
	_this.page_size = 10;
	_this.map = new google.maps.Map2(document.getElementById(_this.config.map_dom_id));
	_this.map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 30)));	
	_this.map.removeMapType(G_HYBRID_MAP);
	_this.map.addMapType(G_PHYSICAL_MAP);	
	//_this.map.setMapType(G_PHYSICAL_MAP);
	//为探宝活动准备
	if(typeof _this.config.act=='function'){
		_this.map.setMapType(G_NORMAL_MAP);
		_this.config.act(_this);
	}
	if (_this.config.enable_wheel_zoom){
		_this.map.enableScrollWheelZoom(); //滚轮可使用
	}

	//指定关系后添加控件
	if (_this.config.HierarchicalMap) {
		//var mapControl = new GHierarchicalMapTypeControl();	
		//_this.map.addControl(mapControl, new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 30))); //卫星，混合地图
		_this.map.addMapType(G_SATELLITE_MAP);
	}		

	if (_this.config.add_panel) {
		for (var k in _this.config.add_panel) {
			if (_this.config.add_panel[k]) {
				_this.add_panel(k);
			}
		}		
	}	

	_this.baseIcon = new GIcon();
	if (!_this.config.no_icon) {
		_this.baseIcon.image = "http://site.tongxueimg.com/t/images/place/default_marker.png?v=2"; 
	}
	//_this.baseIcon.shadow = "/images/shadow50.png";
	_this.baseIcon.iconSize = new GSize(24, 24);
	//_this.baseIcon.shadowSize = new GSize(37, 34);
	_this.baseIcon.iconAnchor = new GPoint(12, 24);
	_this.baseIcon.infoWindowAnchor = new GPoint(12, 24);
	//_this.baseIcon.infoShadowAnchor = new GPoint(0, 7);
	
	//_this.map.setCenter(new GLatLng(39.917, 116.397), 12); //设置地图中心
	_this.newZIndex = 0; //初始层的z-index, hack for labeledmarker
	//_this.set_markers_to_map();
	//_this.map_initial_status();
	//鼠标停留在地图区域的时候,停止滚动
	GEvent.addListener(_this.map, "click", function(point){
		_this.map.enableScrollWheelZoom();
	});
	GEvent.addListener(_this.map, "drag", function(point){
		_this.map.enableScrollWheelZoom();
	});	
	GEvent.addListener(_this.map, "mouseover", function(point){
		if (_this.rollInterval){clearInterval(_this.rollInterval);}
	});
	GEvent.addListener(_this.map, "mouseout", function(point){
		if (!_this.config.enable_wheel_zoom){
			_this.map.disableScrollWheelZoom();
		}
		_this.roll();
	});
	//google.load("search", "1");
	//var loc = google.loader.ClientLocation;
}
//添加类似google使用的HierarchicalMap插件
tx_map.prototype.addHierarchicalMap = function(){
	if (typeof _this.extLargeMapControl2 !='undefined'){
		return ;
	}
	var opts2 = {
	          zoomInBtnTitle : "放大",
	          zoomOutBtnTitle : "缩小",
	          moveNorthBtnTitle : "向上平移",
	          moveSouthBtnTitle : "向下平移",
	          moveEastBtnTitle : "向右平移",
	          moveWestBtnTitle : "向左平移",
	          homeBtnTitle : "返回上一结果"
	};
	_this.extLargeMapControl2 = new ExtLargeMapControl(opts2);

	if (_this.config.add_panel.local_parse) {
		_this.map.addControl(_this.extLargeMapControl2, new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 30)));	
	}else{
		_this.map.addControl(_this.extLargeMapControl2);
	}
};
//增加面板
tx_map.prototype.add_panel = function(panel_name) {
	var funcName = "_this.add_"+panel_name+"_panel";
	try {  
		var t = eval(funcName);
        if(typeof(t)=="function") {
			t();
        }
	} catch(e) {
		//alert("not function"); 
    }  
}
//增加对应的面板
tx_map.prototype.add_distance_panel = function() {
	/** 初始化标尺控件 */
	function GDistancePanel() {
			me = this;
			//me.BACKGROUND_IMAGE_ = 'dot1_p.png';				 
	}	
	GDistancePanel.prototype = new GControl();
	GDistancePanel.prototype.initialize = function(map) {
		var container = document.createElement('div');
		me.map_ = map;
		me.setButtonStyle_(container);
		// “距离”面板
		var btnDistance = document.createElement('div');
		me.distance_panel = btnDistance;
		btnDistance.width = 80;
		btnDistance.height = 19;
		btnDistance.title = "距离";
		btnDistance.innerHTML = "距离";  
		container.appendChild(btnDistance);
		
		// 初始化内部变量
		map.rulerControl_ = me;
		map.getContainer().appendChild(container);
		return container;
	}
	GDistancePanel.prototype.get_panel = function() {
		return me.distance_panel;
	}
	/** 设置控件的格式 */
	GDistancePanel.prototype.setButtonStyle_ = function(button) {
	  button.style.background = '#FFF url(' + this.BACKGROUND_IMAGE_ + ')';
	  button.style.border = '1px solid #888888';
	  button.style.padding = '3px';
	  button.style.textAlign = 'left';
	  $(button).css("font-size", '12px');
	}
	/** 返回控件的默认位置 */
	GDistancePanel.prototype.getDefaultPosition = function() {
	  	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 5));
	}
	var distanceControl = new GDistancePanel(); 
	_this.map.addControl(distanceControl);
	_this.distance_panel = distanceControl.get_panel();
}
tx_map.prototype.add_tray_panel = function() {
	/** 初始化标尺控件 */
	function GTrayPanel() {
			me = this;
			//me.BACKGROUND_IMAGE_ = 'dot1_p.png';				 		
	}
	GTrayPanel.prototype = new GControl();
	GTrayPanel.prototype.initialize = function(map) {
		var container = document.createElement('div');
		$(container).css("width", "100%");
		me.map_ = map;
		me.tray_panel = document.createElement('div');	
		container.appendChild(me.tray_panel);
		$(me.tray_panel).addClass("tray_panel");
		me.init_panel_html();
		// 初始化内部变量
		map.getContainer().appendChild(container);
		return container;
	}
	GTrayPanel.prototype.init_panel_html = function() {
		$(me.tray_panel).html('<div class="tray_panel_opacity"></div><div class="tray_panel_avatar_box" id="tray_panel_avatar_box"><div class="tray_panel_avatar" id="tray_panel_avatar"></div></div><a href="javascript:void(0)" class="tray_panel_left" id="tray_panel_left" onclick="txmap.userphotoRoll.left()"></a><a href="javascript:void(0)" id="tray_panel_right" class="tray_panel_right" onclick="txmap.userphotoRoll.right()"></a>');
	}
	//获得面板内容
	GTrayPanel.prototype.get_panel_html = function() {
		//me.tray_panel.html("11");
		//ajax获得要得到的内容.
	}
	GTrayPanel.prototype.get_panel = function() {
		return me.tray_panel;
	}
	/** 返回控件的默认位置 */
	GTrayPanel.prototype.getDefaultPosition = function() {
	  	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0, 35));
	}

	var trayControl = new GTrayPanel(); 
	_this.map.addControl(trayControl);
	_this.tray_panel = {"dom":trayControl.get_panel(), "obj":trayControl};
}
tx_map.prototype.add_local_parse_panel = function(){
	/** 初始化标尺控件 */
	var me;
	function GLocalParse() {
			me = this;
			//me.BACKGROUND_IMAGE_ = 'dot1_p.png';				 		
	}
	GLocalParse.prototype = new GControl();
	GLocalParse.prototype.initialize = function(map) {
		var container = document.createElement('div');
		$(container).css("width", "100%");
		me.map_ = map;
		me.local_parse_panel = document.createElement('div');	
		container.appendChild(me.local_parse_panel);
		$(me.local_parse_panel).addClass("local_parse_panel");
		me.init_panel_html();
		// 初始化内部变量
		map.getContainer().appendChild(container);
		GEvent.addListener(map, "moveend", me.parse);/**/
		return container;
	}
	GLocalParse.prototype.parse = function() {
		var geocoder = new GClientGeocoder();
		geocoder.getLocations(me.map_.getCenter(), me.parse_point);
	}
	GLocalParse.prototype.parse_point = function(response) {
		var place;
		if (!response || response.Status.code != 200) {
     		me.update_panel_html("抱歉，地图中心点位置无法解析");
	    } else {
	      	//place = response.Placemark[0];
	      	places = _this.analyse_g_points_place(response.Placemark);
	      	var len = places.length;
	      	var i;
	      	var bound = _this.map.getBounds();
	      	var temp_ne, temp_ws;
	      	for(i=len-1;i>-1;i--){
	      		temp_ne = new GLatLng(places[i]['north'], places[i]['east']);
	      		temp_ws = new GLatLng(places[i]['south'], places[i]['west']);
	      		if(bound.containsLatLng(temp_ne)&&bound.containsLatLng(temp_ws)){
	      			place = places[i];
	      			break;
	      		}
	      	}
	      	if (!place){
	      		place = places[0];
	      	}
	      	me.update_panel_html("地图中心点位于 <b>"+place.address+"</b> 附近");
	      	var show_city;
	      	if ($("#search_city_showbox").length>0){
	      		if (place.place_std){
		      		for(var t in place.place_std){
		      			show_city = place.place_std[t];
		      			if (t == 'DependentLocalityName'){ //区的名称
		      				break;
		      			}
		      		}
	      		}else{
	      			show_city = place.address;
	      		}
	      		$("#search_city_showbox").html(show_city);
	      	}
	    }
	}
	GLocalParse.prototype.update_panel_html = function(html) {
		$(me.local_parse_panel).find("#local_parse_panel_box").html(html);
	}
	GLocalParse.prototype.init_panel_html = function() {		
		$(me.local_parse_panel).html('<div class="local_parse_panel_opacity"></div><div class="local_parse_panel_box" id="local_parse_panel_box"></div>');
	}
	//获得面板内容
	GLocalParse.prototype.get_panel_html = function() {
		//me.tray_panel.html("11");
		//ajax获得要得到的内容.
	}
	GLocalParse.prototype.get_panel = function() {
		return me.local_parse_panel;
	}
	/** 返回控件的默认位置 */
	GLocalParse.prototype.getDefaultPosition = function() {
	  	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
	}

	var localParse = new GLocalParse(); 
	_this.map.addControl(localParse);
	_this.localParse = {"dom":localParse.get_panel(), "obj":localParse};
}
//传递地址进行解析 之前使用的geo搜索, 现在使用local_search
tx_map.prototype.address_parse = function(search_address) {
	//if (!_this.geocoder) 
		//_this.geocoder = new GClientGeocoder();
	//_this.search_status = 1;  //记录是否有返回值
	//_this.geocoder.getLocations(search_address, _this.addAddressToMap);
	_this.local_search(search_address);
}
//本地搜索,这个需要加载google.load("search", "1"); 为pick_place.php准备,如果其他地方有用到,需做整理
tx_map.prototype.local_search = function(search_address) {
	var searcher = new google.search.LocalSearch();
	searcher.setResultSetSize(google.search.Search.LARGE_RESULTSET);	
	//searcher.setQueryAddition("category:All|餐饮‎|购物|住宿|出游|娱乐|服务|教育|‎健康|‎企业|‎国家机构|其他");
	searcher.setCenterPoint(_this.map); //该参数可以传递很多类型
	searcher.setSearchCompleteCallback(null, _this.local_search_callback,[searcher]);
	//searcher.gotoPage(2);
	searcher.execute(search_address);
}
/**
 *本地搜索的处理函数 搜索最多8个结果,不足的周边搜索补足
 *此结果集会有2种形式，因为关键字搜索，首先默认添加当前地图作为影响，意义为尽量在当前地图附近搜索关键字，
 *当此形式没有结果的时候，进行一次全球搜索，例如 在北京地图的时候，搜索歐悅設計股份有限公司 第一种是搜不到的，之后做一次全球搜索补充 
 */
tx_map.prototype.local_search_callback = function(searcher){
	var hoop_search, hoop_results, hoop_viewport;
	var search_type=true; //记录当前搜索类型，true：关键字本地搜索
	if (searcher.results){
		hoop_search = searcher;
		hoop_viewport = searcher.resultViewport;
	}else{
		hoop_search = searcher.responseData;
		hoop_viewport = hoop_search.viewport;
		search_type = false; //关键字全球搜索
	}

	if (!search_type && (hoop_search.results.length==0 )){
		alert("抱歉， 我们无法帮您解析该地址，您可以重新修改地址,请尽量精确");
		return ;
	}

	if (hoop_search.results[0]){
		//如果为第一页, 则清空地图状态
		if (typeof hoop_search.cursor=='undefined' || hoop_search.cursor.currentPageIndex == 0) {
			_this.clear_all();	
		}
		var points = [];
      	var o = hoop_search.results;
      	var address_array = [];
      	var temp_join = null;
      	
      	for(var j=0;j<_this.markers_on_map.length;j++){
			points.push(_this.markers_on_map[j][3]);
			address_array.push(_this.markers_on_map[j][3]['address']);
			delete _this.markers_on_map[j];
		}		
		
		var rest_l = points.length;
		var res = rest_l;

		if (res<10){
			for(var i=rest_l;i<o.length+rest_l;i++){
				var k=i - rest_l;
				
				if (typeof o[k].addressLines !='undefined') {
					temp_join = join_address(o[k]);
					if ($.inArray(temp_join, address_array)==-1){
			      			tem={};
			      			
			      			tem.address = temp_join;
							//tem.list_title = o[k].title;
							tem.AddressLine= o[k].title.replace(/<\/?.+?>/g,"");
							tem.Accuracy=o[k].accuracy;
							tem.lat=o[k].lat;
							tem.lng=o[k].lng;
							tem.streetAddress = o[k].streetAddress;
							tem.CountryName=o[k].country;	
							points.push(tem);
							res++;
						if (res>9) break;
					}
				}
			}
		}
      	_this.set_markers_to_map(points,'lat','lng','address','address', true);
      	
      	/**在以下情况下，不进行下一次查询，初始化地图
      	 * 1 localsearch api搜索，结果少的时候，不带cursor属性
      	 * 2 如果已经进行了下一页搜索，因为考虑到优化的问题，搜索次数过多，前端页面过慢
      	 * 3 搜索结果只有1页，就没必要进行下一页搜索，不过貌似不精确
      	 * 4 当前返回结果不满8条（当前使用的是最大结果集，google提供2种，4条结果或者8条结果），就没必要进行下一页了
      	 * 
      	 * 全球搜索，没做下一页搜索 
      	 */
      	if (typeof hoop_search.cursor=='undefined' || hoop_search.cursor.currentPageIndex >= 1 || hoop_search.cursor.pages.length==1 || hoop_search.results.length<8 || !search_type) {
			_this.map_initial_status();
			//当非第一页的时候，才根据返回的区域进行固定地图，第二页以上，因为有2个返回范围，上一步骤中直接自适应了
			if (typeof hoop_search.cursor=='undefined' || hoop_search.cursor.currentPageIndex==0){
				bounds = new GLatLngBounds();
				bounds.extend(new GLatLng(hoop_viewport.ne.lat, hoop_viewport.ne.lng));
				bounds.extend(new GLatLng(hoop_viewport.sw.lat, hoop_viewport.sw.lng));
				var boundZoom = _this.map.getBoundsZoomLevel(bounds);//获得缩放级别
			}

			_this.map.setCenter(bounds.getCenter(), boundZoom);
			_this.update_map_list_dom();
      	}
      	
      	//如果小于10的数量,则解析补充，对于搜索框的搜索，可以先做一次关键词搜索，不符合条件者则进行localsearch进行补全
      	if (_this.markers_on_map.length<10){
      		if (typeof hoop_search.cursor!='undefined' && hoop_search.cursor.pages.length>1 && hoop_search.results.length==8 && typeof hoop_search.gotoPage == 'function') {
      			hoop_search.gotoPage(1);
      		}else{
				_this.search_around();	
      		}
      	}else{
      		return ;
      	}
	}else{ //如果不存在的话,再进行geo解析
		if(google_key){ key=google_key;}
		//mapspan = _this.map.getBounds().toSpan().toUrlValue();
		url='http://www.google.com/uds/GlocalSearch?key='+key+'&v=1.0&rsz=large&sll=0,0&sspn=90,180&q='+hoop_search.Rf+'&lssrc=lsc&lscstyle=final&start='+0+'&callback=_this.local_search_callback';
		$('head').append('<script src="'+url+'" type="text/javascript"></script>');
	}
}

//测试google地图解析
tx_map.prototype.addAddressToMap = function(response) {
    if (!response || response.Status.code != 200) {
    	_this.search_status = 0;
     	alert("抱歉， 我们无法帮您解析该地址，您可以重新修改地址或者手动指定地图位置");
    } else {
		_this.clear_all();
      	places = response.Placemark;
		
      	places = _this.analyse_g_points(places);
		//alert(places[0].AddressDetails.Country.CountryName)
      	_this.set_markers_to_map(places, 'lat', 'lng', 'address', 'address');
      	_this.map_initial_status();
      	_this.update_map_list_dom();
    }
    _this.local_search(response.name);	
}
//搜索周围, start为第几页, zoom1和zoom2是为banding的drag, move服务的,没用
tx_map.prototype.search_around = function(zoom1, zoom2, start) {
	var newpoint=_this.map.getCenter();
	var _lat=newpoint.lat();
	var _lng=newpoint.lng();
	var key='';	
	if (typeof start =='undefined') {
		start = 0;
	}
	var sspn = _this.map.getBounds().toSpan().toUrlValue();
	if(google_key){ key=google_key;}
	_this.start = start;

	//mapspan = _this.map.getBounds().toSpan().toUrlValue(); 
	url='http://www.google.com/uds/GlocalSearch?key='+key+'&v=1.0&rsz=large&sll='+_lat+','+_lng+'&sspn='+sspn+'&q=%20'+encodeURIComponent('category:All|房地产|餐饮‎|购物|住宿|出游|娱乐|服务|教育|‎健康|‎企业|‎国家机构|其他')+'&lssrc=lsc&lscstyle=final&start='+start+'&callback=_this.search_around_callback';
	$('head').append('<script src="'+url+'" type="text/javascript"></script>');
};
tx_map.prototype.search_around_callback=function(d){
		var points=[];
		var o=d.responseData.results;
		var map_bounds = _this.map.getBounds();	
		var address_array = [];	
		
		//alert(o.length)
		for(var j=0;j<_this.markers_on_map.length;j++){
			//当鼠标移动的时候，只保留留地图视野内的点，但是在搜索第二页关键字的时候，会有问题
			if (map_bounds.containsLatLng(_this.markers_on_map[j][0].getLatLng())){
				points.push(_this.markers_on_map[j][3]);
				address_array.push(_this.markers_on_map[j][3]['address']);
			}
		}		
		var rest_l = points.length;
		var res = rest_l;
		if (res<10){
			_this.clear_all();
			for(var i=rest_l;i<o.length+rest_l;i++){
				var k=i - rest_l;
				if (typeof o[k].addressLines !='undefined' &&  map_bounds.containsLatLng(new GLatLng(o[k].lat, o[k].lng))) {
					var temp_address = join_address(o[k]);
					if ($.inArray(temp_address, address_array)!=-1){
						continue;
					}
					var tem = {};		
					tem.address=temp_address;
					//tem.list_title = o[k].title;
					tem.AddressLine= o[k].title.replace(/<\/?.+?>/g,"");
					tem.Accuracy=o[k].accuracy;
					tem.streetAddress=o[k].streetAddress;
					tem.lat=o[k].lat;
					tem.lng=o[k].lng;
					tem.CountryName=o[k].country;	
					points.push(tem);
					res++;
					if (res>9) break;
				}
			}
		} else {
			return ;	
		}
      	defaultmap.set_markers_to_map(points,'lat','lng','address','address', true);
      	defaultmap.update_map_list_dom();
      	//如果不足10个,且当前解析次数不大于3次,且确定当前页有返回结果
      	if (res<10 && (_this.start<3) && d.responseData.results.length!=0) {
      		_this.search_around(null, null, _this.start+1);
      	}
}
//整理google返回的地址解析数据
tx_map.prototype.analyse_g_points = function(places) {
	p = [];
	for(k in places) {
		p[k] = {};
		b = [];
		b[0] = places[k];
		i1 = i2 = 0;
		do {
			for(t in b[i1]){
				if (typeof b[i1][t] =="object" || typeof b[i1][t]=="array") {
					if (t == "coordinates") {
						p[k]['lng'] = b[i1][t][0];
						p[k]['lat'] = b[i1][t][1];
					} else if (t =="AddressLine") {
						p[k]['AddressLine'] = b[i1][t][0];
					} else {
						i2 = i2+1;
						b[i2] = b[i1][t];
					}
				} else {
					 p[k][t] = b[i1][t];
				}
			}
			delete b[i1];
			i1++;
		} while (b[b.length-1]);
	}
	return p;
	
}

//绑定点的事件
tx_map.prototype.bindMarkerEvent = function(index, event) {
	if (!event) { event = "click"; }
	GEvent.addListener(_this.markers_on_map[index][0], event, function() {
		_this.expand_marker(index)
	});
}
//清除所有状态,除了所有的锚点,例如清除所有的浮动泡泡,清除连线
tx_map.prototype.clear_except_markers = function() {
	_this.map.closeInfoWindow();
	if (_this.polyline) 
		_this.polyline.remove(); //清除连线
}
//清除的比较彻底
tx_map.prototype.clear_all = function() {
	_this.map.clearOverlays();
	_this.markers_on_map = [];
	_this.now_marker = _this.config.first_index;
}
//创建点，带有lebel信息
tx_map.prototype.createInfoMarker = function(point, index, userName) {
	  	var letteredIcon = new GIcon(_this.baseIcon);
	  	markerOptions = {
			"icon":letteredIcon,
			"clickable": true,
			"title": userName,
			//"labelText": "<div>"+userName+"<\/div>",
			"labelOffset": new GSize(-5, -29),
			//"hide":true,
			"zIndexProcess":function(marker, b){
				_this.newZIndex += 10000;
				if (marker.div_) marker.inHandler(_this.newZIndex);
		 		return _this.newZIndex;
	  		}
		};
		  
	  	var marker = new LabeledMarker(point, markerOptions);
	  	_this.map.addOverlay(marker);
		//_this.map_initial_status(true,8);
	  	return marker;
}
//展开单个锚点
tx_map.prototype.expand_marker = function(roll_index) {
	var index = _this.now_marker;
	if (typeof roll_index!='undefined') {
		index = roll_index;
	}	
	if (_this.markers_on_map[index]) {
		if (_this.tray_panel) {
			$(_this.tray_panel.dom).find(".tray_panel_avatar img").removeClass("current").eq((_this.page-1)*_this.page_size+index).addClass("current");
		}
		//_this.markers_on_map[index][0].openInfoWindowHtml(_this.markers_on_map[index][1]);
		_this.open_marker_view(_this.markers_on_map[index][0], _this.markers_on_map[index][1]);
	}
}
//取得所有在地图上的点, 这只是一个示例,大部分需要覆盖重置 create_view是否要重新组织view?
tx_map.prototype.set_markers_to_map = function(points, i_lat, i_lng, i_label,i_view, create_view) {			
	//alert(points+','+i_lat+','+i_lng+','+i_label+','+i_view+','+create_view)
	if (_this.myEventListener){GEvent.removeListener(_this.myEventListener);}
	
	_this.markers_on_map = [];
	if (typeof points=="undefined")  return ;

	//初始化所有服务至数组
	var t=-1;
	for (var i in points) {
		var temp =  points[i];
		//alert(temp.AdministrativeAreaName)
		var labelName = _this.split_marker_param(i_label, temp);
		var lat = _this.split_marker_param(i_lat, temp);
		var lng = _this.split_marker_param(i_lng, temp);
		var view = _this.split_marker_param(i_view, temp);

		//alert(temp[i_lat]+','+temp[i_lng]+','+i+','+userName)
		//保持坐标合法性
		if (lat<=90 && lat>=-90 && lng<=180 && lng>=-180) {
			t++;
			_this.markers_on_map[t] = [];
			marker_temp = _this.createInfoMarker(new GLatLng(lat, lng), t, labelName); //生成marker
	
			if (typeof create_view !='undefined' && typeof _this.create_item == 'function') {
				info_temp = _this.create_item([view, temp], t);
			} else {
				info_temp = view;
			}
			_this.markers_on_map[t] = [marker_temp, info_temp, labelName, temp];
			_this.bindMarkerEvent(t);
		}
	}
}
tx_map.prototype.split_marker_param = function(param, par_value) {	
	var split_arr = param.split('->');
	for (var t in split_arr) {
		if (par_value[split_arr[t]])
			par_value = par_value[split_arr[t]];
	}
	return par_value;
}
//修改或者生成新的list
tx_map.prototype.update_map_list_dom = function(list_dom) {
	if (!list_dom) list_dom = $('#' + _this.config.map_search_list_id);
	if (_this.config.act && _this.config.act == act_bao){
  		return ;
  	}
	list_dom.html("");
	for (var i=0; i<_this.markers_on_map.length; i++) {		
		temp = _this.markers_on_map[i][3];		
		 if (typeof temp.list_title!='undefined'){
			list_dom.append('<li><div class="order order_'+i+'"><b></b></div><div class="address_info"><a href="javascript:void(0)" title="'+temp.address +'">'+temp.list_title+'</a></div></li>');
		}else if (typeof temp.AddressLine!='undefined') {
			list_dom.append('<li><div class="order order_'+i+'"><b></b></div><div class="address_info"><a href="javascript:void(0)" title="'+temp.AddressLine+' ('+temp.address +')">'+temp.AddressLine+'</a></div></li>');
		}else if (typeof temp.label!='undefined'){
			list_dom.append('<li><div class="order order_'+i+'"><b></b></div><div class="address_info"><a href="javascript:void(0)" title="'+temp.address +'">'+temp.label+'</a></div></li>');
		} else{
			if (temp.address){
				list_dom.append('<li><div class="order order_'+i+'"><b></b></div><div class="address_info"><a href="javascript:void(0)" title="'+temp.address+'">'+temp.address + '</a></div></li>');	
			}			
		}
	}
	list_dom.find("li").click(function(){
		var parent_li = $(this);
		var all_li = list_dom.find("li");
		all_li.removeClass("current");
		parent_li.addClass("current");
		index = all_li.index(parent_li);
		$('.LabeledMarker_markerLabel b').removeClass("current");
		$(_this.markers_on_map[index][0].div_).find("b").addClass("current");
		_this.markers_on_map[index][0].openInfoWindowHtml(_this.markers_on_map[index][1]);
		return false;
	})
}
//整理google返回的地址解析数据,特殊处理place
tx_map.prototype.analyse_g_points_place = function(places) {
	var p = [];
	for(k in places) {
		p[k] = {};
		p[k]['lat'] = places[k].Point.coordinates[1];
		p[k]['lng'] = places[k].Point.coordinates[0];
		p[k]['north'] = places[k].ExtendedData.LatLonBox.north;
		p[k]['south'] = places[k].ExtendedData.LatLonBox.south;
		p[k]['east'] = places[k].ExtendedData.LatLonBox.east;
		p[k]['west'] = places[k].ExtendedData.LatLonBox.west;
		p[k]['address'] = places[k].address;
		p[k]['Accuracy'] = places[k].AddressDetails.Accuracy;
		if (typeof places[k].AddressDetails.Country!='undefined') {
			p[k]['country_code'] = places[k].AddressDetails.Country.CountryNameCode;
			p[k]['CountryName'] = places[k].AddressDetails.Country.CountryName;
		}else{
			continue;
		}
		if (typeof places[k].AddressDetails.Country.AdministrativeArea!='undefined') {
			p[k]['place_std'] = {};
			b = [];
			b[0] = places[k].AddressDetails.Country.AdministrativeArea;
			i1 = i2 = 0;
			do {
				for(t in b[i1]){
					if (typeof b[i1][t] =="object" || typeof b[i1][t]=="array") {
						if (t == 'AddressLine') {
							p[k]['place_std']['AddressLine'] = b[i1][t][0];	
						}else{
							i2 = i2+1;
							b[i2] = b[i1][t];
						}
					} else {
						 p[k]['place_std'][t] = b[i1][t];
					}
				}
				delete b[i1];
				i1++;
			} while (b[b.length-1]);
		}
	}
	return p;
	
}
function obj2str(o){
    var r = [];
    if(typeof o =="string") return "\'"+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\'";
    if(typeof o == "object"){
        if(!o.sort){
            for(var i in o)
                r.push("'"+i+"'"+":"+obj2str(o[i]));
            if(!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)){
                r.push("toString:"+o.toString.toString());
            }
            r="{"+r.join()+"}"
        }else{
            for(var i =0;i<o.length;i++)
                r.push(obj2str(o[i]))
            r="["+r.join()+"]"
        }
        return r;
    }
    return o.toString();
}
function join_address(address_res){
	var address = '';
	var china_array = ['CN', 'China', 'Taiwan', "Hong Kong", "HK"];
	if (address_res.country!='' && address_res.country!='CN' && address_res.country!='China'){
		for(var i in address_res.addressLines) {
			if (address.indexOf(address_res.addressLines[i])==-1){
				if (address == '')
					address += address_res.addressLines[i];
				else
					address += " " + address_res.addressLines[i];
			}
		}
	}else{
		for(var i in address_res.addressLines) {
			var rep = address_res.addressLines[i].replace("China", "中国");
			if (address.indexOf(rep)==-1 && rep.indexOf("邮政编码")==-1){
				if (rep == '中国') {
					address = rep + address;					
				}else{
					address = address + rep;
				}
			}
		}
	}
	return address;
}
//checkin提交前对地点名进行发送到GOOGLE进行解，以得到完整数据
tx_map.prototype.checkin_sub=function(response){
	if(response.name){var name=response.name;}
	if (!response || response.Status.code != 200) {
		//没有解析到的数据,原则上应该添加0.1的矩形范围,但是无法得到规范的地级等级属性
      alert("抱歉， 我们无法帮您解析该地址，您可以重新修改地址或者手动指定地图位置");
    } else {
		//_this.clear_all();
      	var places = response.Placemark;
      	var checkin_place;
      	var ori_p = _this.markers_on_map[_this.check_in_index][0].getLatLng();
		//返回结果得到最近的结果
		if (places.length==1){
			checkin_place = places[0];
		}else{
			var distance = Number.MAX_VALUE;			
			for(var v in places){
				var new_d = ori_p.distanceFrom(new GLatLng(places[v].Point.coordinates[1], places[v].Point.coordinates[0]));
				if (new_d<distance) {
					checkin_place = places[v];
					distance = new_d;
				}
			}
		}
		places = _this.analyse_g_points_place([checkin_place]);
		var temp;
		temp = places[0];		
		//使用localsearch得到的中心点
		temp.lat = ori_p.lat();
		temp.lng = ori_p.lng();
		temp.streetAddress = _this.markers_on_map[_this.check_in_index][3]['streetAddress']; 
		//处理地址,之前是直接按地址解析,地址+addressLine会有问题, 解析后有可能没有,人工增加,缩放级别》邮政编码级准确度。。
		if (typeof _this.AddressLine !="undefined" && temp.address.indexOf(_this.AddressLine)==-1){
			if (_this.AddressLine.indexOf(temp.address)!=-1) {
				temp.address = _this.AddressLine;
				_this.AddressLine = '';
			} else if (_this.markers_on_map[_this.check_in_index][3]['Accuracy']>7 || temp['Accuracy']>7) {
				//如果没有,该地址就为建筑地址
				temp.address = temp.address + _this.AddressLine;
				temp.AddressLine = _this.AddressLine;
				temp.north = temp.lat + 0.01;
				temp.south = temp.lat - 0.01;
				temp.east = temp.lng + 0.01;
				temp.west = temp.lng - 0.01;
			}else{				
				temp.AddressLine = _this.AddressLine;
				temp.address = temp.address + _this.AddressLine;
			}
		} else {
			_this.AddressLine = '';
		}
		var places='{';
		for(var k in temp){
			if (typeof temp[k]=="object") {
				places+=('"'+k+'":\"'+obj2str(temp[k])+'\",');
			}else{
				places+=('"'+k+'":"'+temp[k]+'",');
			}
		}
		if(name){
			places+='"name":"'+name+'"';
		}else{
			places=places.substring(0,places.length-1)
		}
		places+='}'
		$.ajax({
			'url':'/ajax/checkin.php',
			type:'post',
			data:{place:places},
			dataType:"json",
			beforeSend:function(){
				var bool = true;
				if (typeof checkin_before == 'function') {
					bool = checkin_before(temp);
				}
				return bool;
			},
			success:function(d){
				/*eval('var t='+d);
				window.parent.document.getElementById('nowplaceshow').innerHTML=t.place_name;
				window.parent.document.getElementById('nowplace').innerHTML=t.place_name;	
				window.parent.txmap.filter.init();*/
				if (typeof checkin_callback =='function') {
					checkin_callback();
				}else{
					setTimeout("window.parent.location.reload();window.parent.ye_dialog.close();", 100)
				}
				//window.parent.ye_dialog.close();
			}
		});
	}	
};
//checkin post到服务端
tx_map.prototype.checkin = function(index) {
	_this.AddressLine = _this.markers_on_map[index][3].AddressLine;
	_this.check_in_index = index;
	//var searchname = _this.markers_on_map[index][3].streetAddress;
	var searchname=_this.markers_on_map[index][3].address;
	/*if(_this.AddressLine && secondname.indexOf(_this.AddressLine)==-1){
		secondname = secondname + "" + _this.AddressLine;
	}*/
	if (!_this.geocoder){
		_this.geocoder = new GClientGeocoder();
	}
	if (!searchname) {
		searchname = _this.markers_on_map[index][3].AddressLine;
	}
	_this.geocoder.getLocations(searchname, _this.checkin_sub); //geocoder分析
};
tx_map.prototype.init = function() {
	//alert(_this.config.all_markers.view);
	_this.set_markers_to_map(_this.config.all_markers, _this.config.setmark_key[0], _this.config.setmark_key[1], _this.config.setmark_key[2],_this.config.setmark_key[3]);
	_this.map_initial_status(null, _this.config.fixed_zoom);
}
//地图初始化的状态  all_or_index: true->初始显示所有点, 如果提供了某个的锚点的index,则显示其状态
//fixed_zoom 是否固定缩放级别
tx_map.prototype.map_initial_status = function(all_or_index, fixed_zoom) {
	var default_point;
	var bound_center, bound_zoom;
	//如果显示某个点
	if (all_or_index && parseInt(all_or_index)) {
		if  (_this.markers_on_map[all_or_index]) {
			_this.expand_marker(all_or_index);
			return ;
		}
	}
	//自适应点
	if (_this.config.markers_extend && _this.markers_on_map.length!=0) {
		//如果不需要固定缩放级别
		if (typeof fixed_zoom=="undefined" || fixed_zoom>19 || fixed_zoom<1) {
			//如果只有一个点
			if(_this.markers_on_map.length==1){
				if (_this.markers_on_map[0][3].south) { //如果该点存在框属性
					var s=_this.markers_on_map[0][3].south;
					var w=_this.markers_on_map[0][3].west;
					var n=_this.markers_on_map[0][3].north;
					var e=_this.markers_on_map[0][3].east;
					bounds = new GLatLngBounds(new GLatLng(s,w),new GLatLng(n,e));
					var boundZoom = _this.map.getBoundsZoomLevel(bounds);
					_this.map.setCenter(bounds.getCenter(), boundZoom);			
				} else {
					_this.map.setCenter(_this.markers_on_map[0][0].getLatLng(), _this.config.max_zoom);
				}
			}else{//自适应点
				bounds = new GLatLngBounds();
				for (var i=0; i<_this.markers_on_map.length; i++) {
					if (_this.markers_on_map[i][0]) {
						bounds.extend(_this.markers_on_map[i][0].getLatLng());
					}
				}
				var boundZoom = _this.map.getBoundsZoomLevel(bounds);//获得缩放级别
				if (boundZoom>_this.config.max_zoom) {
					boundZoom = _this.config.max_zoom;
				}
				bound_center = bounds.getCenter();
				bound_zoom = boundZoom;								
			}
		} else {
			//alert(_this.config.default_center[0])
			bound_center = new GLatLng(_this.config.default_center[0], _this.config.default_center[1]);
			bound_zoom = fixed_zoom;
		}
	}

	//如果地图上没有数据,或者设置了地图点不自动包含, 则走默认属性
	if (_this.markers_on_map.length==0 || !_this.config.markers_extend) {
		//是否设置到地图上, 只要存在set_to_map变量, 就不设置到地图
		if (typeof _this.config.default_status.set_to_map=="undefined") {
			default_point = new GLatLng(_this.config.default_center[0], _this.config.default_center[1]);
			if (_this.markers_on_map.length==0){
				var default_marker = _this.createInfoMarker(default_point, 0, _this.config.default_status.view);
				default_marker.openInfoWindowHtml(_this.config.default_status.view);
				GEvent.addListener(default_marker, "click", function() {
					default_marker.openInfoWindowHtml(_this.config.default_status.view);
				});
				/*_this.markers_on_map[0] = [];
				_this.markers_on_map[0][0] = default_marker;
				_this.markers_on_map[0][1] = _this.config.default_status.view;		
				_this.markers_on_map[0][2] = "";
				_this.markers_on_map[0][3] = this.config.default_status;
				_this.bindMarkerEvent(0);
				_this.now_marker = 0;*/
			}
		}
		//如果需要设置一个默认的框范围
		if (typeof _this.config.default_status.north!="undefined") {
			bounds = new GLatLngBounds();
			if (_this.config.default_status.north =='' || Math.abs(_this.config.default_status.north)>90)  {
				_this.config.default_status.north = 90;
				_this.config.default_status.south = -90;
				_this.config.default_status.east = 180;
				_this.config.default_status.west = -180;
			}
			bounds.extend(new GLatLng(_this.config.default_status.north, _this.config.default_status.east));
			bounds.extend(new GLatLng(_this.config.default_status.south, _this.config.default_status.west));
			var boundZoom = _this.map.getBoundsZoomLevel(bounds);//获得缩放级别
			if (boundZoom>_this.config.max_zoom) {
				boundZoom = _this.config.max_zoom;
			}
			bound_center = bounds.getCenter();
			bound_zoom = boundZoom;
		} else {
			if (fixed_zoom) {
				bound_center = default_point;
				bound_zoom = fixed_zoom;
			}else{
				bound_center = default_point;
				bound_zoom = _this.config.fixed_zoom;
			}
		}
	}
	if (fixed_zoom) {
		bound_zoom = fixed_zoom;
	}
	if (bound_zoom<_this.config.min_zoom) {
		bound_zoom = _this.config.min_zoom;
	}
	if (!bound_center){
		bound_center = new GLatLng(_this.config.default_center[0], _this.config.default_center[1]);
	}
	if (_this.map.getCurrentMapType()==G_PHYSICAL_MAP&&bound_zoom>15){
		_this.map.setMapType(G_NORMAL_MAP );
	}
	_this.map.setCenter(bound_center, bound_zoom);
	_this.expand_marker(_this.config.first_index);
	_this.roll();
	_this.addHierarchicalMap();
}
//输出提示信息
tx_map.prototype.msg = function(msg_string) {
	$('#' + _this.config.error_dom_id).html(msg_string);
}
//初始化点击地图,自定义地址的操作
tx_map.prototype.init_map_click = function(callback) {
	if (_this.myEventListener){GEvent.removeListener(_this.myEventListener);}
	_this.myEventListener = GEvent.bind(_this.map, "click", this, function(marker, latlng) {
	     if (latlng) {
	     	callback();			
	     }
	});
}
//发送坐标
tx_map.prototype.post_pos = function(url, lat, lng, zoom, callback) {
	if (!zoom) {
		zoom = _this.map.getZoom();
	}
	$.ajax({
		"url":url,
		type:"post",
		data:{"lat":lat, "lng":lng, "zoom":zoom},
		dataType:"json",
		beforeSend:function() {
			//如果没有url信息或者经纬度信息
			if (!url || !lat || !lng) {
				_this.msg("请输入经纬度信息");
				return false;
			}
		},
		success:function() {
			if (callback) callback({"lat":lat, "lng":lng, "zoom":zoom});
			_this.msg("发送成功");
		}
	});
}
//轮显各个点
tx_map.prototype.roll = function(stop){
	if (_this.rollInterval){clearInterval(_this.rollInterval);}
	if (!_this.config.rollTime) return ;
	if (typeof stop!="undefined") {
		clearInterval(_this.rollInterval);
		return ;
	}
	//如果当前地图上没有点或者只有一个,则不滚动
	if (_this.markers_on_map.length==1 || _this.markers_on_map.length==0) {
		return ;
	}
	_this.rollInterval = setInterval(function() {
		_this.clear_except_markers();  //清除当前地图图标
		_this.now_marker++;
		if (!_this.markers_on_map[_this.now_marker]) { //不存在,返回
			_this.now_marker = _this.config.first_index;
		}

		_this.expand_marker(_this.now_marker);
	}, _this.config.rollTime);
}
//地图已经存在的上一页或者下一页点, 向右提取新的数据不在这处理
tx_map.prototype.roll_markers = function(page) {
	var first_index = (page-1)*_this.page_size;
	var points = all_markers.slice(first_index, first_index + _this.page_size);
	if (points.length==0) {
		_this.config.default_status.view = '暂无内容';	
	} else {
		_this.config.default_status.set_to_map = false;
	}
	_this.page = page;
	_this.clear_all();
    _this.set_markers_to_map(points,"status->place->lat", "status->place->lng", "userInfo->name", "status->content", null, {tray_init:false, "add_tray_img":false});
    _this.map_initial_status();
}
tx_map.prototype.open_marker_view = function(marker, html){	
	var t, pixel, p_latlng, height, y_left;
	var c;//包含内容的div
	p_latlng = marker.getLatLng();
	var img = $(html).find(".content img"); 
	//图片加载完毕后再进行弹出
	if (img.length==1) {
		img.load(function(){
			_this.map.openInfoWindowHtml(p_latlng, html, {onOpenFn:function(){
				//得到map里的消息泡泡
				c = _this.map.getInfoWindow().getContentContainers();
				//获得整个泡泡的大致高度,+160是补充外围 c只是泡泡内容的高度
				height = $(c).height() + 160;			
				//经纬度转换为距离地图左上角的像素距离
				pixel = _this.map.fromLatLngToContainerPixel(p_latlng);
				//如果当前泡泡内容高度超过了点y轴的高度
				if (height>pixel.y){
					//这个时候会破坏google地图自动的信息泡泡定位机制，得自己计算左右像素位置
					y_left = ($(c).parents(".gmnoprint").width())/2;
					if (pixel.x<y_left){
						y_left = y_left-pixel.x;
					}else if (200+pixel.x>$('#'+_this.config.map_dom_id).width()){
						y_left = $('#'+_this.config.map_dom_id).width()-200-pixel.x;
					}else{
						y_left = 0;
					}				
					t = new GSize(y_left, height-pixel.y);
					_this.map.panBy(t);
				}
			}});		
		});	
	}else{		
		_this.map.openInfoWindowHtml(p_latlng, html, {onOpenFn:function(){
			//得到map里的消息泡泡
			c = _this.map.getInfoWindow().getContentContainers();
			//获得整个泡泡的大致高度,+160是补充外围 c只是泡泡内容的高度
			height = $(c).height() + 160;			
			//经纬度转换为距离地图左上角的像素距离
			pixel = _this.map.fromLatLngToContainerPixel(p_latlng);
			//如果当前泡泡内容高度超过了点y轴的高度
			if (height>pixel.y){
				//这个时候会破坏google地图自动的信息泡泡定位机制，得自己计算左右像素位置
				y_left = ($(c).parents(".gmnoprint").width())/2;
				if (pixel.x<y_left){
					y_left = y_left-pixel.x;
				}else if (200+pixel.x>$('#'+_this.config.map_dom_id).width()){
					y_left = $('#'+_this.config.map_dom_id).width()-200-pixel.x;
				}else{
					y_left = 0;
				}				
				t = new GSize(y_left, height-pixel.y);
				_this.map.panBy(t);
			}
		}});
	}
};
//探宝活动
function act_bao(map_class) {
	var map = map_class.map;
	var time_ajax = null;
	var key = '';
	var tickets_marker = [];
	var tickets_ids = [];
	GEvent.addListener(map, "move", function(point){
		var map_zoom = map.getZoom();		
		if (map_zoom>=19){
			//ajax获取当前是否有宝
			if (time_ajax){
				clearTimeout(time_ajax);
			}
			time_ajax = setTimeout(ajax_ticket, 100);
			//有宝, 显示
		}else{
			remove_tickets(1);
		}
	});
	function ajax_ticket(){
		var bound = map.getBounds();
		var sw = bound.getSouthWest();
		var ne = bound.getNorthEast();
		var south = sw.lat();
		var west = sw.lng();
		var north = ne.lat();
		var east = ne.lng();
		var zoom = map.getZoom();
		$.ajax({
			'url':'/ajax/get_ticket.php',
			'dataType':'json',
			'type':'get',
			'data':{"north":north, "south":south, "west":west, "east":east, "zoom":zoom, "key":key},
			success:function(response){
				remove_tickets();
				var tickets = response.tickets;
				var i;
				var t_marker;
				var t_point;
				for(i in tickets){
					t_point = new GLatLng(tickets[i].lat, tickets[i].lng);
					//如果在地图内,且不在已知的点内
					if (bound.containsLatLng(t_point) && $.inArray(tickets[i].ticket_id, tickets_ids)==-1){
						t_marker = create_marker(t_point, tickets[i].type);
						tickets_marker.push({"marker":t_marker, "id":tickets[i].ticket_id});
						tickets_ids.push(tickets[i].ticket_id);
					}
				}
			}
		});
	}
	var icons = {};
	//火车票
	var type_1 = new GIcon();
	type_1.image = "http://site.tongxueimg.com/t/images/hd/ticket/b.gif?v=3";
	type_1.iconSize = new GSize(77, 77);
	type_1.iconAnchor = new GPoint(38, 77);
	type_1.infoWindowAnchor = new GPoint(38, 77);
	icons.train = type_1;	
	
	function create_marker(point, type){
		var letteredIcon = icons[type];
	  	markerOptions = {
			"icon":letteredIcon,
			"clickable": true,
			"title": "宝贝哦",
			//"labelText": "<div>"+userName+"<\/div>",
			"labelOffset": new GSize(-5, -29),
			//"hide":true,
			"zIndexProcess":function(marker, b){
				_this.newZIndex += 10000;
				if (marker.div_) marker.inHandler(_this.newZIndex);
		 		return _this.newZIndex;
	  		}
		};
		  
	  	var marker = new LabeledMarker(point, markerOptions);
	  	map.addOverlay(marker);
	  	
  		GEvent.addListener(marker, "click", function() {
  			marker.openInfoWindowHtml("恭喜你找到火车票！快点截图上传至活动主页吧！<br/>宝藏经纬度:"+point.lng()+","+point.lat());
  		});
		//_this.map_initial_status(true,8);
	  	return marker;
	}
	function remove_tickets(force){
		var bound = map.getBounds();
		if (!tickets_marker || tickets_marker.length==0) {
			return ;
		}
		var i;		
		for(i in tickets_marker) {
			if (force){
				map.removeOverlay(tickets_marker[i].marker);
				var index = $.inArray(tickets_marker[i].id, tickets_ids);
				tickets_ids.splice(index, 1);
				tickets_marker.splice(i, 1);
			}else{
				if (!bound.containsLatLng(tickets_marker[i].marker.getLatLng())){
					map.removeOverlay(tickets_marker[i].marker);
					var index = $.inArray(tickets_marker[i].id, tickets_ids)
					tickets_ids.splice(index, 1);
					tickets_marker.splice(i, 1);
				}
			}
		}
	}
};

/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
txmap.userphotoRoll={
	//info:{},
	left:function(){
		var a=txmap.userphotoRoll;
		a.init();
		a.roll('left')
	},
	right:function(){
		var a = this;
		if ($('#'+a.info.tray_panel_right).attr("class").indexOf('tray_panel_right_disable')==-1){
			a.init();
			a.roll('right')
		}
	},
	init:function(map, next_load_data_obj){//第一次点击时初始化所需数据，其中三个数据需要指定固定值。a.info.tray_panel_avatar_box，a.info.tray_panel_avatar，a.info.user_photo_width=58
		var a=txmap.userphotoRoll;
		if (typeof a.info!='object') {
			a.info={};
			a.info.tray_panel_avatar_box='tray_panel_avatar_box';//滚动列表外的overflow:hidden盒子
			a.info.tray_panel_avatar='tray_panel_avatar';//滚动列表
			a.info.tray_panel_left='tray_panel_left';
			a.info.tray_panel_right='tray_panel_right';
			a.info.tray_panel_avatar_box_width=document.getElementById(a.info.tray_panel_avatar_box).clientWidth;//滚动列表盒子的宽度
			a.info.user_photo_num=$('#'+a.info.tray_panel_avatar+' img').length;//要滚动的总数量
			a.info.user_photo_width=50;//单个滚动元素的宽度
			if (typeof map!='undefined')
				a.info.map = map;			
			if (typeof next_load_data_obj=='object'){
				a.info.next_load_data_obj = next_load_data_obj;
			}
			//a.info.user_photo_height=58;
			//滚动列表最多显示数量，不足一个宽度则舍去不算
			a.info.show_user_photo_num=Math.floor(a.info.tray_panel_avatar_box_width/a.info.user_photo_width);
			a.info.first_user_photo_num=0;//计数器，用来记录当前状态下显示出的第一个元素的序号从0开始，也可以理解为目前已滚动出去的元素个数
			a.lRButtonBg();	
		}else{
			return;
		}
	},
	//重新初始化所有数据
	re_init_info:function() {
		var a=txmap.userphotoRoll;
		if (typeof a.info !='undefined')
			a.info.first_user_photo_num=0;//计数器，用来记录当前状态下显示出的第一个元素的序号从0开始，也可以理解为目前已滚动出去的元素个数
	},
	//重新计算当前用户头像数量,因为向右会ajax loading数据
	re_init_photo_num:function(){
		var a=txmap.userphotoRoll;
		a.info.user_photo_num=$('#'+a.info.tray_panel_avatar+' img').length;
	},
//A-----------
//B           ----------
//C                      ----------
// ----------0----------n----------
	roll:function(direction){		
		var a=txmap.userphotoRoll;		
		var move_num=0;//要移动的格数
		var space;//要移动到的left值
		var roll_mar = true;
		if(direction=='left'){
			if(a.info.first_user_photo_num<=0){//A
				roll_mar = false;
				return;
			}else if(a.info.first_user_photo_num>=a.info.show_user_photo_num){//C
				move_num=-(a.info.show_user_photo_num);
				
			}else{//B
				move_num=-a.info.first_user_photo_num;
			}
			space=-a.info.user_photo_width*(a.info.first_user_photo_num+move_num);
			a.info.map.page = a.info.map.page -1; 
		}else if(direction=='right'){
			a.info.map.page = a.info.map.page + 1;
			if(a.info.user_photo_num-a.info.first_user_photo_num-a.info.show_user_photo_num<=0){//右边没有数据了, 则load数据
				move_num=a.info.show_user_photo_num;
				$('#'+a.info.tray_panel_right).addClass('tray_panel_right_disable')
				txmap.filter._a.currentPage = txmap.filter._a.currentPage+1;
				txmap.filter._a.page_size = 10;
				txmap.filter._setup();
				$("#map_loading").removeClass("hide");				
				if (typeof a.info.next_load_data_obj=='object') {//如果设置了自己的数据提取函数，则启用，否则使用timeline作为默认
					a.info.next_load_data_obj.just_load_data(a.map_next_callback);
				}else{
					timeline.justLoadData(a.map_next_callback);
				}
				roll_mar = false;
			}else if(a.info.user_photo_num-a.info.first_user_photo_num-a.info.show_user_photo_num>=a.info.show_user_photo_num){//C
				move_num=a.info.show_user_photo_num;
			}else{//每次按一页翻页,不计算右边剩余多少个了
				//move_num=a.info.user_photo_num-a.info.first_user_photo_num-a.info.show_user_photo_num;
				move_num=a.info.show_user_photo_num;
			}
			space=-a.info.user_photo_width*(a.info.first_user_photo_num+move_num);
		}
		//更新第一位置
		a.info.first_user_photo_num+=move_num;
		//滚动地图标志
		if (roll_mar && typeof a.info.map!='undefined') {
			a.info.map.roll_markers(a.info.first_user_photo_num/a.info.show_user_photo_num + 1);
		}
		$('#'+a.info.tray_panel_avatar).animate({left: space},1500,function(){			
			a.lRButtonBg();														   
		});
	},
	//获得下一页地图数据
	map_next_callback:function(response) {		
		var a=txmap.userphotoRoll;
		if (response.items.length>9)
			$('#'+a.info.tray_panel_right).removeClass('tray_panel_right_disable');
		for (var t in response.items) {
			all_markers.push(response.items[t])
		}
		a.info.map.page++;
		filter_map_callback(response, {tray_init:false});
	},
	lRButtonBg:function(){
		var a=txmap.userphotoRoll;
		if(a.info.first_user_photo_num<=0){
			$('#'+a.info.tray_panel_left).addClass('tray_panel_left_disable')
		}else{
			$('#'+a.info.tray_panel_left).removeClass('tray_panel_left_disable')
		}
		//如果当前第一个+每页显示个数>总数,则没有更多数据
		if(a.info.show_user_photo_num+a.info.first_user_photo_num>a.info.user_photo_num){
			$('#'+a.info.tray_panel_right).addClass('tray_panel_right_disable')
		}else if(a.info.map.config.db_status_total<=a.info.show_user_photo_num+a.info.first_user_photo_num){
			$('#'+a.info.tray_panel_right).addClass('tray_panel_right_disable');
		}else{
			$('#'+a.info.tray_panel_right).removeClass('tray_panel_right_disable');
		}
	},
	//头像跟随地图滚动,在new tx_map.roll中使用
	followRoll:function(now_marker){
		var a=txmap.userphotoRoll;
		var space;
		if(now_marker<a.info.first_user_photo_num){
			if(a.info.first_user_photo_num-now_marker<a.info.show_user_photo_num){
				a.left();
			}else{
				space=-a.info.user_photo_width*(now_marker);
				$('#'+a.info.tray_panel_avatar).animate({left: space},1500,function(){
					a.info.first_user_photo_num=now_marker;
					a.lRButtonBg();																   
				});
			}
		}else if(now_marker>=a.info.first_user_photo_num+a.info.show_user_photo_num){
			if((now_marker-(a.info.first_user_photo_num+a.info.show_user_photo_num))<a.info.show_user_photo_num){
				a.right();
			}else{
				if(a.info.user_photo_num-now_marker>=a.info.show_user_photo_num){
					space=-a.info.user_photo_width*(now_marker);
				}else{
					space=-a.info.user_photo_width*(now_marker-(a.info.show_user_photo_num-(a.info.user_photo_num-now_marker)));
				}
				$('#'+a.info.tray_panel_avatar).animate({left: space},1500,function(){
					a.info.first_user_photo_num=now_marker;
					a.lRButtonBg();																   
				});
			}
		}
	}
}
//随便看看
txmap.detail={
	map:null,
	init:function(ajax,place){
		var d,p;
		d = ajax;
		p = place;

		if (GBrowserIsCompatible()) {
	        var map = new GMap2(document.getElementById("map_canvas"));
	        map.disableDragging();
			i = 0;
			//var defalut_point = new GLatLng();
			//this.createDefaultMarker(new GlatLng(default_point));
			//map.addOverlay();
			bounds = new GLatLngBounds();
			bounds.extend(new GLatLng(p.lat, p.lon));
			if (p.north && p.east) {
				bounds.extend(new GLatLng(p.north, p.east));
			}
			if (p.south && p.west) {
				bounds.extend(new GLatLng(p.south, p.west));
			}
			var default_point = new GLatLng(p.lat, p.lon);			
			var default_marker = this.createDefaultMarker(default_point);
			map.addOverlay(default_marker);
			var point, marker;
	        // 在随机位置向地图中添加 10 个标记
	        for (var val in d) {	
	        	point = new GLatLng(d[val].place.lat,d[val].place.lon);
	        	marker = this.createInfoMarker(point, i);
	        	map.addOverlay(marker);
	        	bounds.extend(point);
	        	i++;
	        }
	        bounds.extend(default_point);
	        var mapCenter  = bounds.getCenter();
	        if (!mapCenter.lat() || !mapCenter.lng() ) {
	        	if (default_point) {
	        		mapCenter = default_point
	        	}else{
	        		mapCenter = new GLatLng(39.917, 116.397)
	        	}
	        }
	        var boundZoom = map.getBoundsZoomLevel(bounds);//获得缩放级别
	        boundZoom = boundZoom?boundZoom:4;
			map.setCenter(mapCenter, boundZoom);
		}
	},
	newZIndex:-1000000, //控制div的z-index
	createDefaultMarker: function(point) {
		
	},
	createInfoMarker: function(point, index) {
		var baseIcon = new GIcon();
		baseIcon.iconSize = new GSize(24, 25);				
		baseIcon.iconAnchor = new GPoint(12, 12);
		baseIcon.infoWindowAnchor = new GPoint(12, 12);

	  	var letteredIcon = new GIcon(baseIcon);
	  	markerOptions = {
			"icon":letteredIcon,
			"clickable":true,
			"labelText": '<div class="order order_'+index+'"><b></b><\/div>',
			"labelOffset": new GSize(-12, -25),
			"zIndexProcess":function(marker, b){
						this.newZIndex += 10000;
						if (marker.div_) marker.inHandler(this.newZIndex);
				 		return this.newZIndex;
			 }
		};
		  
	  	var marker = new LabeledMarker(point, markerOptions);
	  	return marker;
	},
	createDefaultMarker: function(point){
		var baseIcon = new GIcon();
		baseIcon.image = "http://site.tongxueimg.com/t/images/place/default_marker.png?v=2";
		baseIcon.iconSize = new GSize(24, 24);				
		baseIcon.iconAnchor = new GPoint(12, 24);
		baseIcon.infoWindowAnchor = new GPoint(12, 24);

	  	var letteredIcon = new GIcon(baseIcon);
	  	markerOptions = {
			"icon":letteredIcon,
			"clickable":true,
			"labelText": '<div class="order_default"><b></b><\/div>',
			"labelOffset": new GSize(-12, -25),
			"zIndexProcess":function(marker, b){
						this.newZIndex += 10000;
						if (marker.div_) marker.inHandler(this.newZIndex);
				 		return this.newZIndex;
			 }
		};
		  
	  	var marker = new LabeledMarker(point, markerOptions);
	  	return marker;
	}
}
//消息详细页-附近消息
txmap.browse={
	time:'',
	map:null,
	init:function(d){
		//d.longitude经
		//d.latitude纬
		//d.status.text内容
		this.time=d.created_time;
		if (GBrowserIsCompatible()) {
			this.map = new GMap2(document.getElementById("map_canvas"));
			//默认值，应为用户当时标注地点
			this.map.setCenter(new GLatLng(d.latitude, d.longitude), 5);
			this.map.openInfoWindow(this.map.getCenter(),document.createTextNode(d.status.text));
			var point = new GLatLng(d.longitude, d.latitude);
        	this.map.addOverlay(new GMarker(point));
			setTimeout(this.autoshow,10000)
		}
	},
	autoshow:function(){
		$.get('/ajax/get_browse.php',{time:txmap.browse.time},function(b){
			if(b==false){
				setTimeout(txmap.browse.autoshow,30000)	
			}else{														   
			var d;
			eval('d='+b);
				txmap.browse.time=d.created_time;
				txmap.browse.map.panTo(new GLatLng(d.latitude, d.longitude))
				txmap.browse.map.openInfoWindow(txmap.browse.map.getCenter(),document.createTextNode(d.status.text));
				var point = new GLatLng(d.longitude, d.latitude);
				txmap.browse.map.addOverlay(new GMarker(point));
				setTimeout(txmap.browse.autoshow,10000)	
			}
		})
		 
		
	}
}
var defaultmap;
txmap.pick_place_iframe={
	newbounds:null,
	show_default:function(latitude, longitude, north, south, east, west, param){
		var init_paras = {};
		if(latitude && longitude && north && south && east && west){
			init_paras = {"rollTime":0,'default_center':[latitude,longitude],"all_markers":[], "setmark_key":["lat", "lng", "label", "view"], "no_icon":true, 'default_status':{'set_to_map':false, 'north':north, 'south':south, 'east':east, 'west':west}, 'enable_wheel_zoom':true, 'HierarchicalMap':false};
		}else{
			init_paras = {"rollTime":0,"fixed_zoom":8,"all_markers":[], "setmark_key":["lat", "lng", "label", "view"], "no_icon":true, 'enable_wheel_zoom':true, 'HierarchicalMap':false};
		}
		for (var k in param) {
			if (param[k]!='undefined') {
				init_paras[k] = param[k];
			}
		}
		defaultmap=new tx_map(init_paras);
		//创建点，带有lebel信息
		defaultmap.createInfoMarker = function(point, index, userName) {
				_this.baseIcon.iconSize = new GSize(24, 25);				
				_this.baseIcon.iconAnchor = new GPoint(12, 12);
				_this.baseIcon.infoWindowAnchor = new GPoint(12, 12);
				
			  	var letteredIcon = new GIcon(_this.baseIcon);
			  	var hide_bool = false;
			  	if (defaultmap.config.act == act_bao){
			  		hide_bool = true;
			  	}
			  	markerOptions = {
					"icon":letteredIcon,
					"clickable": true,
					"title": userName,
					"labelText": '<div class="order order_'+index+'"><b></b><\/div>',
					"labelOffset": new GSize(-12, -25),
					"hide":hide_bool,
					"zIndexProcess":function(marker, b){
						_this.newZIndex += 10000;
						if (marker.div_) marker.inHandler(_this.newZIndex);
				 		return _this.newZIndex;
			  		}
				};			  	
			  	var marker = new LabeledMarker(point, markerOptions);
			  	_this.map.addOverlay(marker);
				//_this.map_initial_status(true,8);
			  	return marker;
		};
		//绑定点的事件
		defaultmap.create_item = function(data, index) {
			place_name=data[1].AddressLine;
			view = data[0];
			var c_view='<div class="map_popupdiv"><h3>'+place_name+'</h3><p>地址:'+view+'</p><input type="button" onclick="_this.checkin('+index+')" /></div>';
			return c_view;
		};
		//展开单个锚点, 这个时候也需要处理对应的map_search_list
		defaultmap.expand_marker = function(roll_index) {
			if (_this.config.act && _this.config.act == act_bao){
		  		return ;
		  	}
			var index = _this.now_marker;
			if (typeof roll_index!='undefined') {
				index = roll_index;
			}
			if (_this.markers_on_map[index]) {
				if (_this.tray_panel) {
					$(_this.tray_panel.dom).find(".tray_panel_avatar img").removeClass("current").eq((_this.page-1)*_this.page_size+index).addClass("current");
				}
				//_this.markers_on_map[index][0].openInfoWindowHtml(_this.markers_on_map[index][1]);
				var all_li = $('#'+this.config.map_search_list_id).find("li");
				var parent_li = all_li.eq(index);
				all_li.removeClass("current");
				parent_li.addClass("current");
				$('.LabeledMarker_markerLabel b').removeClass("current");
				$(_this.markers_on_map[index][0].div_).find("b").addClass("current");				
				_this.open_marker_view(_this.markers_on_map[index][0], _this.markers_on_map[index][1]);
			}
		};
		defaultmap.init();
		if (init_paras.act != act_bao){
			defaultmap.update_map_list_dom();		
			defaultmap.search_around();
			_this.update_map_list_dom();		
			GEvent.addListener(defaultmap.map, "dragend", defaultmap.search_around);/**/
			GEvent.addListener(defaultmap.map, "zoomend", defaultmap.search_around);/**/
		}		
	},
/*	 o[i]={
	 "GsearchResultClass":"GlocalSearch",
	 "viewportmode":"explicit",
	 "listingType":"local",
	 "lat":"39.909477",
	 "lng":"116.414555",
	 "accuracy":"1",
	 "title":"东方\u003cb\u003e商务\u003c/b\u003e中心",
	 "titleNoFormatting":"东方商务中心",
	 "ddUrl":"http://www.google.com/maps?source\u003duds\u0026daddr\u003d%E5%8C%97%E4%BA%AC%E5%B8%82%E4%B8%9C%E5%9F%8E%E5%8C%BA%E4%B8%9C%E9%95%BF%E5%AE%89%E8%A1%971%E5%8F%B7%2C++%28%E4%B8%9C%E6%96%B9%E5%95%86%E5%8A%A1%E4%B8%AD%E5%BF%83%29+%4039.909477%2C116.414555\u0026saddr\u003d31.26387862248445%2C121.44905090332031",
	 "ddUrlToHere":"http://www.google.com/maps?source\u003duds\u0026daddr\u003d%E5%8C%97%E4%BA%AC%E5%B8%82%E4%B8%9C%E5%9F%8E%E5%8C%BA%E4%B8%9C%E9%95%BF%E5%AE%89%E8%A1%971%E5%8F%B7%2C++%28%E4%B8%9C%E6%96%B9%E5%95%86%E5%8A%A1%E4%B8%AD%E5%BF%83%29+%4039.909477%2C116.414555\u0026iwstate1\u003ddir%3Ato",
	 "ddUrlFromHere":"http://www.google.com/maps?source\u003duds\u0026saddr\u003d%E5%8C%97%E4%BA%AC%E5%B8%82%E4%B8%9C%E5%9F%8E%E5%8C%BA%E4%B8%9C%E9%95%BF%E5%AE%89%E8%A1%971%E5%8F%B7%2C++%28%E4%B8%9C%E6%96%B9%E5%95%86%E5%8A%A1%E4%B8%AD%E5%BF%83%29+%4039.909477%2C116.414555\u0026iwstate1\u003ddir%3Afrom",
	 "streetAddress":"北京市东城区东长安街1号",
	 "city":"",
	 "region":"",
	 "country":"China",
	 "staticMapUrl":"http://mt.google.com/mapdata?cc\u003dus\u0026tstyp\u003d5\u0026Point\u003db\u0026Point.latitude_e6\u003d39909477\u0026Point.longitude_e6\u003d116414555\u0026Point.iconid\u003d15\u0026Point\u003de\u0026w\u003d150\u0026h\u003d100\u0026zl\u003d4",
	 "url":"http://www.google.com/local?source\u003duds\u0026q\u003dcategory%3A%E5%95%86%E5%8A%A1%E5%A4%A7%E5%8E%A6\u0026sll\u003d39.909477%2C116.414555\u0026latlng\u003d39909477%2C116414555%2C12097192132337754341\u0026near\u003d39.909477%2C116.414555",
	 "content":"",
	 "maxAge":604800,
	 "phoneNumbers":[{"type":"","number":"010-85188888"},{"type":"","number":"010-85186363"}],
	 "addressLines":["China","北京市东城区东长安街1号"]
	 },
*/
	dragend_call_back:function(d){
		var points=[];
		var o=d.responseData.results;
		//alert(o.length)
		for(var i=0;i<o.length;i++){
			points[i]={};
			points[i].address=o[i].title;
			points[i].lat=o[i].lat;
			points[i].lng=o[i].lng;
		}
		defaultmap.clear_all();
      	defaultmap.set_markers_to_map(points,'lat','lng','address','address');
      	//_this.set_markers_to_map(places, 'lat', 'lng', 'address', 'address');
      	defaultmap.map_initial_status();
		
		var bounds = new GLatLngBounds(txmap.pick_place_iframe.newbounds.getSouthWest(),txmap.pick_place_iframe.newbounds.getNorthEast() );
		var boundZoom = _this.map.getBoundsZoomLevel(bounds);
		_this.map.setCenter(bounds.getCenter(), boundZoom);
      	defaultmap.update_map_list_dom();
	},
	search:function(dom_id,dom_id_city){
		var v=$('#'+dom_id).val();
		if(dom_id_city){
			//v=$('#'+dom_id_city).val()+$('#'+dom_id).val();
		}
		defaultmap.address_parse(v);
	},
	search_city:function(th){
		defaultmap.address_parse(th.innerHTML);
		var box=document.getElementById('citybox');
		box.style.display='none';
		//alert(th.innerHTML)
	},
	search_city_submit:function(){
		var v=document.getElementById('city_value').value;
		if(v!='' && v!='输入城市名'){
			defaultmap.address_parse(v);
			var box=document.getElementById('citybox');
			box.style.display='none';
		}else{
			alert('请输入城市名');
		}
	},
	change_city_popup:function(){
		var box=document.getElementById('citybox');
		var d=box.style.display;
		if(d=='none'){
			box.style.display='block';
		}else{
			box.style.display='none';
		}
		
	},
	drag_and_drop:function(){
		
		var newpoint=_this.map.getCenter();
		txmap.pick_place_iframe.newbounds=_this.map.getBounds()
		var _lat=newpoint.lat();
		var _lng=newpoint.lng();
		//alert(_lat+','+_lng)
		var url='http://www.google.com/uds/GlocalSearch';
url+='?key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q';
url+='&v=1.0';
url+='&rsz=large';
url+='&sll='+_lat+','+_lng+',';
url+='&sspn=0';
url+='&q= category:商务大厦';
url+='&lssrc=lsc';
url+='&lscstyle=final';
url+='&start=0';
url+='&callback=txmap.pick_place_iframe.dragend_call_back';
if(google_key){ var key=google_key;}
url='http://www.google.com/uds/GlocalSearch?key='+key+'&v=1.0&rsz=large&sll='+_lat+','+_lng+'&sspn=1&q=%20category:%E5%95%86%E5%8A%A1%E5%A4%A7%E5%8E%A6&lssrc=lsc&lscstyle=final&start=1&callback=txmap.pick_place_iframe.dragend_call_back'
		//var url='http://www.google.com/uds/GlocalSearch?key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q&v=1.0&rsz=large&sll='+_lat+'%2C'+_lng+'&sspn=5.206601%2C0.911179&q=中国北京市朝阳区国贸%20category:%E5%95%86%E5%8A%A1%E5%A4%A7%E5%8E%A6&lssrc=lsc&lscstyle=final&start=0&callback=txmap.pick_place_iframe.dragend_call_back'
		$('head').append('<script src="'+url+'" type="text/javascript"></script>')
		
	},
	change_city:function(){
		
	}
};

//标注地点，个人首页，bind html
txmap.pick_place={
	init:function(c){
		//如送消息
		if(c && c.account=='post'){
			this.account='post'
		}
		//var h='<input id="search_place_text" type="text" /><input type="button" onclick="txmap.pick_place.search_place()" value="\u641c\u7d22" /><div id="search_place_list" class="search_place_list"></div>';
		ye_dialog.openUrl('/pick_place.php',732,460,'\u6807\u6CE8\u4F4D\u7F6E');
	},
	search_place:function(){
		var t=document.getElementById('search_place_text');
		var listbox=document.getElementById('search_place_list');
		var text=t.value;//搜索的内容
		if(text ==false){
			alert('\u8bf7\u8f93\u5165\u8981\u641c\u7d22\u7684\u5185\u5bb9');
			t.focus();
		}else{
			$.get(
				'/ajax/location.php',
				{name:text},
				function(b){
					listbox.innerHTML=b;
				}
			)
		}
	},
	choice:function(place){//place=在location.php中绑定函数时做为参数传入
		//发消息
		if(this.account && this.account=='post'){
			//保存起来等发送的时候一并传入
			document.getElementById('nowplace').innerHTML=place;
			ye_dialog.close();
			document.getElementById('placelist').style.display='none';
			this.account='';
		}else{
		//存入表
		$.post(
			'/ajax/checkin.php',
			{name:place},
			function(b){
				eval('var a={'+b+'}');
				//用户信息
				if(txmap.pick_place.account && txmap.pick_place.account=='placePage_post'){//地点页面的post
					if(document.getElementById('place_pose_pickplace_box')){
						$('#place_pose_pickplace_box').html('');
						document.getElementById('ye_dialog_iframe').contentWindow.document.getElementById('placenamebox').innerHTML=a.place.name;
						
					}
				}else{
					document.getElementById('nowplaceshow').innerHTML=a.place.name;
					//用户发信息选择地点
					document.getElementById('nowplace').innerHTML=a.place.name;
					ye_dialog.close();
					//刷新列表
					txmap.filter.init();
				}
			}
			)
		}
		
	}
}
//信息筛选
//用法,参数说明如下：如不传参则安注释中的备注，可只传其中任意个参数，则会覆盖原先的参数进行筛选
/*txmap.filter.init(
	{
		place:{},//地点
		region:'100Km',//范围
		bodys:'everybody',//人
		thing:['checkins','notes','photos'],//消息
		timeline://thimline参数
		{
			url:'/ajax/recentData_v2.php?focusGroupId=&aid=<? echo $home_type;?>&q=<? echo $q;?>',//第一次Load地址
			urlUpdate:'/ajax/recentData_update_v2.php?focusGroupId=0&aid=<? echo $home_type;?>&q=<? echo $q;?>',//更新数据地址
			currentPage:1,//第1页
			autoUpdate:true,//自动更新
			intervalTime:60000,//自动更新间隔时间
			type:1,//消息类型
			count:30,//每页最大条数
			sortType:$("#filterId").attr("checked") == true?2:1,//消息类型
			afterUpdateFun:function(){$("#myTips").hide();$("#pictureTips").hide();},//加载完成后运行
			emptyFun:function(){emptyFun1()}//消息为空时运行
		}
	}
)*/

txmap.filter={
	_a:{url:'/ajax/recentData_v2.php?focusGroupId=&aid=place&q=',
	    urlUpdate:'/ajax/recentData_update_v2.php?focusGroupId=0&aid=place&q=',
		currentPage:1,
		autoUpdate:true,
		intervalTime:60000,
		type:1,
		count:30,
		sortType:$("#filterId").attr("checked") == true?2:1,
		afterUpdateFun:function(){$("#myTips").hide();$("#pictureTips").hide();$("#allTips").hide();},
		emptyFun:function(){
			if (typeof emptyFun1 == 'function') {
				emptyFun1();
			}
		},
		f_text:0,
		f_photo:0,
		f_video:0,
		ajax_load:1
	},
	_b:{region:'all',bodys:'everybody',thing:[1,1,1], "lat":0, "lng":0, "place_id":0,"radius":0, "photo":'all', "ori":'all', "fix_user":0, "t":'self'},
	init:function(b){
		if(b && typeof b==='object'){			
			if(b.place){
				this._b.place=b.place;
			}
			if (b.lat){
				this._b.lat=b.lat;
			}
			if (b.lng){
				this._b.lng=b.lng;
			}
			if (b.place_id){
				this._b.place_id=b.place_id;
			}
			if(b.region){
				this._b.region=b.region;
			}
			if(b.bodys){
				this._b.bodys=b.bodys;
			}
			if(b.thing){
				this._b.thing=b.thing;
			}
			if(b.radius){
				this._b.radius=b.radius;
			}
			if(b.t){
				this._b.t=b.t;
			}
			if(b.timeline){
				for(var k in b.timeline){
					if (typeof b.timeline[k]!='undefined'){
						this._a[k]=b.timeline[k];
					}
				}
			}
		}		
		if (typeof filter_mode!='undefined' && filter_mode=='map') {
			this._a.page_size = 10;
			this._a.url = "/ajax/recentData_v2.php?aid=place";
			this._setup();
			$("#map_loading").removeClass("hide");
			//地图模式,获得数据后处理数据
			timeline.justLoadData(filter_map_callback);			
		}else{
			//当前是列表模式
			this._a.url  = '/ajax/recentData_v2.php?focusGroupId=&aid=index&q=';
			this._a.page_size = '';
			this._setup();
			timeline.init();
		}
	},
	_setup:function(b){
		
		var a=this;
		//alert(a._a.url)
		timeline.setup({
			url: a._a.url,
			urlUpdate: a._a.urlUpdate,
			currentPage: a._a.currentPage,
			ajax_load: a._a.ajax_load,
			autoUpdate: a._a.autoUpdate,
			intervalTime: a._a.intervalTime,
			type: a._a.type,
			count: a._a.count,
			sortType: a._a.sortType,
			afterUpdateFun: a._a.afterUpdateFun,
			emptyFun: a._a.emptyFun,
			place: a._b,
			page_size:a._a.page_size
		})
	}
}
//页面其它函数
txmap.pagehandle={
	//发文章时重新选择地点
	changplace:function(listid){
		var event = window.event ||this.changplace.caller.arguments[0];
		if(window.event)
			event.cancelBubble = true;
		else
	        event.stopPropagation(); 
			
		for(var i=1;i<4;i++){
				$('#hidden_nav_'+i).hide();
				$('#main_nav_'+i).removeClass('active')
		}
		var className = $('#'+listid).attr("class");
		if (className.indexOf('hide')!==-1){
			$('#'+listid).removeClass("hide");
		}else{
			$('#'+listid).addClass("hide");
		}
	},
	changplace_select:function(listid,con,placeid){
		$.post('/ajax/checkin.php',{place_id:placeid},function(){
				//document.getElementById('nowplaceshow').innerHTML=con;
				//document.getElementById('nowplace').innerHTML=con;	
				//document.getElementById('nowplaceshow').innerHTML=con;
				document.getElementById(listid).style.display='none';					
				//txmap.filter.init();
				setTimeout("window.location.reload()", 1000)
		})
		
		
	},
	//筛选列表切换
	changfilter:function(listid){
		var event = window.event ||this.changfilter.caller.arguments[0];
		if(window.event)
			event.cancelBubble = true;
		else
	        event.stopPropagation(); 
		$('#placelist').hide();
		var lists = $(".filter_nav .hidden_nav");
		var navs = $(".filter_nav .main_nav li")
		
		var nownav=document.getElementById('main_nav_'+listid);
		var nowlist=document.getElementById('hidden_nav_'+listid);
		if(nowlist.style.display=='none'){
			lists.hide();
			navs.removeClass('active');
			
			nowlist.style.display='';
			nownav.className='active';
		}else{
			nowlist.style.display='none'
			nownav.className='';
		}
	},
	//筛选列表选项
	changfilter_select:function(th,listid,navid,type,value,place_id, t){
		var nav=document.getElementById(navid);
		var nowlist=document.getElementById(listid);
		
		if(type!='thing'){
			var hrefs=nowlist.getElementsByTagName('a');
			for(var i=0;i<hrefs.length;i++){
				if(hrefs[i].className=='active'){
					hrefs[i].className='';
				}
			}
			th.getElementsByTagName('a')[0].className='active';
		}
		
		nav.innerHTML=th.getElementsByTagName('a')[0].innerHTML;
		nav.setAttribute('title',th.getElementsByTagName('a')[0].innerHTML)
		if(type=='region'){
			//txmap.filter._b.region=value;
			txmap.filter._b.radius=value;
			txmap.filter._b.place_id=place_id;
			txmap.filter._b.t = t;
			txmap.filter._b.bodys = 'all';
		}else if(type=='bodys'){
			txmap.filter._b.bodys=value;
		}else if(type=='thing'){
			var n=th.getAttribute('openr');
			if(n==1){
				th.setAttribute('openr','0');
				th.getElementsByTagName('a')[0].className='';
			}else if(n==0){
				th.setAttribute('openr','1');
				th.getElementsByTagName('a')[0].className='active';
				
				
			}
			var n0=document.getElementById('hidden_nav_3_1').getAttribute('openr');
			var n1=document.getElementById('hidden_nav_3_2').getAttribute('openr');
			var n2=document.getElementById('hidden_nav_3_3').getAttribute('openr');
			var shocon='';
			if(n0==1){
				txmap.filter._b.thing[0]=1;
				shocon+=''
			}else if(n0==0){
				txmap.filter._b.thing[0]=0;
			}
			if(n1==1){
				txmap.filter._b.thing[1]=1;
				shocon+='消息 '
			}else if(n1==0){
				txmap.filter._b.thing[1]=0;
			}
			if(n2==1){
				txmap.filter._b.thing[2]=1;
				shocon+='图片 '
			}else if(n2==0){
				txmap.filter._b.thing[2]=0;
			}
			
			if(n0==1 && n1==1 && n2==1){
				nav.innerHTML='全部';
			}else if(n0==0 && n1==0 && n2==0){
				nav.innerHTML='无';
			}else if(n1==0 && n2==0){
				nav.innerHTML='无';
			}else{
				nav.innerHTML=shocon;
			}
		}else if (type=='photo') {
			txmap.filter._b.photo=value;
		}else if (type=='ori'){
			txmap.filter._b.ori=value;
		}
		//触发新的搜索条件,所有的状态初始化, 搜索第一页, userphotoRoll第一位为0
		txmap.filter._a.currentPage = 1;
		txmap.userphotoRoll.re_init_info();
		//触发ajax
		txmap.filter.init()		
		nowlist.style.display='none';
	},
	//place页面三个功能
	checkIn:function(placeid,placename){
       if (txweb.user.isLogin == false) {
    	   window.location.href = txweb.user.loginURL;
        }else{
			var h='<div class="showSwfPannal"><h3 style="margin-top: 20px;">'+placename+'</h3><p><input class="input_button" type="button" value="标注" onclick="txmap.pagehandle.checkIn_sel(\''+placeid+'\')" /><input class="input_button" type="button" value="取消" onclick="ye_dialog.close()"/></p></div>';
			ye_dialog.openHtml(h,'标注地点',400,150);
		}
	},
	checkIn_sel:function(placeid){
		$.post('/ajax/checkin.php',{place_id:placeid},function(){
			ye_dialog.close();
			ye_msg.open("你已经把自己标注在这个位置", 1.5, 1);
			//$("#modal_check").hide();
			//$("#modal_post").fadeIn();
		})
	},
	favorite:function(){
		
		var h='<table style="width:100%"><tr>Name:<td></td><td>CANDY甜蜜蜜</td></tr><tr>Alias:<td></td><td><input id="newfavoritename" type="text" /></td></tr></table><input type="button" onclick="txmap.pagehandle.favorite_add()" value="Add to favorites" />';
		ye_dialog.openHtml(h,'Favorite this place',400,150);
		
	},
	favorite_add:function(name){
		var placeid=document.getElementById('placeid').value;
		var alcas=document.getElementById('newfavoritename').value;
		$.post(
			'/ajax/addFavorite.php',
			{place_id:placeid,alcas:alcas},
			function(b){
				if(b){ alert('成功');ye_dialog.close();}else{'不成功'}
				
			}
		)
	},
	post:function(url){
		//var h='<a style="background:red;display:block;height:300px;left:0px;position:absolute;top:-30px;width:500px;" href="####" onclick="ye_dialog.openHtml(h,\'Post2\',400,150)">xxxxxxxxxx</a>';

		///ye_dialog.openHtml(h,'Post',500,230);
		ye_dialog.openUrl(url,480,350,'评论位置','auto');

	},
	post_pickPlace:function(){
		txmap.pick_place.account="placePage_post";
		var h='';
		h+='<div id="place_pose_pickplace_box" >';
		h+='<div id="ye_dialog_window" style="  width: 500px; height: 340px; display: block;position:absolute;top:5px; _top:180px; left:-10px;">';
		h+='<a id="ye_dialog_close" title="关闭" onclick="(function(){document.getElementById(\'place_pose_pickplace_box\').innerHTML=\'\'})()" href="####"/>';
		h+='<div id="ye_dialog_title">Where are you?</div>';
		h+='<div id="ye_dialog_body" style="height: 202px;">';
		h+='<input type="text" id="search_place_text" />';
		h+='<input type="button" onclick="txmap.pick_place.search_place()"  value="搜索" />';
		h+='<hr/>';
		h+='<div id="search_place_list" class="search_place_list">';
		h+='</div>';
		h+='</div>';
		h+='</div>';
		if(document.getElementById('place_pose_pickplace_box')){
			$('#place_pose_pickplace_box').html(h);
		}else{
			$('#ye_dialog_body').append(h);
		}
		
	}
	
}
