﻿$(function(){

	if($("#menustate").length>0)
	{
		$(".sitemenu a").removeClass("current")
		$(".sitemenu a:eq("+$("#menustate").text()+")").addClass("current");
	}

	$(".sitetop a[href^='http']").attr("target","_blank");
	$(".topbanner a:eq(0)").click(function(){window.external.addFavorite('http://www.yhclub.com','余杭宽带俱乐部');return false;})
	$(".topbanner a:eq(1)").click(function(){this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.yhclub.com/');return false;})
})










;(function($){

	jQuery.fn.extend({
			 
 
		replaceClass: function(c1, c2) {
					return this.filter('.' + c1).removeClass(c1).addClass(c2).end();
		},
		
//////////////设置切换盒组件///////////////
//////////////def:"class1" 默认的按钮效果///////////////	
//////////////chg:"class2" 变化后的按钮效果///////////////	
//////////////chglist:"具体的需要变化的列表对象选择" ///////////////
//////////////wennull:"当chglist里的内容为空时是否需要显示该BOX" ///////////////	
//////////////index:"默认显示第几个" ///////////////	
//////////////bindevent:"绑定事件" ///////////////	
///	$(".index_top2 .box3 .list2 div").SwichBox({def:"b2",chg:"b1",chglist:".index_top2 .box3 .list2 ul"})	
		SwichBox:function(settings)
		{  
			settings = $.extend({def:"",chg:"",chglist:"",whennull:false,index:0,bindevent:"mouseover"}, settings);
			var now=$(this);
			now.each(function(index) {
					if(index==settings.index){
						$(this).attr("class",settings.chg);
						$(settings.chglist).eq(index).css("display","block");
						if(settings.whennull){
							if($(settings.chglist).eq(index).html()==""){$(settings.chglist).eq(index).css("display","none")}
						}

					}else{	
					    $(this).attr("class",settings.def);
						$(settings.chglist).eq(index).css("display","none");
					}
					
					$(this).bind(
							settings.bindevent,	
							function(){
								if($(this).attr("class")==settings.chg) return;
								now.attr("class",settings.def);
								$(this).attr("class",settings.chg);
								$(settings.chglist).css("display","none");
								$(settings.chglist).eq(index).fadeIn("fast");
								if(settings.whennull){
									if($(settings.chglist).eq(index).html()==""){$(settings.chglist).eq(index).css("display","none")}
								}
							}
					)
							  
				  
									  
			})	
				
		},
		
	/////设置input鼠标移动上去效果
	/////def:默认的CSS效果;
	/////chg:鼠标移上去的效果
	/////设置何种类形的input
		SetInputStyle:function(settings)
		{
			settings=$.extend({def:"",chg:""}, settings);	
			//if(itype=="") itype=":input[type='text']";
			$(this).addClass(settings.def)
			$(this).hover(
			function(){
				$(this).removeClass().addClass(settings.chg);
			}
			,function(){
				$(this).removeClass().addClass(settings.def);
			});
			
			
		},
		
		
		
		
	////表单验证 checktype="sy_notnull sy_email sy_num{0} or sy_num  sy_phone "	
	///errmsg 自定义验证信息
	/// errtarget 自定义该验证信息要放到哪里他的值可以是 #a .class 的所有JQ选择器
		
		
		
		CheckForm:function(settings){
			function CheckForm_test(reg,str){
				var patt1 = new RegExp(reg);
				var result = patt1.test(str);
				return result;
			}
			function CheckForm_showmsg(obj,msg)
			{
				if(obj.attr("errmsg")!=undefined ) msg= obj.attr("errmsg");
				if(obj.attr("errtarget")!=undefined){
					$(obj.attr("errtarget")).html("").css("display","");
					$(obj.attr("errtarget")).css("color","red").html(msg);
				}else{
					obj.next(".sy_errmsg").remove();
					obj.after("<b class='sy_errmsg'>"+msg+"</b>");
				}
			}
			function CheckForm_removemsg(obj)
			{
				if(obj.attr("errtarget")!=undefined){
					$(obj.attr("errtarget")).css({color:"red",display:"none"}).html("");
				}else{
					obj.next(".sy_errmsg").remove();	
				}
			}
			
			function CheckForm_method_notnull(obj){
				if(obj.val()==""){
						CheckForm_showmsg(obj,"该内容为必填项！")
						return false;
					}else{
						 CheckForm_removemsg(obj);	
						 return true;
					}	
				
			}
			
			function CHeckForm_notkey(obj)
			{
				var b=false;
				if(obj.attr("synotkey")=="true"){
					if(obj.val()=="")		b=true;
				}
				return b;
			}
			
			function CheckForm_method_synum(obj)
			{
				if( CHeckForm_notkey(obj)) return true;
				
					var _n=obj.attr("checktype")
					var t=0;
					var regstr="^[0-9]*$";
					var emsg="该项只能填入数字！";
					if(_n.indexOf(":")!=-1 && _n.indexOf("-")==-1){
						t=parseInt(_n.split(":")[1]);
						if(t!=0){
						regstr="^\\d{"+t+"}$";
						emsg="该项只能填入"+t+"位的数字";
						}
					}
					if(_n.indexOf(":")!=-1 && _n.indexOf("-")!=-1){
						var _s=(_n.split(":")[1]).split("-");
						regstr="^\\d{"+_s[0]+","+_s[1]+"}$";
						emsg="该项只能填入"+_s[0]+"至"+_s[1]+"位的数字";
						
					}
					
					if( !CheckForm_test( regstr,obj.val() ) ){
						CheckForm_showmsg(obj,emsg)
						return false;
					}else{
						CheckForm_removemsg(obj);	
						return true;
						
					}
			}
			function CheckForm_method_symbphone(obj)
			{
				if( CHeckForm_notkey(obj)) return true;
					var _n=obj.attr("checktype");
					var regstr="^0{0,1}(13[4-9]|15[7-9]|15[0-2]|18[7-8])[0-9]{8}$";
					var emsg="您的手机号码不正确！";
					
					if( !CheckForm_test( regstr,obj.val() ) ){
						CheckForm_showmsg(obj,emsg);
						return false;
					}else{
						CheckForm_removemsg(obj);	
						return true;
					}
			}
			
			function CheckForm_method_syemail(obj)
			{
				if( CHeckForm_notkey(obj)) return true;
					var _n=obj.attr("checktype")
					var regstr="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
					var emsg="您的email格式不正确！";
					
					if( !CheckForm_test( regstr,obj.val() ) ){
						CheckForm_showmsg(obj,emsg)
						return false;
					}else{
						CheckForm_removemsg(obj);	
						return true;
					}	
			}
			
			settings=$.extend({bindbutton:"",checklist:"",success:function(){}}, settings);	
			var _t=$(this);
			
			//点击时进行的检查
			_t.css("cursor","pointer").click(function(){
				var _b=true;
				///不能为空
				$("input[checktype='sy_notnull']").each(function(){
					if( !CheckForm_method_notnull($(this)) ) _b=false;	
				})
				
				///只能为数字
				$("input[checktype*='sy_num']").each(function(){
					
					if( ! CheckForm_method_synum($(this)) ) _b=false;
				
				})
				///只能为正确的电话号码
				$("input[checktype*='sy_mbphone']").each(function(){
					if( ! CheckForm_method_symbphone($(this)) ) _b=false;
				
				})
				///只能为正确的email
				$("input[checktype*='sy_email']").each(function(){
					if( ! CheckForm_method_syemail($(this)) ) _b=false;
				
				})
				if(_b)
				{
					 if ($.isFunction(settings.success)) { 
						settings.success();
					}

				}
				
					
			})
			
			$("input[checktype='sy_notnull']").each(function(){
					$(this).blur(function(){
						
						CheckForm_method_notnull($(this));
					})				
			})
			$("input[checktype^='sy_num']").each(function(){
					$(this).blur(function(){
					if( CHeckForm_notkey($(this))) { CheckForm_removemsg($(this));return ;}
					_b=CheckForm_method_synum($(this));
					})
			})
			$("input[checktype^='sy_mbphone']").each(function(){
					$(this).blur(function(){
					if( CHeckForm_notkey($(this))) { CheckForm_removemsg($(this));return ;}
					_b=CheckForm_method_symbphone($(this));
					})
			})
			$("input[checktype^='sy_email']").each(function(){
					$(this).blur(function(){
						if( CHeckForm_notkey($(this))) { CheckForm_removemsg($(this));return ;}
					_b=CheckForm_method_syemail($(this));E
					})
				
			})
			
			
			
			
			
			
			
		},
		
		
	////设置输入框默认信息点击与移除后的信息显示与颜色区别
	
		SetInputDefault:function(settings)
		{
			var _this=$(this)
			settings=$.extend({values:"",def:"",chg:"",bindclick:""},settings);
			
			if(_this.val()=="") _this.val(settings.values);
			if(_this.val()==settings.values) 	_this.css("color","#ccc"); 
			
			_this
			.click(function(){
				if(_this.val()==settings.values)
				{	_this.css("color","#000");	
					_this.val("");
				}					   
			})
			.blur(function(){
				if(_this.val()==""){
					_this.val(settings.values);
					_this.css("color","#ccc");
				}
			})
			
			if(settings.bindclick!=""){
				$(settings.bindclick).css("cursor","pointer").click(function(){
					if(_this.val()=="" || _this.val()==settings.values ){
						_this.val(settings.values);
						_this.css("color","#ccc");
					}
					
				})
			}
			
			
					
		}
	
		
		
	
	
			 
	});

/*调用：
1 无参数调用：默认浮动在右下角
$("#id").floatdiv();

2 内置固定位置浮动
//右下角
$("#id").floatdiv("rightbottom");
//左下角
$("#id").floatdiv("leftbottom");
//右下角
$("#id").floatdiv("rightbottom");
//左上角
$("#id").floatdiv("lefttop");
//右上角
$("#id").floatdiv("righttop");
//居中
$("#id").floatdiv("middle");

另外新添加了四个新的固定位置方法

middletop（居中置顶）、middlebottom（居中置低）、leftmiddle、rightmiddle

3 自定义位置浮动
$("#id").floatdiv({left:"10px",top:"10px"});
以上参数，设置浮动层在left 10个像素,top 10个像素的位置
*/
jQuery.fn.floatdiv=function(location){
		//判断浏览器版本
	var isIE6=false;
	var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0;
	if(Sys.ie && Sys.ie=="6.0"){
		isIE6=true;
	}
	var windowWidth,windowHeight;//窗口的高和宽
	//取得窗口的高和宽
	if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	return this.each(function(){
		var loc;//层的绝对定位位置
		var wrap=$("<div></div>");
		var top=-1;
		if(location==undefined || location.constructor == String){
			switch(location){
				case("rightbottom")://右下角
					loc={right:"0px",bottom:"0px"};
					break;
				case("leftbottom")://左下角
					loc={left:"0px",bottom:"0px"};
					break;	
				case("lefttop")://左上角
					loc={left:"0px",top:"0px"};
					top=0;
					break;
				case("righttop")://右上角
					loc={right:"0px",top:"0px"};
					top=0;
					break;
				case("middletop")://居中置顶
					loc={left:windowWidth/2-$(this).width()/2+"px",top:"0px"};
					top=0;
					break;
				case("middlebottom")://居中置低
					loc={left:windowWidth/2-$(this).width()/2+"px",bottom:"0px"};
					break;
				case("leftmiddle")://左边居中
					loc={left:"0px",top:windowHeight/2-$(this).height()/2+"px"};
					top=windowHeight/2-$(this).height()/2;
					break;
				case("rightmiddle")://右边居中
					loc={right:"0px",top:windowHeight/2-$(this).height()/2+"px"};
					top=windowHeight/2-$(this).height()/2;
					break;
				case("middle")://居中
					var l=0;//居左
					var t=0;//居上
					l=windowWidth/2-$(this).width()/2;
					t=windowHeight/2-$(this).height()/2;
					top=t;
					loc={left:l+"px",top:t+"px"};
					break;
				default://默认为右下角
					location="rightbottom";
					loc={right:"0px",bottom:"0px"};
					break;
			}
		}else{
			loc=location;
			alert(loc.bottom);
			var str=loc.top;
			//09-11-5修改：加上top为空值时的判断
			if (typeof(str)!= 'undefined'){
				str=str.replace("px","");
				top=str;
			}
		}
		/*fied ie6 css hack*/
		if(isIE6){
			if (top>=0)
			{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+"+top+");\"></div>");
			}else{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);\"></div>");
			}
		}
		$("body").append(wrap);
		
		wrap.css(loc).css({position:"fixed",
			z_index:"999"});
		if (isIE6)
		{
			
			wrap.css("position","absolute");
			//没有加这个的话，ie6使用表达式时就会发现跳动现象
			//至于为什么要加这个，还有为什么要加nothing.txt这个，偶也不知道，希望知道的同学可以告诉我
			$("body").css("background-attachment","fixed").css("background-image","url(n1othing.txt)");
		}
		//将要固定的层添加到固定层里
		$(this).appendTo(wrap);
		$(".close").attr("style","text-align:right;display:block;cursor:pointer").click(function(){
		  $(this).parent().css("display","none");
		});
	});
};	

	  
})(jQuery);


