$(document).ready(function(){
	$('#nav li:last').addClass("none");
	var thisClass = $("#nav li.on");
	$('#nav li').hover(function(){
		$(thisClass).removeClass("on");
		$(this).addClass("on");
	},function(){
		$(this).removeClass("on");
		$(thisClass).addClass("on");
	});
	$('#clickLink').hover(function(){
		$(this).find("p").show();
	},function(){
		$(this).find("p").hide();
	});	
	
	$('.sub_fastLink ul li').hover(function(){
		$(this).find("div").animate({ marginLeft:90 , opacity:'show'  }, 400);
	},function(){
		$(this).find("div").animate({ marginLeft:100 , opacity:'hide'  }, 200);
	});
	
	$("#size_12px").click(function(){
		$(".detailedBox .text").css("fontSize","12px"); 
	});
	
	$("#size_14px").click(function(){
		$(".detailedBox .text").css("fontSize","14px"); 
	});
	
	$("#size_16px").click(function(){
		$(".detailedBox .text").css("fontSize","16px"); 
	});
	
	$("#pages").after('<div class="black"></div>');
	$("#formC").click(function(){
		var blackHeight = $('body').height();
		var htmlHeight = $('html').height();
		if(htmlHeight > blackHeight){
			$('.black').height(htmlHeight).show()
		}
		else{
			$('.black').height(blackHeight).show()
		}
		$('.formBox').animate({ top:300,opacity:'show' },500 );
		$(".click,.black").click(function(){
			$(".formBox").animate({top:250,opacity:'hide'},500,function(){
				$(".black").hide();
			});
		});
		return false;
	});
	
	$.tabs('tabPage_0');
	$.tabs('tabPage_1');
	$.tabs('tabPage_2');
	$.tabs('tabPages');
	$.tabs('tabPages_newList_1');
	$.tabs('tabPages_newList_2');
	$.tabs('tabPages_newList_3');
	$.tabs('tabPages_newList_4');
	$.tabs('tabPages_newList_5');
	$.tabs('tabPages_newList_6');
	$.tabs('tabPages_newList_7');
	$.tabs('tabPages_newList_8');
	$.tabs('tabPages_newList_9');
});

$.tabs = function(containerId, start) {
    var ON_CLASS = 'on';
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:eq(' + i + ')').css({display:"block"});
    $(id + '>ul>li:nth-child(' + (i+1) + ')').addClass(ON_CLASS);
    $(id + '>ul>li>a').mousemove(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);
            if (target.size() > 0) {
                $(id + '>div:visible').css({display:"none"});
                target.css({display:"block"});
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS);
            } else {
                alert('无效的选项卡');
            }
        }
        return false;
    });
};

function ppRoll(a)
{
this.myA = a;
this.myA.IsPlay = 1;
this.$(a.demo).style.overflow = "hidden";
this.$(a.demo).style.width = a.width;
this.$(a.demo).style.height = a.height;
this.$(a.demo2).innerHTML=this.$(a.demo1).innerHTML;
this.$(a.demo).scrollTop=this.$(a.demo).scrollHeight;
this.Marquee();
this.$(a.demo).onmouseover=function() {eval(a.objStr+".clearIntervalpp();");}
this.$(a.demo).onmouseout=function() {eval(a.objStr+".setTimeoutpp();")}
}
ppRoll.prototype.$ = function(Id) {return document.getElementById(Id);}
ppRoll.prototype.getV = function(){ 
alert(this.$(this.myA.demo2).offsetWidth-this.$(this.myA.demo).scrollLeft);
alert(this.$(this.myA.demo2).offsetWidth);
alert(this.$(this.myA.demo).scrollLeft);}
ppRoll.prototype.Marquee = function(){
this.MyMar=setTimeout(this.myA.objStr+".Marquee();",this.myA.speed);
if(this.myA.IsPlay == 1)
{if(this.myA.direction == "left"){
if(this.$(this.myA.demo2).offsetWidth-this.$(this.myA.demo).scrollLeft<=0)
this.$(this.myA.demo).scrollLeft-=this.$(this.myA.demo1).offsetWidth;
else{
this.$(this.myA.demo).scrollLeft++;
}}}}
ppRoll.prototype.clearIntervalpp = function(){this.myA.IsPlay = 0;}
ppRoll.prototype.setTimeoutpp = function()
{this.myA.IsPlay = 1;}

function addBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}
function jsScroller (o, w, h) {
	var self = this;
	var list = o.getElementsByTagName("div");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className.indexOf("Scroller-Container") > -1) {
			o = list[i];
		}
	}
	
	//Private methods
	this._setPos = function (x, y) {
		if (x < this.viewableWidth - this.totalWidth) 
			x = this.viewableWidth - this.totalWidth;
		if (x > 0) x = 0;
		if (y < this.viewableHeight - this.totalHeight) 
			y = this.viewableHeight - this.totalHeight;
		if (y > 0) y = 0;
		this._x = x;
		this._y = y;
		with (o.style) {
			left = this._x +"px";
			top  = this._y +"px";
		}
	};
	
	//Public Methods
	this.reset = function () {
		this.content = o;
		this.totalHeight = o.offsetHeight;
		this.totalWidth	 = o.offsetWidth;
		this._x = 0;
		this._y = 0;
		with (o.style) {
			left = "0px";
			top  = "0px";
		}
	};
	this.scrollBy = function (x, y) {
		this._setPos(this._x + x, this._y + y);
	};
	this.scrollTo = function (x, y) {
		this._setPos(-x, -y);
	};
	this.stopScroll = function () {
		if (this.scrollTimer) window.clearInterval(this.scrollTimer);
	};
	this.startScroll = function (x, y) {
		this.stopScroll();
		this.scrollTimer = window.setInterval(
			function(){ self.scrollBy(x, y); }, 40
		);
	};
	this.swapContent = function (c, w, h) {
		o = c;
		var list = o.getElementsByTagName("div");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className.indexOf("Scroller-Container") > -1) {
				o = list[i];
			}
		}
		if (w) this.viewableWidth  = w;
		if (h) this.viewableHeight = h;
		this.reset();
	};
	
	//variables
	this.content = o;
	this.viewableWidth  = w;
	this.viewableHeight = h;
	this.totalWidth	 = o.offsetWidth;
	this.totalHeight = o.offsetHeight;
	this.scrollTimer = null;
	this.reset();
};

