/**
*
* myScroller:  News scroller
* Copyright (c) 2006, Raul IONESCU <ionescu.raul@gmail.com>, Bucharest, ROMANIA
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @package      myScroller
* @copyright 	Copyright (c) 2006, Raul IONESCU.
* @author 	Raul IONESCU <ionescu.raul@gmail.com>
* @license      http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 	1.0
* @category 	Javascript news scroller
* @access 	public
*
*/
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
function myScroller(scrollerID,speed)
////////////////////////////////////////////////////////
{
speed = ((isNaN(speed)==true)?(16):(Math.abs(parseInt(speed))));

if (!(this instanceof (myScroller))) return new myScroller(scrollerID,speed);

var stopped    = false;
var intervalID = null; 
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
this.init=function()
////////////////////////////////////////////////////////
{
if(stopped == true) return;
var _n, _nc, _nHeight, _ncHeight, xmlElement;


if(((_n = getElement(scrollerID)) == null) || ((_nc = _n.firstChild) == undefined) || (_nc.nodeType == undefined)) return;

xmlElement = myAJAX.prototype.constants.XML.NodeType.Element;
while(_nc.nodeType != xmlElement)
        if((_nc = _nc.nextSibling) == null) break;

if((_nc == null) || (_nc.nodeType != xmlElement)) return;

_nHeight  = getElementHeight(_n);
_ncHeight = getElementHeight(_nc);

if(_nHeight >= _ncHeight) return;

_nc.position    = 0;
_nc.start       = new Number(_nHeight);
_nc.totalHeight = new Number(0 - _ncHeight);
eval('myScroller.prototype.nodes.' + scrollerID + ' = _nc;');
intervalID=setInterval('_scroll("' + scrollerID + '")',speed);
_n.onmouseover = function() { if(intervalID!=null) { clearInterval(intervalID); intervalID=null; } }
_n.onmouseout  = function() { if(stopped == false) intervalID = setInterval('_scroll("' + scrollerID + '")',speed); }
}
////////////////////////////////////////////////////////
this.stop = function() { if(intervalID!=null) clearInterval(intervalID); }
////////////////////////////////////////////////////////
this.switchScrolling = function()
{
var _n,_nc;
if(((_n = getElement(scrollerID)) == null) || ((_nc = _n.firstChild) == undefined) || (_nc.nodeType == undefined)) return;

stopped = !stopped;
if(stopped == true) 
        {
         this.stop();
         _n.style.overflowY='auto';
        } 
else 
        {
         _n.style.overflowY='hidden';
         this.init();
        } 
_nc.style.top = _n.style.top + 138;
}
////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////
myScroller.prototype.nodes = new Object();
////////////////////////////////////////////////////////
function _scroll(scrollerID)
////////////////////////////////////////////////////////
{
var n = eval('myScroller.prototype.nodes.' + scrollerID);
if(n == undefined) return;
var position = n.position;

n.style.top = position+'px';	
if(position == n.totalHeight)  position = n.start; 
n.position = --position;
}
////////////////////////////////////////////////////////