// JavaScript Document
function clsHexBanner() {
	var objContainer = ""
	var objToScroll = ""
	var strContainerID = ""
	var strToScrollID = ""
	var intWidth = 0
	var intHeight = 0
	var intScrollSpeed = 0
	var intScrollInterval = 50
	var intPixelPerSec = 50
	var blnScroll = true;
	var objDoScroll = ""
	var intScrollDir = 1  // 1: right to left, 2: left to right, 3: bottom to top, 4: top to bottom
	var strContentsUrl = ""
	var intContentType = 1
	var blnPause = true
	var blnInit = false
	var blnSetSize = false;
	
	this.setDirection = function(intValue) {intScrollDir = intValue;};
	this.setSpeed = function(intValue) {intPixelPerSec = intValue;};
	this.setWidth = function(intValue) {intWidth = intValue;}
	this.setHeight = function(intValue) {intHeight = intValue;}
	this.pauseOnMouseOver = function(blnValue) {blnPause = blnValue;}
	
	this.setContents = function(strValue,intType) {
		strContentsUrl = strValue;
		intContentType = intType;
	};
	 
	
	function getXmlData(strfile,objOnloadFunction){
		var xmlObj = null;
		if(window.XMLHttpRequest){
			xmlObj = new XMLHttpRequest();
		} else if(window.ActiveXObject){
			xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			return;
		}
		xmlObj.onreadystatechange = function(){		
			if(xmlObj.readyState == 4){				
				objOnloadFunction(xmlObj)
			}
		}
		xmlObj.open ('GET', strfile, true);
		xmlObj.send ('');
	}
	
	this.create = function create(strTargetID){
		if (strContainerID == "") {
			var intUnID = Math.floor(Math.random()*100000);
			strContainerID = "hexScroll" + intUnID;
			objContainer = document.getElementById(strContainerID);
			while (objContainer != null) {
				var intUnID = Math.floor(Math.random()*100000);
				strContainerID = "hexScroll" + intUnID;
				objContainer = document.getElementById(strContainerID);
			}
			strToScrollID = "hexScrollContents" + intUnID;		
			
			objContainer = document.createElement("Div");
			objContainer.id = strContainerID;
			objContainer.style.overflow = "hidden";
			objContainer.style.position = "relative";
			objContainer.style.width = (intWidth == 0) ? "100%" : intWidth + "px";
			objContainer.style.height = (intHeight == 0) ? "100%" : intHeight + "px";
			
			
			objToScroll = document.createElement("span");
			objToScroll.id = strToScrollID;
			objToScroll.style.position ="absolute";
			objToScroll.style.overflow = "visible"
			objToScroll.style.left = 0;
			objToScroll.style.top = 0;
			objToScroll.style.width = "1000"  + "px"
			objToScroll.style.height = "100%"
			
			objContainer.appendChild(objToScroll)
			
			
			
		}
		
		var objTaget = (strTargetID != "") ? document.getElementById(strTargetID) : null;
		
		
		if (objTaget != null) {			
			objTaget.appendChild(objContainer)
			objContainer.style.Height = objTaget.clientHeight
			objTaget.innerHTML += ""
		}else{
			/*var objTemp = document.createElement("Div");
			objTemp.appendChild(objContainer)
			document.write(objTemp.innerHTML)*/
		}
		if (intContentType == 1) {
			getXmlData(strContentsUrl,writeContents)
		}else if (intContentType == 2) {		
			var objContents = document.getElementById(strContentsUrl)	
			objContents.style.display = "block"
			objContents.style.whiteSpace = "nowrap"
			objContents.style.overflow = "visible"
			
			if (objContents.scrollWidth > 1000) {
				objToScroll.style.width = objContents.scrollWidth + "px"
			}
			
			objToScroll.appendChild(objContents)
			//init_scroll()
		}else {	
			objToScroll.innerHTML = strContentsUrl
			objToScroll.style.overflow = "visible"
			//objToScroll.style.width = "auto"
			
		}
		
		if (objTaget == null) {	
			var objTemp = document.createElement("div")
			objTemp.appendChild(objContainer)
			document.write(objTemp.innerHTML)		
		}

		
			
		
		if (intContentType != 1){
			init_scroll()
		}
		
	}
	
	function writeContents(xmlObj){	
		document.getElementById(strToScrollID).innerHTML = xmlObj.responseText;		
		init_scroll()
	}
	
	function init_scroll(){
		
		objContainer = document.getElementById(strContainerID)
		objToScroll = document.getElementById(strToScrollID)
		intWidth = (intWidth == 0) ? objContainer.clientWidth : intWidth;
		intHeight = (intHeight == 0) ? objContainer.clientHeight : intHeight;
		setSpeed(intPixelPerSec)
		
		switch (intScrollDir) {
			case 1:
				objToScroll.style.left = intWidth + "px";
			break
			case 2:
				objToScroll.style.left = (0-objToScroll.scrollWidth) + "px";
			break
			case 3:
				objToScroll.style.top = intHeight + "px";
			break
			case 4:
				objToScroll.style.top = (0-objToScroll.scrollHeight) + "px";
			break
		}
		
		objDoScroll = setInterval(scrollContents,intScrollInterval) 
		if (blnPause) {
			objContainer.onmouseover = function() {
				blnScroll = false;
			}
			objContainer.onmouseout = function() {
				blnScroll = true;
			}
		}
	}
	
	function scrollContents() {
		if (blnScroll) {
			if (!blnSetSize && intContentType != 1) {
				objToScroll.style.width = document.getElementById(strContentsUrl).scrollWidth + "px"
				objToScroll.style.height = document.getElementById(strContentsUrl).scrollHeight + "px"
				blnSetSize = true;
			}
			var intOldPos = 0
			var intNewPos = 0
			switch (intScrollDir) {
				case 1:
					intOldPos = objToScroll.style.left
					intNewPos = parseInt(intOldPos)-intScrollSpeed;
					if (intNewPos+objToScroll.scrollWidth < 0){intNewPos=intWidth} 
					objToScroll.style.left = intNewPos + "px";
				break
				case 2:
					intOldPos = objToScroll.style.left
					intNewPos = parseInt(intOldPos)+intScrollSpeed;
					if (intNewPos > intWidth){intNewPos=-objToScroll.scrollWidth} 
					objToScroll.style.left = intNewPos + "px";
				break
				case 3:
					intOldPos = objToScroll.style.top
					intNewPos = parseInt(intOldPos)-intScrollSpeed;
					if (intNewPos+objToScroll.scrollHeight <= 0){intNewPos=intHeight}
					objToScroll.style.top = intNewPos + "px";
				break
				case 4:
					intOldPos = objToScroll.style.top
					intNewPos = parseInt(intOldPos)+intScrollSpeed;
					if (intNewPos > intHeight){intNewPos=-objToScroll.scrollHeight}
					objToScroll.style.top = intNewPos + "px";
				break
			}
		}
	}

	
	function setSpeed(intSpeed){
		if (intSpeed>0){
			intSpeed = intSpeed*2
			intScrollInterval = 50
			intScrollSpeed = intSpeed/(1000/intScrollInterval);
			
			var intI = (intScrollSpeed < 1) ? 1 : Math.floor(intScrollSpeed)
			var intR = intScrollSpeed - intI
			
			if (intScrollSpeed < 1) {
				intScrollInterval = (1/intScrollSpeed) * intScrollInterval
				intScrollSpeed = 1
			}else{
				if (intR > 0) { 
					intScrollInterval = (intI/intScrollSpeed) * intScrollInterval
					intScrollSpeed = intI
				}			
			}
			if (objDoScroll != "") {
				window.clearInterval(objDoScroll)
				objDoScroll = setInterval(scrollContents,intScrollInterval) 
			}
		}else{
			intScrollSpeed = 0
		}	
	}
}