J1616.Weather={$citys:null,config:{ckStr:"",city:"",district:"",prov:"",weatherCitys:[]},oldConfig:{city:"",prov:"",weatherCitys:[]},quickCitys:["北京","苏州","无锡","洛阳","大连","青岛","张家界","桂林","三亚","扬州","丽江","开封","景德镇","成都","阿坝|九寨沟","昆明","九江|庐山","汕头","南京","淄博","西安","厦门","武汉","重庆","长沙","上海","广州","深圳","杭州","池州|九华山"],cookieNames:[{name:"city",domain:J1616.Util.getDomain()},{name:"weatherCitys",domain:""}],_pv:null,_ct:null,_cityGn:"",_cityGw:"",_makeProvinces:function($items){var provs={};$items.each(function(){var t=this.pv[0],q=this.pv[1];if(typeof provs[t]=='undefined')
provs[t]=q;});for(var key in provs){var s=provs[key];provs[key]=[$items.filter(function(){return this.pv[0]==key}),s];}
var newProvs={},i=0,tmpArr=[];for(var k in provs){tmpArr[i]=[k,provs[k]];i++;}
tmpArr.sort(function(a,b){return a[1][1].charCodeAt(0)-b[1][1].charCodeAt(0)});$(tmpArr).each(function(){newProvs[this[0]]=this[1];});return newProvs;},_makeContinents:function($items){var provs={};$items.each(function(){var t=this.ct;if(typeof provs[t]=='undefined')
provs[t]=1;});for(var key in provs){provs[key]=[$items.filter(function(){return this.ct==key}),""];}
return provs;},_fillSel:function($citys,$continents){var _this=this,pv_1="",pv_2="",pv_3="",ct_1="",ct_2="";_this._pv=_this._makeProvinces($citys);_this._ct=_this._makeContinents($continents);for(var key in _this._pv){pv_1+="<option value=\""+key+"\" "+(key=="直辖市"?"selected=\"selected\"":"")+">"+_this._pv[key][1]+" "+key+"</option>";};pv_2+="<option value=''>--请选择--</option>";$(_this._pv["直辖市"][0]).each(function(){pv_2+="<option value=\""+this.n+"\">"+this.n+" "+key+"</option>";});pv_3+="<option value=''>--请选择--</option>";$('.unOverSeas_province').html(pv_1);$('.unOverSeas_city').html(pv_2);$('.unOverSeas_children').html(pv_3);for(var key in _this._ct){ct_1+="<option value=\""+key+"\">"+key+"</option>";};ct_2+="<option value=''>--请选择--</option>";$(_this._ct["亚洲"][0]).each(function(){ct_2+="<option value=\""+this.n+"\">"+this.n+"</option>";});$('.overSeas_continent').html(ct_1);$('.overSeas_city').html(ct_2);setTimeout(function(){$('.overSeas_continent').find("option[value='亚洲']").attr("selected",true);$('.overSeas_city').find("option:eq(1)").attr("selected",true);},0);},_makeZimuList:function(a){var _this=this,html="";var t=_this.$citys.filter(function(){var reg=new RegExp("^"+a.toUpperCase(),"g");var re=reg.test($(this).attr("py"));return re;});t.each(function(){html+="<span><a>"+__gaoliang(this.n,a.length)+"</a></span>";});$(".cityss").html(html);function __gaoliang(a,length){var re="<b class='red'>"+a.substr(0,length)+"</b>"+a.substring(length);return re;}},bindEvents:function(){var _this=this;var $div=$("#weather_div_dz"),$table=$("#weather_table_dz");$('.unOverSeas_province').bind("change",function(){_s(_this._pv,$(this));});$('.unOverSeas_city').bind("change",function(){_ss(_this._pv,$(this).prevAll("select").val(),$(this));});$('#gn .unOverSeas_city').bind("change",function(){_this.getWeather($(this).val());});$('.overSeas_continent').bind("change",function(){_s(_this._ct,$(this))});function _s(tmps,$this){var t=tmps[$this.val()][0];var d="",e="";for(var i=0;i<t.length;i++){if(i==0)d+="<option value=''>--请选择--</option>";d+="<option value='"+t[i].n+"'>"+t[i].n+"</option>";}
if(t[0]["c"]){e+="<option value=''>--请选择--</option>";}
if(e)
$this.siblings("select:eq(0)").html(d).siblings("select:eq(1)").html(e);else
$this.siblings("select:eq(0)").html(d);}
function _ss(tmps,prov,$this){var e="<option value=''>--请选择--</option>";if($this.val()){var t=$(tmps[prov][0]).filter(function(){return this.n==$this.val()});for(var i=0;i<t[0]["c"].length;i++){e+="<option value='"+(i?t[0]["c"][0]:"")+t[0]["c"][i]+"'>"+t[0]["c"][i]+"</option>";}}
var nextSel=$this.nextAll("select").html(e);setTimeout(function(){nextSel.find('option:eq(1)').attr("selected","selected");},0);}
$("ul.ns_tab01").tab({cssOn:"ns_tab01_on"});$("ul.ns_tab01>li>a").click(function(){if($("ul.ns_tab01>li>a").index($(this))==1){$("ul.ns_tab01>a").hide();}else{$("ul.ns_tab01>a").show();}
$("h1.ns_t04").html($(this).attr("city")+"天气预报");});$("#weather_btn_dz").click(function(){_this._getDingzhiCitys(_this.config.weatherCitys);$div.show();$table.hide();return false;});$(".zimu a:not(#zimuClear)").click(function(){var $old=$(".zimu a.zimu_on");$old.removeAttr("class");$(this).attr("class","zimu_on ns_bd04 ns_bg05");var v=$(".cityzimu input").val();v+=$(this).text();$(".cityzimu input").val(v);_this._makeZimuList(v);});$("#zimuClear").click(function(){var html="";$(".zimu a.zimu_on").removeAttr("class");$(".cityzimu input").val("");$(_this.quickCitys).each(function(){if(this.toString().indexOf('|')==-1){html+="<span><a _i=''>"+this+"</a></span>";}else{html+="<span><a _i='"+this.toString().split("|")[0]+"'>"+this.toString().split("|")[1]+"</a></span>";}});$(".cityss").html(html);});$(".cityss a").live("click",function(){var val=$.trim($(this).text());if($(this).attr("_i"))
_this.getWeather(val,$(this).attr("_i"));else
_this.getWeather(val);return false;});$(".search_layer a").mousedown(function(){var val=$.trim($(this).text());if(val)_this.getWeather(val);$("#keyword").blur();return false;});$("#weather_table_dz a").live("click",function(){var val=$.trim($(this).attr("_i")),text=$.trim($(this).text());if(val==text)
_this.getWeather(text);else
_this.getWeather(text,val.replace(text,""));return false;});$(".cityzimu input").keyup(function(){var v=$(this).val();if(v)
_this._makeZimuList(v);else
$("#zimuClear").click();});$(".btn_dz").click(function(){var wcs=_this.config.weatherCitys;if(wcs.length>=6){alert("最多只能定制6个城市");return false;}
var t=$(this).prev("select").val();var sel=$(this).prev("select")[0];var s=sel.options[sel.selectedIndex].text;if(t&&s){if($.inArray(t+"_"+s,wcs)==-1){wcs[wcs.length]=t+"_"+s;}
_this._getDingzhiCitys(wcs);}});$(".btn_dz_del").live("click",function(){var wcs=_this.config.weatherCitys;var t=$(this).parent().attr("_i")+"_"+$(this).parent().text();$(this).parent().remove();J1616.removeArrayItem(wcs,$.inArray(t,wcs));return false;});$("#btn_dz_save").click(function(){if(_this.config.weatherCitys.length==0){alert("请至少添加一个城市,最多6个");return false;}
_this.getDingzhiWeather(_this.config.weatherCitys);_this.oldConfig=J1616.str2obj(J1616.obj2str(_this.config));J1616.Util.setCookie(_this.cookieNames[1]["name"],_this.config.weatherCitys.join("|"));$div.hide();$table.show();});$("#btn_dz_cancel").click(function(){_this._getDingzhiCitys(_this.oldConfig.weatherCitys);_this.config=J1616.str2obj(J1616.obj2str(_this.oldConfig));$div.hide();$table.show();return false;});$("#btn_keyword").click(function(){var v=$.trim($("#keyword").val());if(v&&v!="请输入城市名"){_this.getWeather(v);$(".search_layer").hide();}});$("#keyword").focus(function(){$(".search_layer").show();}).blur(function(){$(".search_layer").hide();}).keyup(function(e){e=e||window.event;if(e.keyCode==13)
$("#btn_keyword").click();}).rit();},_getDingzhiCitys:function(wcs){var html='';$("#dz_added_citys").empty();$(wcs).each(function(){var s=this;if(s.toString().indexOf("_")==-1)
s=s+"_"+s;if(s.split("_").length>=2)
html+="<span class=\"follow-set-mycity\" _i=\""+s.split("_")[0]+"\">"+s.split("_")[1]+"<a href=\"#\" title=\"删除\" class=\"btn_dz_del\"></a></span>";});$("#dz_added_citys").html(html);},citySelChange:function(obj,isGw){var _this=this,val=$(obj).val(),parentCity=isGw?"":$(obj).find("option:eq(1)").attr("value");if(val){if(val!=parentCity)val=val.replace(parentCity,"");_this.getWeather(val,parentCity);}},getWeather:function(city,parentCity){if(!city)return false;var _this=this;if(!parentCity)parentCity=city;var fileName=parentCity==city?city:parentCity+city;var h=[],item=_this.$citys.filter(function(){return this.n==parentCity})[0];if(!item)return false;var isGw=item.i;if(isGw){$("ul.ns_tab01>li>a:eq(1)").attr("city",city);$(".ns_tab01>li>a:eq(1)").click();}else{$("ul.ns_tab01>li>a:eq(0)").attr("city",city);$(".ns_tab01>li>a:eq(0)").click();_this.config.city=parentCity;_this.config.district=city;_this.config.prov=item.pv[0];_this.config.ckStr=_this.config.city+"_"+_this.config.district+"_"+_this.config.prov;}
_this.huisuSel(fileName,parentCity,item);$(".main:visible").html('<div class="w-loading"><img src="http://i.9533.com/img/loading.gif" width="32" height="32" />&nbsp;&nbsp;正在加载...</div>');$.ajax({url:'grab/weather/'+encodeURIComponent(encodeURIComponent(fileName))+'.js?_='+_this._getRandom(),type:"GET",cache:true,dataType:"script",success:function(){var timer=setInterval(function(){if(J1616_weather_info){var w=J1616_weather_info,info=w.info,indexStyles=["warea-zs-zyx","warea-zs-kq","warea-zs-cy","warea-zs-ss",];if(info.today.描述.length&&info.today.气温&&info.today.日期&&info.today.图标.length){if(!isGw){h[h.length]="<div class=\"warea-c ns_bg01 ns_bd04\">";h[h.length]=" <ul class=\"warea-cin\"><li>";h[h.length]="   <h3>"+(parentCity==city?w.city[1]:w.city[1].replace(parentCity,""))+"</h3>";h[h.length]="  </li><li>"+info.today.日期+"</li><li>";for(var i=0;i<info.today.图标.length;i++){h[h.length]="<img src=\"http://i.9533.com/weather/img/"+info.today.图标[i]+".png\" />";}
h[h.length]="</li><li class=\"warea-q\">"+(typeof info.today.描述[0]=='undefined'?"":info.today.描述[0])+"</li>";h[h.length]="  <li class=\"warea-q\">"+(typeof info.today.气温=='undefined'?"":info.today.气温)+"</li>";h[h.length]="  <li class=\"warea-q2\">"+(typeof info.today.描述[1]=='undefined'?"":info.today.描述[1])+"</li>";h[h.length]="  <li class=\"warea-s ns_bd04 ns_bg06\">相关地区:";h[h.length]="       <select id=\"city_children_sel\" onchange=\"J1616.Weather.citySelChange(this);\">";h[h.length]="  <option value=\"\">--请选择--</option>";for(var i=0;i<item.c.length;i++){if(i==0)
h[h.length]="  <option value=\""+item.c[0]+"\">"+item.c[0]+"</option>";else
h[h.length]="  <option value=\""+item.c[0]+item.c[i]+"\">"+item.c[i]+"</option>";}
h[h.length]="  </select></li>";h[h.length]=" </ul>";h[h.length]=" <ul class=\"warea-zs\">";for(var i=0;i<info.index.length;i++){h[h.length]="  <li class=\""+indexStyles[i]+"\">";h[h.length]="   <h3 class=\"ns_t05\">"+info.index[i].标题+"："+info.index[i].概要+"</h3>";h[h.length]="   <p>"+info.index[i].详述+"</p>";h[h.length]="  </li>";}
h[h.length]=" </ul>";h[h.length]="</div>";h[h.length]="<div class=\"cfsite\">";h[h.length]=" <div class=\"cfsite-tl\">";h[h.length]="  <h2>未来6天</h2>";h[h.length]=" </div>";h[h.length]=" <div class=\"cfsite-c ns_bg01 ns_bd04\" style=\"padding: 10px 0\">";for(var i=0;i<info.next.length;i++){h[h.length]="  <ul class=\"w-7"+(i!=info.next.length-1?" ns_bd04_r":"")+"\">";h[h.length]="   <li class=\"w-7-date\">"+info.next[i].日期+"</li>";h[h.length]="   <li>";for(var j=0;j<info.next[i].图标.length;j++){h[h.length]="<img src=\"http://i.9533.com/weather/img/w/"+info.next[i].图标[j]+".png\" />";}
h[h.length]="</li>";h[h.length]="   <li>"+info.next[i].描述[0]+"</li>";h[h.length]="   <li>"+info.next[i].气温+"</li>";h[h.length]="   <li>"+info.next[i].描述[1]+"</li>";h[h.length]="  </ul>";}
h[h.length]=" </div>";h[h.length]="</div>";var cityName=(parentCity==city?w.city[1]:w.city[1].replace(parentCity,""));$(".warea-tl-dz").html("在首页显示"+cityName+"天气").one("click",function(){return _this.warea_tl_dz(this);});if(J1616.Weather.outLine){$(".warea-tl-dz").hide();}}else{h[h.length]="<div class=\"warea-c ns_bg01 ns_bd04\">";for(var i=0;i<info.next.length;i++){h[h.length]=" <ul class=\"warea-cin2"+(i!=info.next.length-1?" ns_bd04_r":"")+"\">";h[h.length]="  <li>"+info.next[i].日期+"</li>";h[h.length]="  <li><img src=\"http://i.9533.com/weather/img/"+info.next[i].图标[0]+".png\" /></li>";h[h.length]="  <li class=\"warea-b\">"+info.next[i].描述[0]+"</li>";h[h.length]="  <li class=\"warea-b\">"+info.next[i].气温+"</li>";h[h.length]="  <li>"+info.next[i].描述[1]+"</li>";h[h.length]=" </ul>";}
if(!info.next.length){h[h.length]="<div class='w-error'>未找到"+fileName+"的天气预报，请查看其相邻的城市天气</div>";}
h[h.length]="</div>";$(".warea-tl-dz").html("").attr("_i","").attr("href","").attr("_j","").unbind();}
$(".main:visible").html(h.join(""));}else{$(".main:visible").html("<div class=\"w-error\">未找到"+fileName+"的天气预报，请查看其相邻的城市天气</div>")}
$("#wtitle").html("<h1 class=\"ns_t04\">"+(parentCity==city?w.city[1]:w.city[1].replace(parentCity,""))+"天气预报</h1>（中央气象局"+info.pubdate.split(" ")[1]+"发布）");clearInterval(timer,timer=null);}},500);},error:function(){$(".main:visible").html("<div class=\"w-error\">未找到"+fileName+"的天气预报，请确保您输入了正确的城市名称</div>")}});},_getRandom:function(){var a=new Date();var _=""+a.getHours()+(a.getMinutes()/10).toFixed(0);return _;},getDingzhiWeather:function(citys){var _this=this;$("#weather_table_dz").empty();$("#weather_table_dz").html('<tr><th width="80">城市</th><th width="100">天气</th><th>气温</th></tr>');var i=0;(function a(){var s=citys[i];if(s.toString().indexOf("_")==-1)
s=s+"_"+s;if(s.split("_").length>=2){$.ajax({url:'grab/weather/'+encodeURIComponent(encodeURIComponent(s.split("_")[0]))+'.js?_='+_this._getRandom(),dataType:"script",type:"GET",cache:true,success:function(){var timer=setInterval(function(){if(J1616_weather_info){var $weather=J1616_weather_info;$("#weather_table_dz").append(_showWeather($weather,s.split("_")[1]));i++;if(i<citys.length)a();clearInterval(timer,timer=null);}},500);}});}})();function _showWeather($weather,cityName){var o=$weather.info.today;return'<tr><td><a href="#" _i="'+$weather.city[1]+'">'+cityName+'</a></td><td>'+(o.描述.length?o.描述[0]:"无")+'</td><td>'+(o.气温?o.气温:"无")+'</td></tr>';}},huisuSel:function(cityFileName,parentCity,item){var _this=this,pv_2="",pv_3="",ct_2="";if(!item.i){$('.unOverSeas_province').find("option[value='"+item.pv[0]+"']").attr("selected","selected");pv_2="<option value=''>--请选择--</option>";$(_this._pv[item.pv[0]][0]).each(function(i){pv_2+="<option value='"+this.n+"'>"+this.n+"</option>"});$('.unOverSeas_city').html(pv_2);setTimeout(function(){$('.unOverSeas_city').find("option[value='"+item.n+"']").attr("selected","selected");},0);pv_3="<option value=''>--请选择--</option>";if(cityFileName!=parentCity){for(var i=0;i<item["c"].length;i++){if(i==0){pv_3+="<option value='"+item["c"][i]+"'>"+item["c"][i]+"</option>";}else{pv_3+="<option value='"+item["c"][0]+item["c"][i]+"'>"+item["c"][i]+"</option>";}}
$('.unOverSeas_children').html(pv_3);setTimeout(function(){$('.unOverSeas_children').find("option[value='"+cityFileName+"']").attr("selected","selected");},0);}
else{for(var i=0;i<item["c"].length;i++){if(i==0){pv_3+="<option value='"+item["c"][i]+"' selected='selected'>"+item["c"][i]+"</option>";}else{pv_3+="<option value='"+item["c"][0]+item["c"][i]+"'>"+item["c"][i]+"</option>";}}
$('.unOverSeas_children').html(pv_3);}}else{$('.overSeas_continent').find("option[value='"+item.ct+"']").attr("selected","selected");ct_2="<option value=''>--请选择--</option>";$(_this._ct[item.ct][0]).each(function(i){ct_2+="<option value='"+this.n+"'>"+this.n+"</option>"});$('.overSeas_city').html(ct_2);J1616.Util.console("info",item.n);setTimeout(function(){$('.overSeas_city').find("option[value='"+item.n+"']").attr("selected","selected");},0);}},init:function(){var _this=this;J1616.Weather.outLine=false;_this.$citys=$(J1616_weather_citys);var _location=window.location.href;var regex=/([^.]+)\.(?:com|net)\/?$/i;var homePath='http://weather.1616.net';if(regex.test(_location)&&(RegExp.$1!='1616'&&RegExp.$1!='1616dh')){var _path=RegExp.$1,homePath='http://www.'+_path+'.com';J1616.Weather.outLine=true;$('#logo').html('<a href="http://www.'+_path+'.com/"><img alt="返回首页" src="http://www.'+_path+'.com/img/logo.gif" /></a>');$('#adviceHref').hide();$('#homeHref, #pathl>a').attr('href','http://www.'+_path+'.com');}
if(!document.all){$('#pathr > a:first').hide();}
$('#logo,#pathr').show();$('#pathr > a').click(function(){J1616.Util.setHome(this,homePath)});_this.config.ckStr=decodeURIComponent(J1616.Util.getQueryString("city"))||J1616.Util.getCookie("city");_this.config.weatherCitys=J1616.Util.getCookie("weatherCitys")?J1616.Util.getCookie("weatherCitys").split('|'):[];_this.oldConfig=J1616.str2obj(J1616.obj2str(_this.config));$("#gn .main").addClass("mainGn");$("#gw .main").addClass("mainGw");_this._fillSel(_this.$citys.filter(function(){return(this.i==0)}),_this.$citys.filter(function(){return(this.i==1)}));_this.bindEvents();$("#zimuClear").click();if(!_this.config.ckStr){$.getScript('http://chaxun.1616.net/iptolocal.php',function(){_this.config.city=WData[1];_this.config.district=WData[1];_this.config.prov=WData[3];_this.config.ckStr=_this.config.city+"_"+_this.config.district+"_"+_this.config.prov;J1616.Util.setCookie(_this.cookieNames[0]["name"],_this.config.ckStr,null,null,_this.cookieNames[0]["domain"]);_door(_this.config.ckStr)});}else{_door(_this.config.ckStr)}
function _door(cookieStr){var defaultOverseaCity="马尼拉";$("ul.ns_tab01>li>a:eq(1)").attr("city",defaultOverseaCity);$.ajax({url:'grab/weather/'+encodeURIComponent(encodeURIComponent(defaultOverseaCity))+'.js?_='+_this._getRandom(),type:"GET",cache:true,dataType:"script",success:function(){var timer=setInterval(function(){if(J1616_weather_info){var w=J1616_weather_info,h=[],info=w.info,indexStyles=["warea-zs-zyx","warea-zs-kq","warea-zs-cy","warea-zs-ss",];if(info.today.描述.length&&info.today.气温&&info.today.日期&&info.today.图标.length){h[h.length]="<div class=\"warea-c ns_bg01 ns_bd04\">";for(var i=0;i<info.next.length;i++){h[h.length]=" <ul class=\"warea-cin2"+(i!=info.next.length-1?" ns_bd04_r":"")+"\">";h[h.length]="  <li>"+info.next[i].日期+"</li>";h[h.length]="  <li><img src=\"http://i.9533.com/weather/img/"+info.next[i].图标[0]+".png\" /></li>";h[h.length]="  <li class=\"warea-b\">"+info.next[i].描述[0]+"</li>";h[h.length]="  <li class=\"warea-b\">"+info.next[i].气温+"</li>";h[h.length]="  <li>"+info.next[i].描述[1]+"</li>";h[h.length]=" </ul>";}
if(!info.next.length){h[h.length]="<div class='w-error'>未找到"+defaultOverseaCity+"的天气预报，请查看其相邻的城市天气</div>";}
h[h.length]="</div>";$("#gw .main").html(h.join(""));}else{$("#gw .main").html("<div class=\"w-error\">未找到"+defaultOverseaCity+"的天气预报，请查看其相邻的城市天气</div>")}
clearInterval(timer,timer=null);}},500);},error:function(){$("#gw .main").html("<div class=\"w-error\">未找到"+defaultOverseaCity+"的天气预报，请确保您输入了正确的城市名称</div>")}});if(cookieStr.indexOf("_")==-1)
cookieStr=cookieStr+"_"+cookieStr+"_"+cookieStr;var _cfgs=_u(cookieStr.split("_"));_this.config.ckStr=cookieStr;_this.config.city=_cfgs[0];_this.config.district=_cfgs[1];_this.config.prov=_cfgs[2];_this.getWeather(_cfgs[1],_cfgs[0]);_this.config.weatherCitys=(_this.config.weatherCitys.length)?_this.config.weatherCitys:[_g(_cfgs)];_this.oldConfig.weatherCitys=J1616.str2obj(J1616.obj2str(_this.config.weatherCitys));_this.getDingzhiWeather(_this.config.weatherCitys);_this._getDingzhiCitys(_this.config.weatherCitys);function _g(cfgs){var re=cfgs[0]+cfgs[1]+"_"+cfgs[1];if(cfgs[1]==cfgs[0])
re=cfgs[0]+"_"+cfgs[1];return re;}
function _u(cfgs){if(cfgs[0]!=cfgs[1]&&cfgs[0].indexOf(cfgs[1])!=-1){cfgs[0]=cfgs[0].replace(cfgs[1],"");}
return cfgs;}}}};J1616.Weather.init();