// JavaScript Document
;(function($){
		   $.fn.jCompany=function(options){
			   var settings={
				   defaultSelectedCity:"",
				   defaultHotCity:"",
				   tips:""
				   };
			   var op=$.extend(settings,options);
			   var $this=$(this);
			   var citydata=null;
			   var windowid="selectcity";
			   var timeoutid=null;
			   var searchcitypopwincontent=null;
			   var resizeBox=function(){
				   //alert(letterNumber)
				   $this.css({"width":38+$this.find("#lable").text().length/1*12+"px"})
				   }
			   resizeBox();

//			   var tempcity={};//临时的城市json对象;
//			   $(this).blur(function(){
//									 $.msgbox.closemsgbox(windowid);
//									 })
			   
			   var hideSelectCity=function(){
				   $("#"+windowid).remove();
				   }
			   var checkExternalClick=function(event){
				   var $target = $(event.target);
				   if ($target.parents('#' + windowid).length==0 && !$target.hasClass("hasselectcity")){
					   setTips();
					   hideSelectCity();
					   }
				   }
			   var setTips=function(){
				   if ($this.val()==""){$this.val(op.tips).attr("title",op.tips)}
				   }
			   var initSelectCity=function(){
				   setTips();
				   $this.addClass("hasselectcity");
				   $.getJSON("../images/citydata.js",function(data){citydata=data;})
				   $.get(
							
						 function(data){
							 searchcitypopwincontent=data;
							 }
						 )
				   //$(document).mousedown(function(event){checkExternalClick(event)});
				   }
			   initSelectCity();
			   var showHotCity=function(obj){
				   var offsetleft=$(obj).offset().left;
				   var offsettop=$(obj).offset().top+$(obj).innerHeight();
				   offsetleft=offsetleft-260-5+$(obj).width();
				   offsettop=offsettop-190+$(obj).height();
				   
				   $.get(
						 "../images/hotcity.html",
						 function(data){
							 var $popwin=$.msgbox.popupwin(windowid,260,100,"",data).css({"top":offsettop+"px","left":offsetleft+"px"}).addClass("popwin_"+windowid);
							 $popwin.find("#hotcitys li").click(function(){
																		 /*alert($this.parent().find("div[id='header_changecity_lable']").html());*/
																		 
																		 /*跳转页面*/
																		 
																		 $.msgbox.closemsgbox(windowid);return false;
																		 })
							// $popwin.find("#hotcity").click(function(){return false;})
							
							 }
						 )
				   }
			   
			  
			   
			   
			   

			   
			   $(this).click(function(){
									 if ($(this).attr("value")==op.tips || $(this).attr("value")==""){
										 $(this).attr("value","")
										 showHotCity(this);
										 }
									 else{//搜索
										 searchCity(this);
										 }
									 
									 })
			   
			   }
		   })( jQuery );