    /*------------------------------------------------------------------------------
      Purpose : A  vertical/horizontal scrolling text box

      Usage   : - Add the function to the [onload] event of the <body> tag
                  Vertical scrolling   : vInitScroll(X, Y, Width, Heigh, Speed, Direction) Or 
                  Horizontal scrolling : hInitScroll(X, Y, Width, Heigh, Speed, Direction)
                  
                - Direction :  1 - left right / top down
                              -1 - right left / bottom up  
                              
                - Add the following lines to your <body>
                   <div id="newsContent" style="position:relative;display:none">
                        Scrolling Content Here
                   </div>
                
    ------------------------------------------------------------------------------*/

    var hScrollSpeed = 0; 
    var hScrollDir   = 1; 
    var vScrollSpeed = 1; 
    var vScrollDir   = -1; 

    function changeSpeedDir(direction, speed){
        hScrollDir  = direction;
        hScrollSpeed = speed;
    }

    function hScroll(){
            
            var box         = document.getElementById('scrollBox');
            var content     = document.getElementById('scrollContent');         

            var leftMargin  =  box.style.left.replace('px','') - box.style.width.replace('px','') + 60;
            var rightMargin =  box.style.width.replace('px','') - box.offsetWidth + 10;
          
            var newPosX     = parseInt(content.style.left.replace('px','')) + (hScrollSpeed * hScrollDir) ;			            
                
            var margin      = (hScrollDir < 0)?  leftMargin : rightMargin;
            var beginPosX   = (hScrollDir < 0)?  rightMargin : leftMargin;

            if ( (newPosX * hScrollDir) > (margin * hScrollDir) ) 
                    content.style.left = content.style.left;
            else
                    content.style.left = newPosX + 'px';  

            //document.getElementById('msg').innerHTML = 'posX :' + newPosX + ' margin:' + margin;
    }

    function hInitScroll(posX, posY, boxWidth, boxHeight, speed, direction ){
        
        var box                 = document.createElement('div');                
        box.id                  = 'scrollBox'; 

        box.style.position      = 'absolute';
        box.style.overflow      = 'hidden';
        box.style.border        = '0px solid #000000';
        box.style.backgroundColor = '#ffffff';

        box.style.width         = boxWidth + 'px';
        box.style.height        = boxHeight + 'px';
        box.style.left          = posX + 'px';
        box.style.top           = posY + 'px';
        
        var content             = document.createElement('div');                
        content.id              = 'scrollContent';                                            

        content.style.position   = 'relative';     
        content.style.height     = '90%';           
        content.style.left       = '10px';             
        content.style.width      = document.getElementById('newsContent').offsetWidth;
        document.getElementById('newsContent').style.display = 'none';

        box.appendChild(content);                    
        document.body.appendChild(box);
       
        setInterval('hScroll()', speed);	    
        content.innerHTML        = document.getElementById('newsContent').innerHTML;         
    }

    function vScroll(){
            var box          = document.getElementById('scrollBox');
            var content      = document.getElementById('scrollContent');

            var topMargin    = parseInt(box.style.top.replace('px','')) - box.clientHeight - 0 ;
            var bottomMargin = parseInt(box.style.top.replace('px','')) + box.clientHeight + 0 ;
          
            var newPosY      = parseInt(content.style.top.replace('px','')) + (vScrollSpeed * vScrollDir) ;			            
                
            var margin       = (vScrollDir < 0)?  topMargin : bottomMargin;
            var beginPosY    = (vScrollDir < 0)?  bottomMargin : topMargin;

            if ( (newPosY * vScrollDir) > (margin * vScrollDir) ) 
                    content.style.top = beginPosY + 'px';
            else
                    content.style.top = newPosY + 'px';                    
            
    }

    function vInitScroll(posX, posY, boxWidth, boxHeight, speed, direction ){
        var box                 = document.createElement('div');                
        box.id                  = 'scrollBox'; 

        box.style.position      = 'relative';
        box.style.overflow      = 'hidden';
        box.style.border        = '0px solid #000000';

        box.style.width         = boxWidth + 'px';
        box.style.height        = boxHeight + 'px';
        box.style.left          = posX + 'px';
        box.style.top           = posY + 'px';
        
        box.onmouseover         = function(){vScrollSpeed = 0;};
        box.onmouseout          = function(){vScrollSpeed = 1;};

        var content             = document.createElement('div');                
        content.id              = 'scrollContent';                                            

        content.style.position   = 'relative';     
        content.style.width      = '90%';                    
        content.style.left       = '10px';
        content.style.top        = '10px';        

        box.appendChild(content);                    
        document.body.appendChild(box);

        setInterval('vScroll()', speed);	
        vScrollDir               = direction;
        content.innerHTML        = document.getElementById('newsContent').innerHTML;   
    }
