/* 方向 */
function Direction(){
	this.Left = "Left";
	this.Top = "Top";
	this.Right = "Right";
	this.Bottom = "Bottom";
}

/* 滚动广告 */
function ScrollAD(asParent, asChild){
	var currentobject = this;
	
	this.sDirection = "Left";
	this.iSpeed = 30;
	
	var objParent = document.getElementById(asParent);
	var objChild = document.getElementById(asChild);
	var objTr = objChild.parentNode;
	var objTable = objTr.parentNode;
	var objDirection = new Direction();
	var objClone = new Array();
	var iCloneIndex = 0;
	var objMarquee;
	
	this.Initialize = function(){
		var objNewTr;
		
		switch(this.sDirection){
			case objDirection.Left:
				if(objTable.offsetWidth < objParent.offsetWidth * 2){
					while(objTable.offsetWidth < objParent.offsetWidth * 2){
						objClone[iCloneIndex] = objTr.insertCell(-1);
						objClone[iCloneIndex].innerHTML = objChild.innerHTML;
						iCloneIndex ++;
					}
				}else{
						objClone[0] = objTr.insertCell(-1);
						objClone[0].innerHTML = objChild.innerHTML;
				}
				objParent.scrollLeft = objChild.offsetLeft;
				break;
			case objDirection.Top:
				while(objTable.offsetHeight < objParent.offsetHeight * 2){
					objNewTr = objTable.insertRow(-1);
					objClone[iCloneIndex] = objNewTr.insertCell(-1);
					objClone[iCloneIndex].innerHTML = objChild.innerHTML;
					iCloneIndex ++;
				}
				objParent.scrollTop = objChild.offsetTop;
				break;
			case objDirection.Right:
				while(objTable.offsetWidth < objParent.offsetWidth * 2){
					objClone[iCloneIndex] = objTr.insertCell(0);
					objClone[iCloneIndex].innerHTML = objChild.innerHTML;
					iCloneIndex ++;
				}
				objParent.scrollLeft = objTable.offsetWidth - objParent.offsetWidth;
				break;
			case objDirection.Bottom:
				while(objTable.offsetHeight < objParent.offsetHeight * 2){
					objNewTr = objTable.insertRow(0);
					objClone[iCloneIndex] = objNewTr.insertCell(-1);
					objClone[iCloneIndex].innerHTML = objChild.innerHTML;
					iCloneIndex ++;
				}
				objParent.scrollTop = objTable.offsetHeight - objParent.offsetHeight;
				break;
		}
		
		objParent.onmouseout();
	}
	
	function Marquee(){
		switch(currentobject.sDirection){
			case objDirection.Left:
				if(objClone[0].offsetLeft - objParent.scrollLeft <= 0){
					objParent.scrollLeft = 0;
				}else{
					objParent.scrollLeft ++;
				}
				break;
			case objDirection.Top:
				if(objClone[0].offsetTop - objParent.scrollTop <= 0){
					objParent.scrollTop = 0;
				}else{
					objParent.scrollTop ++;
				}
				break;
			case objDirection.Right:
				if(objParent.scrollLeft + objParent.offsetWidth <= objChild.offsetLeft){
					objParent.scrollLeft = objTable.offsetWidth - objParent.offsetWidth;
				}else{
					objParent.scrollLeft --;
				}
				break;
			case objDirection.Bottom:
				if(objParent.scrollTop + objParent.offsetHeight <= objChild.offsetTop){
					objParent.scrollTop = objTable.offsetHeight - objParent.offsetHeight;
				}else{
					objParent.scrollTop --;
				}
				break;
		}
	}
	
	
	objParent.onmouseover = function(){
		clearInterval(objMarquee);
	}
	
	objParent.onmouseout = function(){
		objMarquee = setInterval(Marquee, currentobject.iSpeed);
	}
}