var ScrollAreaDownSRC = "/images/modules/news/down_over.gif";
var ScrollAreaUpSRC = "/images/modules/news/up.gif";
var ScrollAreaDownOverSRC = "/images/modules/news/down_over.gif";
var ScrollAreaUpOverSRC = "/images/modules/news/up_over.gif";
function ScrollAreaH(leftId,rightId,areaId){
    var DIRECTION_LEFT = -1;
    var DIRECTION_RIGHT = 1;
    this.id = ScrollAreas.length;
    this.left = document.getElementById(leftId);
    this.right = document.getElementById(rightId);
    this.area = document.getElementById(areaId);
    var ID = this.id;
    var intervalId = null;
    var direction = null;
    var step = 1;
    this.scroll = function(){
        this.area.scrollLeft += direction * step;
        if (!this.canScroll(direction)) {
            this.stopScroll();
            if (direction < 0) this.left.onmouseout();
            else this.right.onmouseout();
        }
    }
    this.canScroll = function(direction) {
        if (direction == DIRECTION_RIGHT && this.area.scrollWidth == this.area.scrollLeft + this.area.clientWidth) return false;
        if (direction == DIRECTION_LEFT && this.area.scrollLeft == 0) return false;
        return true;
    }

     this.startScroll = function(_direction, speed) {
        if (intervalId != null) this.stopScroll();
        if (!this.canScroll(_direction)) return false;
        direction = _direction;
        intervalId = setInterval("ScrollAreas[" + ID + "].scroll()", speed);
        this.scroll();
        return true;
    }
    this.stopScroll = function() {
        clearInterval(intervalId);
        intervalId = null;
    }


    this.left.onmouseover = function() {
        if (ScrollAreas[ID].startScroll(DIRECTION_LEFT, 40))
        //TODO: up over
            this.childNodes[0].src = "/templates/news/template2images/left_over.gif";
    }
    this.left.onmouseout = function() {
        this.childNodes[0].src = "/templates/news/template2images/left.gif";
        ScrollAreas[ID].stopScroll();
    }
    this.left.onmousedown = function() {
        ScrollAreas[ID].startScroll(DIRECTION_LEFT, 20);
    }
    this.left.onmouseup = function() {
        ScrollAreas[ID].startScroll(DIRECTION_LEFT, 40);
    }
    this.right.onmouseover = function() {
        if (ScrollAreas[ID].startScroll(DIRECTION_RIGHT, 40))
        //TODO: down over
            this.childNodes[0].src = "/templates/news/template2images/right_over.gif";
    }
    this.right.onmouseout = function() {
        this.childNodes[0].src = "/templates/news/template2images/right.gif";
        ScrollAreas[ID].stopScroll()
    }
    this.right.onmousedown = function() {
        ScrollAreas[ID].startScroll(DIRECTION_RIGHT, 20);
    }
    this.right.onmouseup = function() {
        ScrollAreas[ID].startScroll(DIRECTION_RIGHT, 40);
    }
    ScrollAreas[ID] = this;

}


function ScrollArea(upId, downId, areaId) {
    var DIRECTION_UP = -1;
    var DIRECTION_DOWN = 1;

    this.id = ScrollAreas.length;
    this.up = document.getElementById(upId);
    this.down = document.getElementById(downId);
    this.area = document.getElementById(areaId);
    var ID = this.id;
    var intervalId = null;
    var direction = null;
    var step = 1;
    this.scroll = function() {
        this.area.scrollTop += direction * step;
        if (!this.canScroll(direction)) {
            this.stopScroll();
            if (direction < 0) this.up.onmouseout();
            else this.down.onmouseout();
        }
    }
    this.canScroll = function(direction) {
        if (direction == DIRECTION_DOWN && this.area.scrollHeight == this.area.scrollTop + this.area.clientHeight) return false;
        if (direction == DIRECTION_UP && this.area.scrollTop == 0) return false;
        return true;
    }
    this.startScroll = function(_direction, speed) {
        if (intervalId != null) this.stopScroll();
        if (!this.canScroll(_direction)) return false;
        direction = _direction;
        intervalId = setInterval("ScrollAreas[" + ID + "].scroll()", speed);
        this.scroll();
        return true;
    }
    this.stopScroll = function() {
        clearInterval(intervalId);
        intervalId = null;
    }
    this.up.onmouseover = function() {
        if (ScrollAreas[ID].startScroll(DIRECTION_UP, 40))
        //TODO: up over
            this.childNodes[0].src = ScrollAreaUpOverSRC;
    }
    this.up.onmouseout = function() {
        this.childNodes[0].src = ScrollAreaUpSRC;
        ScrollAreas[ID].stopScroll();
    }
    this.up.onmousedown = function() {
        ScrollAreas[ID].startScroll(DIRECTION_UP, 20);
    }
    this.up.onmouseup = function() {
        ScrollAreas[ID].startScroll(DIRECTION_UP, 40);
    }
    this.down.onmouseover = function() {
        if (ScrollAreas[ID].startScroll(DIRECTION_DOWN, 40))
        //TODO: down over
            this.childNodes[0].src = ScrollAreaDownOverSRC;
    }
    this.down.onmouseout = function() {
        this.childNodes[0].src = ScrollAreaDownSRC;
        ScrollAreas[ID].stopScroll()
    }
    this.down.onmousedown = function() {
        ScrollAreas[ID].startScroll(DIRECTION_DOWN, 20);
    }
    this.down.onmouseup = function() {
        ScrollAreas[ID].startScroll(DIRECTION_DOWN, 40);
    }
    ScrollAreas[ID] = this;
}
var ScrollAreas = new Array();
