﻿//Edit By JasonHuang 2007/04/03  2008/07/23依協理要求減少程式碼
function getAttr(srcObj,attributeName){
	if(srcObj==null || attributeName==null){
		return null;
	}
	
	if(srcObj.getAttribute == null){
		return null;
	}
	
	attributeName = srcObj.getAttribute(attributeName);
	if(attributeName==""){
		attributeName=null
	}
	
	return attributeName;
}

function RunForWN(mainObj,secs){ 

		mainObj.Hover = false;
		mainObj.onmouseover = function(){
			this.Hover = true;
		}
		mainObj.onmouseout = function(){
			this.Hover = false;
		}
		
		mainObj.style.display = "block";
		mainObj.divs = new Array();
		var divs = mainObj.getElementsByTagName("div")
		
		var scrolldelay = getAttr(mainObj,"delay") || 2.5;
		if(isNaN(scrolldelay )){
			mainObj.style.display="none";
			return;
		}
		
		scrolldelay = Math.max(parseFloat(scrolldelay) * 100 ,secs); //在此設定轉動的速度
		for(i=0;i<divs.length;i++){
			mainObj.divs[i] = divs[i];
			divs[i].style.backgroundColor="";
			divs[i].m = setTimeout("void(0)",0);
			divs[i].n = i;
			divs[i].o = 10;
			divs[i].style.top = mainObj.offsetHeight*2 + "px";
		
			if(divs[i].id==null || divs[i].id == ""){
				divs[i].id = "_marquee_" + i;
			}
		
			divs[i].flyin = function(){
				clearTimeout(this.m);
				this.style.visibility = "visible";
				var b = this.n-1;
				
				if(b<0){b = mainObj.divs.length-1;
			    }
			    
			    if(this.o >0 ){
				    if(this.parentNode.Hover == false){
					    this.o +=-2;this.style.top = ((this.parentNode.offsetHeight * this.o/10))+ "px";
				    }
				    this.m = setTimeout("document.getElementById('"+this.id+"').flyin()",100);
			    }else{
				    this.o = 0;
				    var n = this.n+1;
				    if(n > (mainObj.divs.length-1)){
					    n =0;
				    }
				    n = document.getElementById("_marquee_" + n);
				    if(n.id !=this.id){
					    this.m = setTimeout("document.getElementById('"+this.id+"').flyout()",(scrolldelay));
					    n.m = setTimeout("document.getElementById('"+n.id+"').style.top='900px';document.getElementById('"+n.id+"').flyin()",(scrolldelay-0));
				    }
			    }
		    }
		
		    divs[i].flyout = function(){
			    clearTimeout(this.m);
			    if(this.o < 10 ){
				    if(this.parentNode.Hover == false){
					    this.o+=2;
					    this.style.top = ( -(this.o/10 * this.offsetHeight) -2) + "px";
				    }
				    this.m = setTimeout("document.getElementById('"+this.id+"').flyout()",100);
			    }else{
				    this.o = 10;this.style.top = this.parentNode.offsetHeight*2 + "px";
			    }
		    }
	    }
	    
	    if(divs.length >0){
		    divs[0].style.top = "1px";
		    divs[0].flyin();
	    }
}

function runMarquee(divname,secs){
	createCSS(divname);
	var mainObj = document.getElementById(divname)
	if(secs == 0 || secs == '' || isNaN(secs) == true){
		secs = 2000;
	}else{
		secs = secs*1000
	}
	RunForWN(mainObj,secs);
}

function createCSS(divname){
	document.write('<STYLE>')
	document.write('	#'+divname+' {')
	document.write('		DISPLAY: none; FONT-SIZE: 13px; MARGIN: 0px; OVERFLOW: hidden; POSITION: relative; HEIGHT: 25px')
	document.write('	}')
	document.write('	#'+divname+' DIV {')
	document.write('		PADDING-RIGHT: 0px; PADDING-LEFT: 5px; LEFT: 0px; VISIBILITY: hidden; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; POSITION: absolute; TOP: 0px')
	document.write('	}')
	document.write('	#'+divname+' MARQUEE {')
	document.write('		DISPLAY: block; HEIGHT: 18px')
	document.write('	}')
	document.write('	#'+divname+' FONT {')
	document.write('		WHITE-SPACE: nowrap! important')
	document.write('	}')
	document.write('	</STYLE> ')
}