function jsScrollbar (o, s, a, ev) {
	var self = this;
	
	this.reset = function () {
		//Arguments that were passed
		this._parent = o;
		this._src    = s;
		this.auto    = a ? a : false;
		this.eventHandler = ev ? ev : function () {};
		//Component Objects
		this._up   = this._findComponent("Scrollbar-Up", this._parent);
		this._down = this._findComponent("Scrollbar-Down", this._parent);
		this._yTrack  = this._findComponent("Scrollbar-Track", this._parent);
		this._yHandle = this._findComponent("Scrollbar-Handle", this._yTrack);
		//Height and position properties
		this._trackTop = findOffsetTop(this._yTrack);
		this._trackHeight  = this._yTrack.offsetHeight;
		this._handleHeight = this._yHandle.offsetHeight;
		this._x = 0;
		this._y = 0;
		//Misc. variables
		this._scrollDist  = 5;
		this._scrollTimer = null;
		this._selectFunc  = null;
		this._grabPoint   = null;
		this._tempTarget  = null;
		this._tempDistX   = 0;
		this._tempDistY   = 0;
		this._disabled    = false;
		this._ratio = (this._src.totalHeight - this._src.viewableHeight)/(this._trackHeight - this._handleHeight);
		
		this._yHandle.ondragstart  = function () {return false;};
		this._yHandle.onmousedown = function () {return false;};
		this._addEvent(this._src.content, "mousewheel", this._scrollbarWheel);
		this._removeEvent(this._parent, "mousedown", this._scrollbarClick);
		this._addEvent(this._parent, "mousedown", this._scrollbarClick);
		
		this._src.reset();
		with (this._yHandle.style) {
			top  = "0px";
			left = "0px";
		}
		this._moveContent();
		
		if (this._src.totalHeight < this._src.viewableHeight) {
			this._disabled = true;
			this._yHandle.style.visibility = "hidden";
			if (this.auto) this._parent.style.visibility = "hidden";
		} else {
			this._disabled = false;
			this._yHandle.style.visibility = "visible";
			this._parent.style.visibility  = "visible";
		}
	};
	this._addEvent = function (o, t, f) {
		if (o.addEventListener) o.addEventListener(t, f, false);
		else if (o.attachEvent) o.attachEvent('on'+ t, f);
		else o['on'+ t] = f;
	};
	this._removeEvent = function (o, t, f) {
		if (o.removeEventListener) o.removeEventListener(t, f, false);
		else if (o.detachEvent) o.detachEvent('on'+ t, f);
		else o['on'+ t] = null;
	};
	this._findComponent = function (c, o) {
		var kids = o.childNodes;
		for (var i = 0; i < kids.length; i++) {
			if (kids[i].className && kids[i].className == c) {
				return kids[i];
			}
		}
	};
	//Thank you, Quirksmode
	function findOffsetTop (o) {
		var t = 0;
		if (o.offsetParent) {
			while (o.offsetParent) {
				t += o.offsetTop;
				o  = o.offsetParent;
			}
		}
		return t;
	};
	this._scrollbarClick = function (e) {
		if (self._disabled) return false;
		
		e = e ? e : event;
		if (!e.target) e.target = e.srcElement;
		
		if (e.target.className.indexOf("Scrollbar-Up") > -1) self._scrollUp(e);
		else if (e.target.className.indexOf("Scrollbar-Down") > -1) self._scrollDown(e);
		else if (e.target.className.indexOf("Scrollbar-Track") > -1) self._scrollTrack(e);
		else if (e.target.className.indexOf("Scrollbar-Handle") > -1) self._scrollHandle(e);
		
		self._tempTarget = e.target;
		self._selectFunc = document.onselectstart;
		document.onselectstart = function () {return false;};
		
		self.eventHandler(e.target, "mousedown");
		self._addEvent(document, "mouseup", self._stopScroll, false);
		
		return false;
	};
	this._scrollbarDrag = function (e) {
		e = e ? e : event;
		var t = parseInt(self._yHandle.style.top);
		var v = e.clientY + document.body.scrollTop - self._trackTop;
		with (self._yHandle.style) {
			if (v >= self._trackHeight - self._handleHeight + self._grabPoint)
				top = self._trackHeight - self._handleHeight +"px";
			else if (v <= self._grabPoint) top = "0px";
			else top = v - self._grabPoint +"px";
			self._y = parseInt(top);
		}
		
		self._moveContent();
	};
	this._scrollbarWheel = function (e) {
		e = e ? e : event;
		var dir = 0;
		if (e.wheelDelta >= 120) dir = -1;
		if (e.wheelDelta <= -120) dir = 1;
		
		self.scrollBy(0, dir * 20);
		e.returnValue = false;
	};
	this._startScroll = function (x, y) {
		this._tempDistX = x;
		this._tempDistY = y;
		this._scrollTimer = window.setInterval(function () {
			self.scrollBy(self._tempDistX, self._tempDistY); 
		}, 40);
	};
	this._stopScroll = function () {
		self._removeEvent(document, "mousemove", self._scrollbarDrag, false);
		self._removeEvent(document, "mouseup", self._stopScroll, false);
		
		if (self._selectFunc) document.onselectstart = self._selectFunc;
		else document.onselectstart = function () { return true; };
		
		if (self._scrollTimer) window.clearInterval(self._scrollTimer);
		self.eventHandler (self._tempTarget, "mouseup");
	};
	this._scrollUp = function (e) {this._startScroll(0, -this._scrollDist);};
	this._scrollDown = function (e) {this._startScroll(0, this._scrollDist);};
	this._scrollTrack = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._scroll(0, curY - this._trackTop - this._handleHeight/2);
	};
	this._scrollHandle = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._grabPoint = curY - findOffsetTop(this._yHandle);
		this._addEvent(document, "mousemove", this._scrollbarDrag, false);
	};
	this._scroll = function (x, y) {
		if (y > this._trackHeight - this._handleHeight) 
			y = this._trackHeight - this._handleHeight;
		if (y < 0) y = 0;
		
		this._yHandle.style.top = y +"px";
		this._y = y;
		
		this._moveContent();
	};
	this._moveContent = function () {
		this._src.scrollTo(0, Math.round(this._y * this._ratio));
	};
	
	this.scrollBy = function (x, y) {
		this._scroll(0, (-this._src._y + y)/this._ratio);
	};
	this.scrollTo = function (x, y) {
		this._scroll(0, y/this._ratio);
	};
	this.swapContent = function (o, w, h) {
		this._removeEvent(this._src.content, "mousewheel", this._scrollbarWheel, false);
		this._src.swapContent(o, w, h);
		this.reset();
	};
	
	this.reset();
};