/*float div adv*/
function addEvent(obj,evtType,func,cap){
    cap=cap||false;
    if(obj.addEventListener){
        obj.addEventListener(evtType,func,cap);
        return true;
    }else if(obj.attachEvent){
        if(cap){
            obj.setCapture();
            return true;
        }else{
            return obj.attachEvent("on" + evtType,func);
        }
    }else{
        return false;
    }
}
function getPageScroll(){
    var xScroll,yScroll;
    if (self.pageXOffset) {
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollLeft){
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {
        xScroll = document.body.scrollLeft;
    }
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array(xScroll,yScroll);
    return arrayPageScroll;
}
function GetPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }    
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
    if(xScroll < windowWidth){    
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}
//广告脚本文件 AdMove.js
/*
例子
<div id="Div2">
    ***** content ******
</div>
var ad=new AdMove("Div2");
ad.Run();
*/
////////////////////////////////////////////////////////
var AdMoveConfig=new Object();
AdMoveConfig.IsInitialized=false;
AdMoveConfig.ScrollX=0;
AdMoveConfig.ScrollY=0;
AdMoveConfig.MoveWidth=0;
AdMoveConfig.MoveHeight=0;
AdMoveConfig.Resize=function(){
    var winsize=GetPageSize();
    AdMoveConfig.MoveWidth=winsize[2];
    AdMoveConfig.MoveHeight=winsize[3];
    AdMoveConfig.Scroll();
}
AdMoveConfig.Scroll=function(){
    var winscroll=getPageScroll();
    AdMoveConfig.ScrollX=winscroll[0];
    AdMoveConfig.ScrollY=winscroll[1];
}
addEvent(window,"resize",AdMoveConfig.Resize);
addEvent(window,"scroll",AdMoveConfig.Scroll);
function AdMove(id){
    if(!AdMoveConfig.IsInitialized){
        AdMoveConfig.Resize();
        AdMoveConfig.IsInitialized=true;
    }
    var obj=document.getElementById(id);
    obj.style.position="absolute";
    var W=AdMoveConfig.MoveWidth-obj.offsetWidth;
    var H=AdMoveConfig.MoveHeight-obj.offsetHeight;
    var x = W*Math.random(),y = H*Math.random();
    var rad=(Math.random()+1)*Math.PI/6;
    var kx=Math.sin(rad),ky=Math.cos(rad);
    var dirx = (Math.random()<0.5?1:-1), diry = (Math.random()<0.5?1:-1);
    var step = 1;
    var interval;
    this.SetLocation=function(vx,vy){x=vx;y=vy;}
    this.SetDirection=function(vx,vy){dirx=vx;diry=vy;}
    obj.CustomMethod=function(){
        obj.style.left = (x + AdMoveConfig.ScrollX) + "px";
        obj.style.top = (y + AdMoveConfig.ScrollY) + "px";
        rad=(Math.random()+1)*Math.PI/6;
        W=AdMoveConfig.MoveWidth-obj.offsetWidth;
        H=AdMoveConfig.MoveHeight-obj.offsetHeight;
        x = x + step*kx*dirx;
        if (x < 0){dirx = 1;x = 0;kx=Math.sin(rad);ky=Math.cos(rad);} 
        if (x > W){dirx = -1;x = W;kx=Math.sin(rad);ky=Math.cos(rad);}
        y = y + step*ky*diry;
        if (y < 0){diry = 1;y = 0;kx=Math.sin(rad);ky=Math.cos(rad);} 
        if (y > H){diry = -1;y = H;kx=Math.sin(rad);ky=Math.cos(rad);}
    }
    this.Run=function(){
        var delay = 25;//移动速度
        interval=setInterval(obj.CustomMethod,delay);
        obj.onmouseover=function(){clearInterval(interval);}
        obj.onmouseout=function(){interval=setInterval(obj.CustomMethod, delay);}
    }
}

/*-----------------------------------------*/

/*------------drop down ads----------------*/


var nTimeoutId ;
function insertDropDownAD(str)
{
	if(str!=""&&str!="close"){
	$("body").prepend("<div id='openbanner' style='width:100%;overflow:hidden;margin:0 auto;height:1px;'></div>");
	$("#openbanner").html(str);
	$("#openbanner").append("<div ><div style='cursor:pointer;color:#fff;background:#b70005;width:970px;margin:-20px     auto;text-align:right;padding-right:30px;color:yellow' onclick=\"insertDropDownAD('close')\">X关闭</div></div>");
	$("#openbanner").animate({height: (  parseInt($("#openbanner div:eq(0)").attr("height")))+'px'}, 1000);
		nTimeoutId = setTimeout('insertDropDownAD("close")',30000)
	}else if(str="close"){
		$("#openbanner").animate({height: '1px'},1000, function(){$("#openbanner").remove()});
		clearTimeout(nTimeoutId)
	}
}

/*-------------------------------------------*/
