﻿var BobImageMove = function(id, id1, id2, orient, speed) {
    this.outerID = id;
    this.innerID1 = id1;
    this.innerID2 = id2;
    this.orient = orient||'h';
    this.speed = speed||50;
    this.flag = true;
}

BobImageMove.prototype.init = function() {

    var self = this;

    $("#" + this.outerID).hover(function() {
        self.flag = false;
    },
    function() {
        self.flag = true;
    });

    if (this.orient == 'h') {
        if ($("#" + this.innerID1).width() > $("#" + this.outerID).width()) {
            $("#" + this.innerID2).html($("#" + this.innerID1).html());
            setInterval(function() { self.marquee(); }, self.speed);
        }
    } else if (this.orient == 'v') {
        if ($("#" + this.innerID1).height() > $("#" + this.outerID).height()) {
            $("#" + this.innerID2).html($("#" + this.innerID1).html());
            setInterval(function() { self.marquee(); }, self.speed);
        }
    }
}

BobImageMove.prototype.marquee = function() {
    if (this.flag) {
        if (this.orient == 'h') {
            if ($("#" + this.outerID).scrollLeft() >= $("#" + this.innerID1).width())
                $("#" + this.outerID)[0].scrollLeft -= $("#" + this.innerID1).width();
            else {
                $("#" + this.outerID)[0].scrollLeft++;
            }
        } else if (this.orient == 'v') {
            if ($("#" + this.outerID).scrollTop() >= $("#" + this.innerID1).height())
                $("#" + this.outerID)[0].scrollTop -= $("#" + this.innerID1).height();
            else {
                $("#" + this.outerID)[0].scrollTop++;
            }
        }
    }
}

/*var m = new BobImageMove("d1", "td1-1", "td1-2");
m.init();*/
