
_package("bjmap.main");


bjmap.main.module=function(){
	var $this=this;
	
	/**
	 * 返回主页面
	 */
//	var homepage=DCI.get("homepage");
//	DCI.event.bindDom(homepage,"click",function(){
//		//var url=homepage.href;
//		var url=DCI.UserLocationURL+"/index.html";
//		//主页面
//		location.href=url;
//		return false;
//	});
	
	
	/**
	 * 绑定模块切换
	 */
	var module=DCI.get("module");
	var lists=module.getElementsByTagName("li");
	var modules=new Array();
	
	DCI.each(lists,function(li,i){
		var li_span=DCI.browser.msie?li.firstChild:li.firstElementChild;
		var value=li_span.getAttribute("value");modules[value]={li:li};
		DCI.event.bindDom(li,"click",function(){
			switcher.call($this,li);
		});
		DCI.event.bindDom(li,"mouseover",function(){
			DCI.addClass(li_span,"module_li_text_hover");
		});
		DCI.event.bindDom(li,"mouseout",function(){
			DCI.removeClass(li_span,"module_li_text_hover");
		});
	});
	
	
	/**
	 * @type 变更模块
	 * @param {string} moduleName 模块名称(search 地图搜索、near 周边搜索、bus 公交查询、navigation 驾车导航)
	 */
	this.changeModule=function(moduleName){
		var module=modules[moduleName];
		if(module){
			switcher.call(this,module.li);
		}
	}
	/**
	 * @type 变更公交类型
	 * @param {string} busType 模块名称(transfer 换乘, line 线路名称查询、station 站点名称查询)
	 */
	this.changeBusType=function(busType){
		if(busType=="line"){
			busSwitcher.call(this,radios[1]);
		}else if(busType=="transfer"){
			busSwitcher.call(this,radios[0]);			
		}else if(busType=="station"){
			busSwitcher.call(this,radios[2]);			
		}
	}
	
	function switcher(li){
		//隐藏热门分类			
//		var popsearch=DCI.get("popsearch");
//		popsearch.style.display="none";
//		resize();
		//获取被点中的模块
		var li_span=void(0),value="",li_bg=void(0);
		if(DCI.browser.msie){
			li_span=li.firstChild;
			value=li_span.value;
			li_bg=li_span.nextSibling.nextSibling;	//获取div背景
		}else if(DCI.browser.mozilla){
			li_span=li.firstElementChild;
			value=li_span.getAttribute('value');
			li_bg=li_span.nextSibling.nextSibling;
		}else
			return;	
			
		//热门分类特殊处理
		if(value=="hotpop"){
			pop.show();
		}else{
			pop.hide();
		}
		//地图api
		if(value=="api"){
			//location.href=DCI.UserLocationURL+"/api.html";
			return ;
		}
			
		//控制模块对应的搜索框显示与隐藏
		if(this.currentNode){
			this.currentNode.style.display="none";
			DCI.removeClass(this.currentLi,"module_li_seleted");
		}
		var div=DCI.get(value);	//获取被点钟各模块的搜索部分的div元素，对其进行显示
		if(!div)
			return;
		div.style.display="block";
		div.style.zIndex=1;
		this.currentNode=div;
		this.currentLi=li;
		DCI.addClass(li,"module_li_seleted");
		
		if(!window.right)return;
		//1 导航查询，2公交查询
		if(value=="bus"){	//选择公交模块时，右键根据公交查询
			window.right.type=2;			
		}else if(value=="navigation"){		//选择导航时，右键根据导航查询
			window.right.type=1;
		}else{
			window.right.type=void(0);		//其他模块时，采取默认
		}
	};
	switcher.call(this,lists[0]);
	
	/**
	 * 绑定公交功能切换
	 */
	var radios=DCI.get("bustype").getElementsByTagName("input");
	DCI.each(radios,function(radio,i){
		DCI.event.bindDom(radio,"click",function(){
			busSwitcher.call($this,radio);
		});
	})
	
	function busSwitcher(radio){
		var id=void(0);
		if(this.currentBusModule){
			this.currentBusModule.style.display="none";	
		}
		if(DCI.browser.msie)
			id=radio.value;
		else if(DCI.browser.mozilla)
			id=radio.getAttribute('value');		
		else
			return;
		var div=DCI.get(id);
		div.style.display="block";
		div.style.zIndex=1;
		radio.checked=true;
		this.currentBusModule=div;
	};
	busSwitcher.call(this,radios[0]);
	
	
	/**
	 * 隐藏结果
	 */
//	var expand=DCI.get("body_expand");
//	DCI.event.bindDom(expand,"click",hidxparesult,this,[expand]);
	this.isClose=false;
	$("#body_expand").bind("click",hidxparesult)
	function hidxparesult(event){
		//获取元素
		var result=$("#body_result");
		var mapbox=$("#body_mapbox");
		var mapcontainer=$("#mapcontainer");
		var expand=$("#body_expand");
		//根据关闭状态执行相应的显隐操作。
		if(!$this.isClose){
			result.css("display","none");
			//展开模块宽度
			expand.css({
				left:0,
				backgroundImage:"url(images/main/miniright.png)"
			});
			mapbox.css({
				width:mapbox.outerWidth()+result.outerWidth(),
				left:expand.outerWidth(true)
			});
			mapcontainer.css({
				width:mapbox.innerWidth()
			});
			$this.isClose=true;
		}else{
			result.css("display","block");
			//展开模块宽度
			expand.css({
				left:result.outerWidth(true),
				backgroundImage:"url(images/main/minileft.png)"
			});
			mapbox.css({
				width:mapbox.outerWidth()-result.outerWidth(),
				left:result.outerWidth()+expand.outerWidth(true)
			});
			mapcontainer.css({
				width:mapbox.innerWidth()
			});
			$this.isClose=false;
		}
		map.resizeMap();
	}
	
	
	/**
	 * 绑定文本框处理事件
	 */
	bjmap.bindTxt();

	
	/**
	  * 正在查询
	  */
	var searchingDiv=document.createElement("div");
	searchingDiv.innerHTML="正在查询.";
	searchingDiv.className="searching";
	searchingDiv.style.display="none";
	DCI.get("body_result").appendChild(searchingDiv);
	var maxvalue=4;
	var starvalue=1;
	var curtvalue=1;
	var timerID;
	
	this.load=function(){
		curtvalue=1;
		searchingDiv.style.display="block";
		timerID=setInterval(settext,500);
	};
	
	var settext=function(){
		var poistr="";
		for(var i=0;i<curtvalue;i++){
			poistr+=".";
		}
		searchingDiv.innerHTML="正在查询"+poistr;
		if(curtvalue<maxvalue){
			curtvalue++;
		}else{
			curtvalue=starvalue;
		}
	};
	
	this.close=function(){
		 clearInterval(timerID);
		 searchingDiv.style.display="none";
	};
}
