var imageTicker = {
    
    //control parameters
    placementId : 'class_image',
    ownPlaceId : 'nt_',
    
    diashow : false,
    keepShow : 7000,
    appear : true,
    appearDirection : 'show',
    appearSpeed : 500,
    currentOpacity : 0,
    animate : false,
    
    //news Ticker object definition
    newsArray : new Array(),
    currentPointer : -1,
    timer : null,
    isLocked : false,
    
    placement : null,
    ownPlace : null,
    currImg : null,
    currTxt : null,
    
    maxImgHeight : 0,
    
    //beginn methods
    init : function(){
        this.placement = document.getElementById(this.placementId);
        this.ownPlace = document.createElement('div');
        this.ownPlace.setAttribute('id',this.ownPlaceId);
        this.currImg = new Image();
        this.currImg.setAttribute('id',this.ownPlaceId+"img");
        this.currTxt = document.createElement('div');
        this.currTxt.setAttribute('id',this.ownPlaceId+"txt");
        this.ownPlace.appendChild(this.currImg);
        this.ownPlace.appendChild(this.currTxt);
        this.placement.appendChild(this.ownPlace);
        
        this.animateIt();
    },
    
    insertNews : function( text, imgSrc ){
        this.newsArray.push( Array(text, imgSrc) );
    },
    
    showNext : function(value){
        this.currentPointer = value?value:(this.currentPointer+1);
        this.currentPointer = (this.currentPointer >= this.newsArray.length || this.currentPointer < 0)?0:this.currentPointer;
        
        if(this.newsArray.length>0){
            this.currImg.src = this.newsArray[this.currentPointer][1];
            this.currTxt.innerHTML = this.newsArray[this.currentPointer][0];
        }
        else{
            this.showError(1);
        }
    },
    
    showPrevious : function(value){
        this.currentPointer = value?value:(this.currentPointer-1);
        this.currentPointer = (this.currentPointer >= this.newsArray.length || this.currentPointer < 0)?(this.newsArray.length-1):this.currentPointer;
        
        if(this.newsArray.length>0){
            this.currImg.src = this.newsArray[this.currentPointer][1];
            this.currTxt.innerHTML = this.newsArray[this.currentPointer][0];
        }
        else{
            this.showError(1);
        }
    },
    
    showError : function(key){
        switch(key){
            case 1:
                this.currTxt.innerHTML = "";
                break;
            default:
                break;
        }
    },
    
    animateIt : function(){
        if(this.isLocked){
            this.isLocked = false;
            if(this.diashow){
                window.setTimeout("imageTicker.animateIt()", this.keepShow);
            }
        }
        else{
            if(this.appear){
                if(this.appearDirection=='show'){
                    this.setOpacity(0);
                    this.showNext();
                    if(this.opacity(0, 100, this.appearSpeed));
                    this.appearDirection='hide';
                    if(this.diashow){
                        window.setTimeout("imageTicker.animateIt()", this.keepShow);
                    }
                }
                else{
                    this.setOpacity(100);
                    if(this.opacity(100, 0, this.appearSpeed));
                    this.appearDirection='show';
                    if(this.diashow){
                        window.setTimeout("imageTicker.animateIt()", this.appearSpeed);
                    }
                }
            }
            else{
                this.showNext();
                if(this.diashow){
                    window.setTimeout("imageTicker.animateIt()", this.keepShow);
                }
            }
        }
    },
    
    opacity : function(opStart, opEnd, opTime){
        var opSpeed = Math.round(opTime / 100);
        var opTimer = 0;
        
        if(opStart > opEnd){
            for(i=opStart; i >= opEnd; i--){
                setTimeout("imageTicker.setOpacity("+i+")",(opTimer * opSpeed));
                opTimer++;
            }
        }
        else if(opStart < opEnd){
            for(i=opStart; i <= opEnd; i++){
                setTimeout("imageTicker.setOpacity("+i+")",(opTimer * opSpeed));
                opTimer++;
            }
        }
        return true;
    },
    
    setOpacity : function(value,grant){
        if(!this.isLocked || grant){
            value = (value<0)?0:((value>=100)?100:value);
            this.ownPlace.style.opacity = (value / 100);
            this.ownPlace.style.MozOpacity = (value / 100);
            this.ownPlace.style.KhtmlOpacity = (value / 100);
            this.ownPlace.style.filter = "alpha(opacity=" + value + ")";
            this.currentOpacity = value;
        }
        return true;
    },
    
    lockUp : function(){
        this.isLocked = true;
        this.setOpacity(100,true);
    },
    
    setMaxHeight : function( maxImgHeight ){
        this.maxImgHeight = maxImgHeight;
    }
    
}