function couplet(){
	if(arguments.length>=1)	this.objID = document.getElementById(arguments[0]);
	if(arguments.length>=2)	this.divTop = arguments[1];
	if(arguments.length>=3) this.divPlane = arguments[2];
	if(arguments.length>=4)	this.scrollDelay = arguments[4];
	if(arguments.length>=5) this.waitTime = arguments[5];

	if(!this.objID){
		this.objID = null; return;
	}else{
		this.objID.style.position="absolute";
		this.objID.style.display="block";
		this.objID.style.zIndex=9999;
	}

	if("" == this.objID.style.top){
		if(isNaN(this.divTop)){
			alert("对象垂直位置(top)参数必须为数字。"); return;
		}else{
			this.objID.style.top = this.divTop+"px";
		}
	}

	if("" == this.objID.style.left && "" == this.objID.style.right){
		if(isNaN(this.divPlane)){
			alert("对象水平位置(left||right)参数必须为数字。"); return;
		}

		if(this.divPlane>0) this.objID.style.left = this.divPlane+"px";
		if(this.divPlane<0) this.objID.style.right = Math.abs(this.divPlane)+"px";
	}

	if(this.scrollDelay<15 || isNaN(this.scrollDelay)) this.scrollDelay = 15;
	if(this.waitTime<500 || isNaN(this.waitTime)) this.waitTime = 500;
	if(arguments.length>=1) this.start();
}

couplet.prototype.start = function(){
	if(null == this.objID) return;

	var objCouplet = this;

	timer = this.scrollDelay;
	objCouplet.lastScrollY = 0;
	objCouplet.timerID = null;

	objCouplet.startID = function(){
		if("block" == objCouplet.objID.style.display){
			objCouplet.run();
		}else{
			clearInterval(objCouplet.timerID);
		}
	}

	objCouplet.Begin = function(){
		objCouplet.timerID = setInterval(objCouplet.startID,timer);
	}
	
	setTimeout(objCouplet.Begin,this.waitTime);
}

couplet.prototype.run = function(){
	if(document.documentElement && document.documentElement.scrollTop){
		uu_scrY = parseFloat(document.documentElement.scrollTop);
	}else if(document.body){
		uu_scrY = parseFloat(document.body.scrollTop);
	}

	uu_divX = parseFloat(this.objID.style.top.replace("px",""));

	uu_curTop = .1 * (uu_scrY - this.lastScrollY);
	uu_curTop = uu_curTop>0?Math.ceil(uu_curTop):Math.floor(uu_curTop);

	this.objID.style.top = parseFloat(uu_divX + uu_curTop) + "px";
	this.lastScrollY += uu_curTop; 
}