// JavaScript Document
window.onload = new Function("scroll(document.all['thisDiv'], 980, 153, 'right', 'both', 1, 20)")
function scroll(obj, oWidth, oHeight, direction, drag, zoom, speed)
{
	function getScrollPixel(dWidth, cWidth)
	{
		var return_px = cWidth
		while(return_px < dWidth)
			return_px += cWidth
		return return_px += cWidth
	}
	
	var scrollDiv		= obj
	var scrollContent	= document.createElement("span")
	scrollContent.style.position = "absolute"
	scrollDiv.applyElement(scrollContent, "inside")
	var displayWidth	= (oWidth != "auto") ? oWidth : scrollContent.offsetWidth
	var displayHeight	= (oHeight != "auto")? oHeight : scrollContent.offsetHeight
	var contentWidth	= scrollContent.offsetWidth
	var contentHeight	= scrollContent.offsetHeight
	var scrollXItems	= getScrollPixel(displayWidth, contentWidth) / contentWidth
	var scrollYItems	= getScrollPixel(displayHeight, contentHeight) / contentHeight

	scrollDiv.style.width	 = displayWidth
	scrollDiv.style.height	 = displayHeight
	scrollDiv.style.overflow = "hidden"
	scrollDiv.setAttribute("state", "stop")
	scrollDiv.setAttribute("drag", drag)
	scrollDiv.setAttribute("direction", direction)
	scrollDiv.setAttribute("zoom", zoom)
	scrollContent.style.zoom = scrollDiv.zoom
	
	var scroll_script =	"var scrollDiv = " + scrollDiv.uniqueID									+"\n"+
				"var scrollObj = " + scrollContent.uniqueID								+"\n"+
				"var contentWidth = " + contentWidth + " * (scrollObj.style.zoom ? scrollObj.style.zoom : 1)"		+"\n"+
				"var contentHeight = " + contentHeight + " * (scrollObj.style.zoom ? scrollObj.style.zoom : 1)"		+"\n"+
				"var scrollx = scrollObj.style.pixelLeft"								+"\n"+
				"var scrolly = scrollObj.style.pixelTop"								+"\n"+

				"switch (scrollDiv.state.toLowerCase())"								+"\n"+
				"{"													+"\n"+
					"case ('scroll')	:"									+"\n"+
						"switch (scrollDiv.direction)"								+"\n"+
						"{"											+"\n"+
							"case ('left')		:"							+"\n"+
								"scrollx = (--scrollx) % contentWidth"					+"\n"+
								"break"									+"\n"+
							"case ('right')	:"								+"\n"+
								"scrollx = -contentWidth + (++scrollx) % contentWidth"			+"\n"+
								"break"									+"\n"+
							"case ('up')	:"								+"\n"+
								"scrolly = (--scrolly) % contentHeight"					+"\n"+
								"break"									+"\n"+
							//"case ('down')	:"								+"\n"+
							//	"scrolly = -contentHeight + (++scrolly) % contentHeight"		+"\n"+
							//	"break"									+"\n"+
							"case ('left_up')	:"							+"\n"+
								"scrollx = (--scrollx) % contentWidth"					+"\n"+
								"scrolly = (--scrolly) % contentHeight"					+"\n"+
								"break"									+"\n"+
							"case ('left_down')	:"							+"\n"+
								"scrollx = (--scrollx) % contentWidth"					+"\n"+
								"scrolly = -contentHeight + (++scrolly) % contentHeight"		+"\n"+
								"break"									+"\n"+
							"case ('right_up')	:"							+"\n"+
								"scrollx = -contentWidth + (++scrollx) % contentWidth"			+"\n"+
								"scrolly = (--scrolly) % contentHeight"					+"\n"+
								"break"									+"\n"+
							"case ('right_down')	:"							+"\n"+
								"scrollx = -contentWidth + (++scrollx) % contentWidth"			+"\n"+
								"scrolly = -contentHeight + (++scrolly) % contentHeight"		+"\n"+
								"break"									+"\n"+
							"default		:"							+"\n"+
								"return"								+"\n"+
						"}"											+"\n"+
						"scrollObj.style.pixelLeft = scrollx"							+"\n"+
						"scrollObj.style.pixelTop = scrolly"							+"\n"+
						"break"											+"\n"+
	
					"case ('stop')	:"										+"\n"+
					"default	:"										+"\n"+
						"return"										+"\n"+
				"}"	
	var contentNode = document.createElement("span")
	contentNode.style.position = "absolute"
	contentNode.style.width = contentWidth
	scrollContent.applyElement(contentNode, "inside")
	for (var i=0; i <= scrollXItems; i++)
	{
		for (var j=0; j <= scrollYItems ; j++)
		{
			if (i+j == 0)	continue
			var tempNode = contentNode.cloneNode(true)
			var contentLeft, contentTop
			scrollContent.insertBefore(tempNode)
			contentLeft = contentWidth * i
			contentTop = contentHeight * j
			tempNode.style.pixelLeft = contentLeft
			tempNode.style.pixelTop  = contentTop
		}
	}
	scrollDiv.onpropertychange = function()
	{
		var propertyName = window.event.propertyName
		var propertyValue = eval("this." + propertyName)
		
		switch(propertyName)
		{
			case "zoom"		:
				var scrollObj = this.children[0]
				scrollObj.style.zoom = propertyValue
				var content_width  = scrollObj.children[0].offsetWidth  * propertyValue
				var content_height = scrollObj.children[0].offsetHeight * propertyValue
				scrollObj.style.pixelLeft = -content_width  + (scrollObj.style.pixelLeft % content_width)
				scrollObj.style.pixelTop  = -content_height + (scrollObj.style.pixelTop  % content_height)
				break
		}
	}	
	scrollDiv.onmousedown = function()
	{
		if (this.state != "drag")	this.setAttribute("tempState", this.state)
		this.state = "drag"
		this.runtimeStyle.cursor = "default"
		this.setAttribute("start_x", event.clientX)
		this.setAttribute("start_y", event.clientY)
		this.setAttribute("default_left", this.children[0].style.pixelLeft)
		this.setAttribute("default_top", this.children[0].style.pixelTop)
		this.setCapture()
	}
	
	scrollDiv.onmouseup = function()
	{
		this.state = this.tempState ? this.tempState : this.state
		this.runtimeStyle.cursor = ""
		this.removeAttribute("tempState")
		this.removeAttribute("start_x")
		this.removeAttribute("start_y")
		this.removeAttribute("default_left")
		this.removeAttribute("default_top")
		this.releaseCapture()
	}
	
	scrollDiv.state = "scroll"
	setInterval(scroll_script, speed)
}
