/**
 * Javascript collection to support the BONNTICKET frontend
 *
 * @author Markus Klein
 * @version $Id$
 * @package bonnticket
 * @subpackage engine
 */


/* Scroller call */
var scrObj;

function start_news_scroller(dom_id)
{
    var domElem;
    if(domElem = document.getElementById(dom_id)) {
        var content = domElem.innerHTML;
        var w = domElem.style.width;
        var h = domElem.style.height;
        scrObj = new scrollerObj('scrObj', h, w, h, w, content,'','','1','left', dom_id);
    }
}


/**
 * Scroller functions
 *
 * @author unknown
 */

function scrollerObj(name, initH, initW, heightB, widthB ,content, initBg, Bg, speed, initFl, dom_id)
{
    //**data**//
    this.name    = name;
    this.initH   = initH;
    this.initW   = initW;
    this.heightB = heightB;
    this.widthB  = widthB;
    this.content = content;
    this.initBg  = initBg;
    this.Bg      = Bg;
    this.iniFl   = initFl;
    this.speed   = parseInt(speed);
    this.timer   = name + "Timer";
    this.dom_id  = dom_id;
    this.elem;

    //**methods**//
    this.getElement  = getElement;
    this.createLayer = createLayer;
    this.scrollLayer = scrollLayer;
    this.scrollLoop  = scrollLoop;

    //**initiate methods**//
    this.createLayer();
    this.getElement();
    this.scrollLayer();
}

function scrollPause()
{
    scrObj.scrollLoop(0);
}

function scrollResume()
{
    scrObj.scrollLoop(1);
}


//**call this method to stop scrolling**//
function scrollLoop(s)
{
    this.speed = s;
}

//**pretty obvious**//
function scrollLayer()
{
    clearInterval(this.timer);

    this.elem = document.getElementById(this.dom_id+'_scroller');
    var y = parseInt(this.elem.style.top);
    var maxTop = (0 - (parseInt(this.heightB)));

    if(y > maxTop) {
        this.elem.style.top = (y - this.speed) + 'px';


        //alert(parseInt(this.elem.style.top)+"\n"+this.elem.id);
    } else {
        this.elem.style.top = this.initH;
    }
    this.timer = setInterval(this.name+'.scrollLayer()','50');
}

//**get the specific dom-expression**//
function getElement(){
    if(document.getElementById) {
        this.elem = document.getElementById(this.name);
    } else if (document.all) {
        this.elem = document.all[name];
    }
}

//**pretty obvious - if NS4 - please upgrade to a standard compliant browser**//
function createLayer(){

    var container_div;

    if(container_div = document.getElementById(this.dom_id)) {

        container_div.style.position = "relative";
        container_div.style.overflow = "hidden";
        container_div.style.width    = this.initW;
        container_div.style.height   = this.initH;
        container_div.style.backgroundColor = this.initBg;;
        container_div.innerHTML      = '';
        
        if(document.attachEvent) {
            container_div.attachEvent ("onmouseover", scrollPause);
            container_div.attachEvent ("onmouseout", scrollResume);
        } else {
            container_div.addEventListener ("mouseover", scrollPause, false);
            container_div.addEventListener ("mouseout", scrollResume, false);
        }
            
        this.elem = document.createElement("div");
        this.elem.id             = this.dom_id+'_scroller';
        this.elem.style.position = "absolute";
        this.elem.style.overflow = "visible";
        this.elem.style.width    = this.widthB;
        //this.elem.style.height   = this.heightB;
        this.elem.style.backgroundColor = this.Bg;
        this.elem.style.top      = this.initH;
        this.elem.style.left     = "0";
        this.elem.style.padding  = "0";
        this.elem.style.margin   = "0";

        this.elem.innerHTML = this.content;
        container_div.appendChild(this.elem);
        container_div.style.visibility = 'visible';
        this.heightB = this.elem.offsetHeight;
        this.elem.style.height = this.heightB;
    }


/*
    var scrollStr = new String;
    if(document.getElementById || document.all){
        scrollStr = scrollStr + '<div id="layer'+this.name+'" style="position:relative;overflow:hidden;float:'+this.initFl+';background-color:#'+this.initBg+';border:0px solid black;width:'+this.initW+';height:'+this.initH+';" onMouseover="'+this.name+'.scrollLoop(0)" onMouseout="'+this.name+'.scrollLoop('+this.speed+')">';
        scrollStr = scrollStr + '<div id="'+this.name+'" style="position:absolute;top:'+this.initH+';left:0px;border:0px solid black;width:'+this.widthB+';height:'+this.heightB+';background-color:#'+this.Bg+'">';
        scrollStr = scrollStr + this.content;
        scrollStr = scrollStr + '<\/div><\/div>';
        document.getElementById(this.dom_id).innerHTML = 'hurz'+scrollStr;
         alert(scrollStr);
    }
    */
    if(this.scrollLayer) {
        this.timer = setInterval(this.name+'.scrollLayer()','100');
    }
}

