function CreepingLine(instanceID, elements){
    this.objInstanceId = instanceID;
    this.elements = elements;
    objectCollector[instanceID] = this;
    
    this.speed = 1;
    
    //Pause slider onMousever (0=no. 1=yes)?
    this.pauseit = 1;
    
    //initialization
    this.currentspeed = this.speed;
    
    this.pausespeed = (this.pauseit == 0) ? this.currentspeed : 0;
    
    if (navigator.appName == "Microsoft Internet Explorer") {
        attachEventHandler(window, "onload", createMethodReference(this, "Prepare"));
        
        attachEventHandler(window, "onload", createMethodReference(this, "CalcResize"));
        attachEventHandler(window, "onresize", createMethodReference(this, "CalcResize"));
    }
    else {
        attachEventHandler(document, "DOMContentLoaded", createMethodReference(this, "Prepare"));
        
        attachEventHandler(document, "DOMContentLoaded", createMethodReference(this, "CalcResize"));
        attachEventHandler(window, "resize", createMethodReference(this, "CalcResize"));
    }
    
    this.clContainer = null;
    this.clLimits = null;
    this.clContent = null;
}

CreepingLine.prototype.Prepare = function CreepingLine_Prepare(){
    this.clContainer = document.getElementById("container" + this.objInstanceId);
    this.clLimits = document.getElementById("limits" + this.objInstanceId);
    this.clContent = document.getElementById("content" + this.objInstanceId);
    attachEventHandler(this.clContent, "onmouseover", createMethodReference(this, "StopScrolling"));
    attachEventHandler(this.clContent, "onmouseout", createMethodReference(this, "StartScrolling"));
    this.width = document.getElementById("tapebar").offsetWidth;
    var fullWidth = this.width;
    this.mainArea = document.createElement("NOBR");
	this.mainArea.style.padding="0";
	this.mainArea.style.margin="0";
    this.clContent.appendChild(this.mainArea);
    var i = 0;
    while (fullWidth > 0 && i < this.elements.length) {
        var span = document.createElement("SPAN");
		span.style.margin = 0;
		span.className = "tapebarElement";
        span.innerHTML = this.elements[i];
        this.mainArea.appendChild(span);
        fullWidth = fullWidth - span.offsetWidth;
        i++;
    }
    this.lastTicker = i - 1;
    setInterval("objectCollector['" + this.objInstanceId + "'].Scroll()", 30);
}
 
CreepingLine.prototype.Scroll = function CreepingLine_Scroll(){
    if (this.mainArea.firstChild==undefined || this.mainArea.firstChild==null)  {
	this.StopScrolling();
	return;
	}
    var left = this.clContent.style.left;
    try {
        left = parseInt(left.replace("px", "").replace("pt", ""));
    } catch (err) {
        left = 0;
    }
    if (Math.abs(left) > this.mainArea.firstChild.offsetWidth) {
        var child = this.mainArea.firstChild;
		var nextChild  = this.mainArea.firstChild.nextSibling;
		if (nextChild == undefined) {
			left = left + child.offsetWidth;
		}
		else {
			left = left + parseInt((child.offsetWidth + nextChild.offsetLeft)/2);
		}
        this.mainArea.removeChild(child);
    }
    var i = this.lastTicker;
    var fullWidth = this.width - (this.mainArea.offsetWidth + left);
    while (fullWidth > 0) {
        i++;
        if (i >= this.elements.length) {
            i = 0;
        }
        var span = document.createElement("SPAN");
		span.style.margin = 0;
		span.className = "tapebarElement";
        span.innerHTML = this.elements[i];
        this.mainArea.appendChild(span);
        fullWidth = fullWidth - span.offsetWidth;
    }
    
    this.lastTicker = i;
    
    if (left > (8 - this.clContent.offsetWidth)) //8 - is the pause
    {
        this.clContent.style.left = (left - this.currentspeed) + "px";
    }
    else {
        this.clContent.style.left = this.clLimits.style.width;
    }
    
}

CreepingLine.prototype.StopScrolling = function CreepingLine_StopScrolling(){
    this.currentspeed = this.pausespeed;
}

CreepingLine.prototype.StartScrolling = function CreepingLine_StartScrolling(){
    this.currentspeed = this.speed;
}

CreepingLine.prototype.GetOuterHTML = function CreepingLine_GetOuterHTML(){

}

CreepingLine.prototype.SetInnerHTML = function CreepingLine_SetInnerHTML(htmlStr){
}

CreepingLine.prototype.CalcResize = function CreepingLine_CalcResize(){
    if (!this.clContainer) 
        this.clContainer = document.getElementById("container" + this.objInstanceId);
    if (!this.clLimits) 
        this.clLimits = document.getElementById("limits" + this.objInstanceId);
    if (!this.clContent) 
        this.clContent = document.getElementById("content" + this.objInstanceId);
    var pos = UiUtils_GetObjPos(this.clContainer)
    this.clLimits.style.left = pos.x + "px";
    this.clLimits.style.top = pos.y + "px";
    this.clLimits.style.width = this.clContainer.clientWidth;
    this.width = document.getElementById("tapebar").offsetWidth;
    this.clLimits.style.height = this.clContainer.clientHeight;
}
