//Blues Javascript 函数库
//2012-11-28:函数库建立
// 定义全局变量
var ajaxPost="GET",ajaxCache=true;
var ie6=$.browser.msie&&($.browser.version=="6.0"||($.browser.version=="7.0"&&document.documentMode==7));
// DOM准备好时执行
$(function(){
// 全局Ajax设置
$.ajaxSetup({timeout:1e4,cache:ajaxCache});
// 检测浏览器
ie6&&$("body").prepend("
");
// 去掉A标签焦点
$("a").focusin(function(){this.blur()});
// 图片链接淡入淡出效果
$(".ani img")[0]&&$(".ani img").live({mouseenter:function(){$(this).stop().fadeTo(100,0.8)},mouseleave:function(){$(this).stop().fadeTo(100,1)}});
// 动作确认属性
$("[data-confirm]")[0]&&$("[data-confirm]").click(function(){return confirm($(this).attr("data-confirm"))});
// 历史返回属性
$("[data-back]")[0]&&$("[data-back]").click(function(){window.history.go($(this).attr("data-back"));return !1});
// 按钮跳转属性
$("button[data-url]")[0]&&$("button[data-url]").click(function(){Jump($(this).attr("data-url"))});
// 下拉框选择默认值
$("select[data-selected]")[0]&&setTimeout(function(){$("select[data-selected]").each(function(){$(this).find("option[selected]").removeAttr("selected").end().find("option[value='"+$(this).attr("data-selected")+"']").attr("selected","selected")})},0);
// 表单提交时检查正则
$("form").submit(function(){return RegForm($(this))});
/* 以下为私有程序 */
// 菜单导航事件
!ie6&&$("div.header ul.menu li").mouseenter(function(){
$(this).find("div").fadeIn(200);
}).mouseleave(function(){
$("div.header ul.menu div").hide();
});
// 类下拉框事件
$(".layer").click(function(){
$(this).next().fadeOut(100).fadeTo(100,0.95,function(){$("html").off().one("click",function(){$(".layer").next().fadeOut(100)})});
return !1;
});
// 插入分享代码
window._bd_share_config={"common":{"bdText":$("meta[name='description']").attr("content"),"bdMiniList":["tsina","tqq","qzone","weixin","sqq","tqf","renren","kaixin001","douban","tieba","youdao","linkedin"]},"slide":{"type":"slide","bdImg":"3","bdPos":"right","bdTop":"140"}};
with(document)0[(getElementsByTagName("head")[0]||body).appendChild(createElement("script")).src="http://bdimg.share.baidu.com/static/api/js/share.js"];
// 首页
if ($("body#index")[0]){
isPad()&&Jump("http://m.mangshan.net/");
FadeSlide($("ul.banner"));
};
// 留言评论页
if ($("body#service_message")[0]){
$("form.msg_form").submit(function(){
Locked();
$.ajax({url:$("form.msg_form").attr("data-ajax"),data:$("form.msg_form").serialize(),type:ajaxPost,success:function(data){
UnLocked();
$("form.msg_form")[0].reset();
data.split("|")[0]=="done"?Alert("留言已提交,我们将尽快回复"):Alert("留言提交失败,请联系0370-5970222");
},error:function(){
UnLocked();
Alert("服务器响应超时,请稍后重试");
}});
return !1;
});
};
// 网上导游页
if ($("body#map_tour")[0]){
swfobject.embedSWF("uploadfile/map/map_v01.swf","guide",$("div#guide").width(),$("div#guide").height(),"10.0.0","false");
};
// 电子地图页
if ($("body#map_baidu")[0]){
BaiduMap();
};
// 全景欣赏页
if ($("body#map_pano")[0]){
var v="VT01";
GetVar("id")!=""&&$("p .button").each(function(){GetVar("id")==$(this).attr("data-pano")&&(v=$(this).attr("data-pano"))});
$("p .button").click(function(){
$("div#pano").empty();
Pano($(this).attr("data-pano"));
$(this).parent().find(".button").removeClass("button_hover");
$(this).addClass("button_hover");
});
$("p .button[data-pano='"+v+"']").click();
/**
$("#krpanoSWFObject").live("dblclick",function(){
var dom=$(this)[0],n=new Date().getTime();
dom.call("screentosphere(mouse.x,mouse.y,ath,atv)");
var ath=dom.get("ath").toFixed(2),atv=dom.get("atv").toFixed(2);
dom.call("addhotspot(hotspot_"+n+");set(hotspot[hotspot_"+n+"].url,images/vr_hotspot.png);set(hotspot[hotspot_"+n+"].crop,240|0|60|50);set(hotspot[hotspot_"+n+"].ath,"+ath+");set(hotspot[hotspot_"+n+"].atv,"+atv+")");
$("div#pano").parent().next("textarea").remove();
$("div#pano").parent().after("\n");
$("div#pano").parent().next("textarea").one("mouseover",function(){$(this)[0].select()});
});
/**/
};
// 在线预定页
if ($("body#shop")[0]){
$("title").before("");
$.getScript("inc/jquery_calendar.js",function(){$("div.main div.shop_search form input").each(function(){
$(this).attr("readonly","readonly").calendar({btnBar:$(this).attr("data-format")==undefined?!1:!0,minDate:$(this).attr("data-mindate"),maxDate:$(this).attr("data-maxdate"),format:$(this).attr("data-format")});
})});
};
// 商品详情页
if ($("body#shop_info")[0]){
// 预订信息层事件
$("div.shop_goods button.a").click(function(){$("div.shop_goods div.goods_info").fadeToggle(100)});
// 订购数量
var dom=$("div.shop_summary input:eq(0)");
dom.val(dom.attr("data-max")>0?1:0).keyup(function(){
/^[0-9]*[1-9][0-9]*$/.test($(this).val())||$(this).val("1");
($(this).val()|0)>$(this).attr("data-max")&&$(this).val($(this).attr("data-max"));
});
$("div.shop_summary span:eq(0)").click(function(){dom.attr("data-max")!=0&&((dom.val()|0)-1>1?dom.val((dom.val()|0)-1):dom.val("1"))});
$("div.shop_summary span:eq(1)").click(function(){dom.attr("data-max")!=0&&((dom.val()|0)+1dom.find("li").size()-1?dom.data("data-n",0):dom.data("data-n",dom.data("data-n")+1);
ie6?dom.find("li:eq("+dom.data("data-n")+")").show():dom.find("li:eq("+dom.data("data-n")+")").fadeIn(1e3);
};
if (dom.find("li").size()>1){
var s=setInterval(function(){this.rFade()},t);
dom.mouseenter(function(){clearInterval(s)}).mouseleave(function(){s=setInterval(function(){this.rFade()},t)});
};
}
//函数:百度地图展示(起点纬度,起点经度)
function BaiduMap(x,y){
var map=new BMap.Map("container");
map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.MapTypeControl());
if (x==undefined){
var Point=new BMap.Point(116.523138,34.175456),marker=new BMap.Marker(Point);
map.centerAndZoom(Point,14);
map.enableScrollWheelZoom();
map.addOverlay(marker);
marker.setAnimation(BMAP_ANIMATION_BOUNCE);
$("a[data-x]").click(function(){
$("a[data-x]").removeClass("now");
$(this).addClass("now");
BaiduMap($(this).attr("data-x"),$(this).attr("data-y"));
});
}else{
var routePolicy=[BMAP_DRIVING_POLICY_LEAST_TIME,BMAP_DRIVING_POLICY_LEAST_DISTANCE,BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
var driving=new BMap.DrivingRoute(map,{renderOptions:{map:map,autoViewport:true},policy:routePolicy[0]});
driving.search(new BMap.Point(x,y),new BMap.Point(116.523138,34.175456));
};
}
//函数:载入全景(文件夹)
function Pano(v){
v="uploadfile/pano/"+v+"/";
embedpano({swf:"inc/pano.swf",xml:v+"pano.xml",target:"pano",html5:"prefer",passQueryParameters:false,onready:function(){
$("#krpanoSWFObject pre:last").html(unescape(escape($("#krpanoSWFObject pre:last").html()).replace(/%u6E56%u5357%u7701%u53CB%u8BDA%u79D1%u6280%u6709%u9650%u516C%u53F8/g,"%u5e03%u9c81%u65af%u7f51%u7edc")));
setTimeout(function(){
$("#krpanoSWFObject")[0].set("plugin[button_vr].visible",true);
$("#krpanoSWFObject")[0].set("plugin[button_rotate].visible",true);
},1e3);
!!$("#pano[data-bgsnd]")[0]&&setTimeout(function(){
$("#krpanoSWFObject")[0].set("plugin[button_sound].visible",true);
$("#krpanoSWFObject")[0].call("playsound(bgsnd,"+$("#pano").attr("data-bgsnd")+",0)");
},1e3);
}});
}
//函数:商品购买(无参数)
function CartsAdd(v){
Locked();
var dom=$("div.shop_goods form");
dom.find("input:eq(1)").val($("div.shop_summary em.now").text());
dom.find("input:eq(2)").val($("div.shop_summary input:eq(0)").val());
dom.find("input:eq(2)").val()==0?(UnLocked(),Alert("对不起,你暂时无法购买该商品")):$.ajax({url:dom.attr("data-ajax"),data:dom.serialize(),type:ajaxPost,success:function(data){
UnLocked();
data.split("|")[0]=="done"?Jump(dom.attr("action")+"?order_id="+data.split("|")[1]):Alert("对不起,你暂时无法购买该商品");
},error:function(){
UnLocked();
Alert("服务器响应超时,请稍后重试");
}});
}
//函数:验证码倒数读秒(DOM)
function Countdown(dom){
GetCookie("mangdang_locked")==null&&SetCookie("mangdang_locked",dom.find("input:text:eq(0)").val());
dom.find("label.l1 span").text("30");
dom.find("label:lt(2)").toggle().find("label.l1 span").text("30");
var i=30,s=setInterval(function(){
i--,dom.find("label.l1 span").text(i);
i<=0&&(DelCookie("mangdang_locked"),dom.find("label:lt(2)").toggle(),clearInterval(s));
},1e3);
}
//函数:轮询订单是否成功(无参数)
function OrderCheck(){
$.ajax({url:$("div.main form:eq(0)").attr("data-ajax"),data:"order_id="+$("div.main form:eq(0) input:hidden:eq(0)").val(),type:ajaxPost,success:function(data){
data.split("|")[0]=="done"?Jump($("div.main form:eq(0)").attr("action")):setTimeout(function(){OrderCheck()},3e3);
}});
}
/* 以上为私有函数 */
//函数:弹出提示层(提示信息,是否UNBind)
function Alert(v,b){
var r=Math.ceil(Math.random()*1e5);
b==undefined&&(b=!0);
$("div.alert")[0]&&$("div.alert").remove();
$("body").append(""+v+"
");
this.rAlert=function(){$("div.alert").css({height:$(document).height(),width:$(window).width()}).find("span").css({marginTop:parseInt($(window).height()/2+$(window).scrollTop())+"px"})};
this.rAlert(),b&&$(window).unbind("resize"),$(window).bind("resize",function(){this.rAlert()});
$("div.r"+r).fadeTo(200,0.9,function(){setTimeout(function(){$("div.r"+r).remove()},1e3)});
}
//函数:锁屏幕(是否UNBind)
function Locked(b){
b==undefined&&(b=!0);
$("div.locked")[0]&&$("div.locked").remove();
$("body").append("");
this.rLocked=function(){$("div.locked").css({height:$(document).height(),width:$(window).width(),backgroundPosition:"center "+parseInt($(window).height()/2+$(window).scrollTop())+"px"})};
this.rLocked(),b&&$(window).unbind("resize"),$(window).bind("resize",function(){this.rLocked()});
$("div.locked").fadeTo(200,0.6);
}
//函数:解锁屏幕(无参数)
function UnLocked(){
$("div.locked").remove();
}
//函数:通用AJAX返回处理(返回信息,错误提示)
function ReAjax(v,e){
v.split("|")[1]!=undefined&&(e=v.split("|")[1]);
var b=!0;
switch (v.split("|")[0]){
case "error":Alert(e==undefined?"Error":e);
break;
case "timeout":Jump(location.href);
break;
default:b=!1;
};
return b;
}
//函数:通用表单提交(DOM,匿名函数)
function Submit(dom,f){
f==undefined&&(f=function(dom){});
Locked();
if (RegForm(dom)){
GetVar("debug")=="blues"&&Debug("[url]:"+dom.attr("action")+"\n[data]:"+dom.serialize());
$.ajax({url:dom.attr("action"),data:dom.serialize(),type:ajaxPost,success:function(data){
GetVar("debug")=="blues"&&Debug("[data]:"+data);
UnLocked();
if (ReAjax(data,"表单提交失败")) return;
if (data=="done"){
f(dom);
Alert("表单提交成功");
};
},error:function(){
UnLocked();
Alert("表单提交超时");
}});
}else{
UnLocked();
Alert("请检查输入");
};
return !1;
}
//函数:错误调试(提示信息)
function Debug(v){
v=v.replace(/").replace("[info]:","[info]:").replace("[url]:","[url]:").replace("[data]:","[data]:");
$("div.debug")[0]||$("body").append("");
$("div.debug").fadeTo(0,0.8).prepend(v+"
").dblclick(function(){$(this).remove()});
}
//函数:判断是否移动设备(无参数)
function isPad(){
var Pad=["iPod","iPhone","Linux armv7l"],thisSys=navigator.platform;
if ($.inArray(thisSys,Pad)!=-1){return !0}else{return !1};
}
//函数:图层显示(DOM,时间)
function Show(dom,t){
$(dom)[0]?$(dom).fadeOut(t).fadeIn(t):$(dom).fadeIn(t);
}
//函数:图层隐藏(DOM,时间)
function Hide(dom,t){
$(dom).fadeOut(t);
}
//函数:检查表单符合正则(DOM)
function RegForm(dom){
var v=!0,i=0;
dom.find("input,select,textarea").each(function(){
$(this).attr("data-reg")!=""&&(new RegExp($(this).attr("data-reg"))).exec($(this).val())==null&&(v=!1,i++,$(this).css({"backgroundColor":"#fcfcfc","borderColor":"#e92b34"}).one("focusin",function(){$(this).css({"backgroundColor":"","borderColor":""})}));
});
v||Alert("有 "+i+" 处错误, 请检查");
return v;
}
//函数:页面跳转(地址)
function Jump(url){
location.href=url;
}
//函数:获取URL参数(变量)
function GetVar(s){
var r=new RegExp("(^|)"+s+"=([^\&]*)(\&|$)","gi").exec(String(location.href)),t;
if (t=r) return t[2];
return "";
}
//函数:设置Cookie(名字,值)
function SetCookie(n,value){
var Days=30;
var exp=new Date();
exp.setTime(exp.getTime()+Days*86400*1000);
document.cookie=n+"="+escape(value)+";expires="+exp.toGMTString();
}
//函数:获取Cookie(名字)
function GetCookie(n){
var arr=document.cookie.match(new RegExp("(^| )"+n+"=([^;]*)(;|$)"));
if(arr!=null) return unescape(arr[2]);
return null;
}
//函数:删除Cookie(名字)
function DelCookie(n){
var exp=new Date();
exp.setTime(exp.getTime()-1);
var cval=GetCookie(n);
if(cval!=null) document.cookie=n+"="+cval+";expires="+exp.toGMTString();
}