﻿// JScript File


SCROLL_ACCEL = 10; //滑动的加速度 1-100有效
SCROLL_TIME = 300; //滑动时间(毫秒)

//判断浏览器
o_navigator = navigator.userAgent;
var isIE = (o_navigator.indexOf("MSIE") > -1) ? 1 : 0;
var isIE5 = (o_navigator.indexOf("MSIE 5") > -1) ? 1 : 0;
var isMac = (o_navigator.indexOf("Mac") > -1) ? 1 : 0;
var isOpera = (o_navigator.indexOf("Opera") > -1) ? 1 : 0;
var isIE50 = (o_navigator.indexOf("MSIE 5.0") > -1) ? 1 : 0;
var isIE55 = (o_navigator.indexOf("MSIE 5.5") > -1) ? 1 : 0;
var isIE6 = (o_navigator.indexOf("MSIE 6.0") > -1) ? 1 : 0;
var isNN6 = (o_navigator.indexOf("Netscape6") > -1) ? 1 : 0;
var isFirefox = (o_navigator.indexOf("Firefox") > -1) ? 1 : 0;
var isDOM = (document.getElementById) ? 1 : 0;
//isIE = (isIE && !isOpera);

var objDiv;
var Scroller = function(){
/*	var startTime,startHeight,endHeight,dist,accel;
	var aniTimer;*/
	aDiv	:	null;
}

Scroller.show = function(){
	with(this.aDiv){
		
		this.startTime = (new Date()).getTime();
		this.startHeight = 0;
		this.endHeight = scrollHeight;
		
		this.dist = this.endHeight;
		this.accel = this.dist / SCROLL_TIME / SCROLL_TIME;
		if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer);
		this.aniTimer = window.setInterval("Scroller.slide()", parseInt(100/SCROLL_ACCEL));
	}
}

Scroller.hide = function(){
	with(this.aDiv){
		this.startTime = (new Date()).getTime();
		this.startHeight = scrollHeight;
		this.endHeight = 0;
		this.dist = -this.startHeight;
		this.accel = this.dist / SCROLL_TIME / SCROLL_TIME;
		if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer);
		this.aniTimer = window.setInterval("Scroller.slide()", parseInt(100/SCROLL_ACCEL));
	}
}

Scroller.slide = function(){
	with(this){
		var now = (new Date()).getTime();
		var elapsed = now - startTime;
		if (elapsed > SCROLL_TIME) endScroll();
		else {
			var t = SCROLL_TIME - elapsed;
			var ny = endHeight - t * t * accel;
			jumpTo(ny);
		}
	}
}

Scroller.jumpTo = function(ny){
	var alpha = Math.abs(parseInt(ny*100/this.dist));
	
	with(this.aDiv){
		style.height = ny+'px';
		scrollTop = ny;
		if(isIE){
		    filters.alpha.opacity = alpha;}
		else{
		    style.opacity = alpha;
		}
	}
}

Scroller.endScroll = function() {
	if (this.aniTimer) this.aniTimer = window.clearTimeout(this.aniTimer);
	with(this.aDiv){
		style.overflowY="";
		style.height = "";
		if(this.endHeight==0){
			style.display = "none";
			//filters.alpha.opacity = 0;
		}
		//else{
		if(isIE){
		    filters.alpha.opacity = 100;}
		else{
		    style.opacity = 100;
		}
		//}
	}
}

function TransNodeImg(imgObj){
    var objIcon;
    objIcon = imgObj;
	switch (objIcon.className)
	{
	    case "down":
	    objIcon.className = "up";
	    break;
	    case "up":
	    objIcon.className = "down";
	    break;
	}
	//alert(oldSrc);
}

function NodeExpand(obj){
    if(obj.getElementsByTagName("b")!=null && obj.getElementsByTagName("b").length>0)
        TransNodeImg(obj.getElementsByTagName("b")[0]);
	objDiv = getNextSibling(obj);
	if(objDiv){
		if(objDiv.style.display =='block'){
			if(isIE || isFirefox){
				objDiv.style.overflowY="hidden";
				Scroller.aDiv = objDiv;
				Scroller.hide();
			}
			else{
				objDiv.style.display = "none";
			}
		}
		else{
			if(isIE || isFirefox){
				objDiv.style.display = 'block';
				if(isIE){
		            objDiv.filters.alpha.opacity = 100;}
		        else{
		            objDiv.style.opacity = 100;
		        }
				objDiv.style.overflowY="hidden";
				objDiv.style.height=0;
				Scroller.aDiv = objDiv;
				Scroller.show();
			}
			else{
			
				objDiv.style.display = "block";
			}
		}
	}
}

function Expand(objDiv){
	if(objDiv!=null){
		if(objDiv.style.display =='block'){
			if(isIE || isFirefox){
				objDiv.style.overflowY="hidden";
				Scroller.aDiv = objDiv;
				Scroller.hide();
			}
			else{
				objDiv.style.display = "none";
			}
		}
		else{
			if(isIE || isFirefox){
				objDiv.style.display = 'block';
				if(isIE){
		            objDiv.filters.alpha.opacity = 100;}
		        else{
		            objDiv.style.opacity = 100;
		        }
				objDiv.style.overflowY="hidden";
				objDiv.style.height=0;
				Scroller.aDiv = objDiv;
				Scroller.show();
			}
			else{
			
				objDiv.style.display = "block";
			}
		}
	}
}

function getNextSibling(startBrother){
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}


