/* scroller version 3.1 */

var scrollers = [];
var currentscroller = null;

function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}

function Scroller(id,topval,multiplier) {
	this.tops = [];
	this.topVals = [];
	this.topval = topval;
	this.id = id;
	this.scrollInt = null;
	this.multiplier = multiplier;
	this.cont = document.getElementById('scroll_text'+this.id);
	
	this.getTops = function() {
		var eh = this.cont.clientHeight * this.multiplier;
		var sh = document.getElementById('scroll_container'+this.id).clientHeight;
		
		if(vIE() != -1) {
			for(i=0;i<11;i++) {
				this.tops[i] = (Math.round((eh-sh)/10 * i))-this.topval;
				this.topVals[i] = this.tops[i];
				if(this.tops[i]>0) {
					this.tops[i] = '-'+this.tops[i];
					this.topVals[i] = this.topVals[i] * -1;
				}
				this.tops[i] = this.tops[i] + 'px';
			}
		} else {
			for(i=0;i<11;i++) {
				this.tops[i] = (Math.round((eh-sh)/10 * i));
				this.topVals[i] = this.tops[i];
				if(this.tops[i] > 0) {
					this.tops[i] = '-' + this.tops[i];
					this.topVals[i] = this.topVals[i] * -1;
				}
				this.tops[i] = this.tops[i] + 'px';
			}
		}			
	}
	
	this.scrollDown = function() {
		if(this.tops.length < 1)
			this.getTops();
			
		var newval = this.tops[1];
		var oldval = this.cont.style.marginTop;
		
		if(oldval == this.tops[10]) {
			return false;
		}
		
		if(oldval > this.topVals[0]) {
			newval = this.tops[0];
		} else {
			if(oldval < this.topVals[10]) {
				newval = this.tops[10];
			} else {
				for(i=9;i>0;i--) {
					if(oldval == this.tops[i]) {
						newval = this.tops[i+1];
						break
					}
				}
			}
		}
		
		this.cont.style.marginTop = newval;
	}

	this.scrollUp = function() {
		if(this.tops.length < 1)
			this.getTops();
			
		var newval = this.topval + 'px';
		var oldval = this.cont.style.marginTop;
			
		if(oldval > this.topVals[0]) {
			newval = this.tops[10];
		} else {
			if(oldval < this.topVals[10]) {
				newval = this.tops[0];
			} else {
				for(i=1;i<11;i++) {
					if(oldval == this.tops[i] && i > 1) {
						newval = this.tops[i-1];
						break;
					}
				}
			}
		}
		
		this.cont.style.marginTop = newval;
	}
	
	this.startScrolling = function(dir) {
		if(dir=='up') {
			this.scrollInt = setInterval("scrollUp(scrollers["+this.id+"])", 200);
		} else {
			this.scrollInt = setInterval("scrollDown(scrollers["+this.id+"])", 200);
		}
	}
	
	this.stopScrolling = function() {
		clearInterval(this.scrollInt);
	}
}

function scrollUp(item) {
	item.scrollUp();
}

function scrollDown(item) {
	item.scrollDown();
}

function handle(delta) {
	try {
		if(currentscroller != null && scrollers.length > 0) {
			scrollers[currentscroller].stopScrolling();
			if(delta < 0) {
				scrollers[currentscroller].scrollDown();
			} else {
				scrollers[currentscroller].scrollUp();
			}
		}
	} catch(err) {
		return false;
	}
}

function wheel(event) {
    var delta = 0;
    
    if(!event)
		event = window.event;
    
    if(event.wheelDelta) {
    	delta = event.wheelDelta/120;
         
        if(window.opera)
        	delta = -delta;
    } else if(event.detail) {
      	delta = -event.detail/3;
    }
        
    if(delta && currentscroller != null)
       	handle(delta);
        
    if(currentscroller != null) {
      	if(event.preventDefault)
       		event.preventDefault();
    	event.returnValue = false;
    }
}

if(window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;