var st = 1;
function marqueeConstructor(aParent, aStep, aSpeed, aDir) {
 if(!aParent) return;
 this.parent = aParent;
 if (aDir == 1) this.parentBound = this.parent.offsetWidth;
 if (aDir == 2) this.parentBound = this.parent.offsetHeight;
 this.marquee = aParent.getElementsByTagName('div')[0];
 if (aDir == 1) this.marqueeBound = this.marquee.offsetWidth; 
 if (aDir == 2) this.marqueeBound = this.marquee.offsetHeight;
 this.marqueeHeight = 0; //this.marqueeBound;
 this.step = aStep;
 this.speed = aSpeed;
 this.dir = aDir;
 this.attachHandler(aParent, 'mouseout', this.bindContext('onMouseout'));
 this.attachHandler(aParent, 'mouseover', this.bindContext('stopMove'));
 this.startMove();
}

marqueeConstructor.prototype = {
 startMove: function() {
 if ( (this.marqueeHeight<0 && this.marqueeHeight<-this.marqueeBound) || (this.marqueeHeight>0 && this.marqueeHeight>this.parentBound) ) /*this.step = -this.step;*/ this.marqueeHeight = this.parentBound;
 this.marqueeHeight += this.step;
 if(this.dir == 1) this.marquee.style.left = this.marqueeHeight + 'px';
 if(this.dir == 2) this.marquee.style.top = this.marqueeHeight + 'px';
 this.timerMove = setTimeout(this.bindContext('startMove'), this.speed);
 },

 stopMove: function() { 
 if (this.timerMove) clearTimeout(this.timerMove);
 if (this.timerOut) clearTimeout(this.timerOut);
 },

 onMouseout: function () {
 this.timerOut = setTimeout(this.bindContext('startMove'), 0);
 },

 attachHandler: function (aObj, aEvent, aFunc) {
 aObj.addEventListener
 ? aObj.addEventListener(aEvent, aFunc, false)
 : (aObj.attachEvent
 ? aObj.attachEvent('on' + aEvent, aFunc)
 : '');
 },

 bindContext: function (aMethod) {
 var context = this;
 return (function () { context[aMethod](); });
 }
}

marqueeConstructor.prototype.attachHandler(window,
 'load',
 function () {
var allPageTags=document.getElementsByTagName("*"); 
for (i=0; i<allPageTags.length; i++)
 if (allPageTags[i].className=='marquee1')
 new marqueeConstructor(allPageTags[i], -2, 2/*скорость*/, 2);
for (i=0; i<allPageTags.length; i++)
 if (allPageTags[i].className=='marquee2')
 new marqueeConstructor(allPageTags[i], -1, 25/*скорость*/, 2);
 }
);

