//Developed by Vladimir Lebedko

function progressBarImageList(width, height){
    var len = progressBarImageList.arguments.length - 2;
    if (len > 0) {
        this.list = new Array(len);
        this.length = len;
        this.width = width;
        this.height = height;
        var im;
        for (var j = 0; j < len; j++) {
            im = new Image(width, height);
            im.src = progressBarImageList.arguments[j + 2];
            this.list[j] = im;
        }
    }
}

function updateProgressBar(){
    with (this) {
        var i = low;
        for (var j = 0; j < size; j++) {
            images[j].src = i < value ? imgsrc1 : imgsrc0;
            i += delta;
        }
    }
}

function setProgressBarValue(value){
    this.value = value - 0;
    this.update();
}

function setProgressBarBounds(low, high){
    this.low = Math.min(low, high);
    this.high = Math.max(low, high);
    this.delta = (this.high - this.low) / this.size;
    this.update();
}

function progressBar(mId, res, size, style){
    if (res) {
        this.window = self;
        this.document = self.document;
        this.tag = null;
        this.id = mId + "ID";
        this.res = res;
        this.value = 0;
        this.low = 0;
        this.high = 100;
        this.size = size || 10;
        this.delta = 100 / this.size;
        this.style = style || 0;
        this.images = new Array(this.size);
        this.imgsrc0 = res.list[0] && res.list[0].src;
        this.imgsrc1 = res.list[1] && res.list[1].src;
        this.setValue = setProgressBarValue;
        this.update = updateProgressBar;
        this.setBounds = setProgressBarBounds;
        var hor = this.style < 2;
        var rev = this.style % 2;
        var innerProgressBarHTML = "";
        innerProgressBarHTML = '<table border="0"  cellspacing="0" cellpadding="0" unselectable="on" ' +
        (hor ? 'width="' + (this.size * res.width) + '" height="' + res.height + '"><tr>' : 'width="' + res.width +
        '" height="' +
        (this.size * res.height) +
        '">');
        for (var j = 0; j < this.size; j++) {
            innerProgressBarHTML = innerProgressBarHTML + (hor ? '' : '<tr>') + '<td width="' + res.width + '" height="' + res.height +
            '" unselectable="on"><img name="' +
            this.id +
            (rev ? this.size - j - 1 : j) +
            '" src="' +
            res.list[0].src +
            '" border="0" width="' +
            res.width +
            '" height="' +
            res.height +
            '"></td>' +
            (hor ? '' : '</tr>');
        }
        innerProgressBarHTML = innerProgressBarHTML + (hor ? '</tr>' : '') + '</table>';
        document.getElementById(mId).innerHTML = innerProgressBarHTML;
        for (var j = 0; j < size; j++) {
            this.images[j] = document.images[this.id + j] || new Image(1, 1);
        }
    }
}

//==========================================================

var sIndex;
var dIndex;
var sCount;
var dCount;
var mName;
var rName;
var url;

var SEGS = new progressBarImageList(12, 20, "img/p0.gif", "img/p1.gif");
var bar1 = new progressBar("mProgressBar", SEGS, 49);

var map = new GMap2(document.getElementById("mapDIV"));
var directions = new GDirections(map);
GEvent.addListener(directions, "load", OnDirectionLoad);
GEvent.addListener(directions, "error", OnDirectionLoad);
