﻿var maps = new Array();

function Map(useWhiteImages, name) {
    this.addTerminal = function(name, street, csz, phone, imageName, imageWhiteName, mapURL) {
        this.terminals.push(new Array(name, street, csz, phone, "/images/" + imageName,
        "/images/" + imageWhiteName, mapURL));
    }

    this.name = name;
    maps[name] = this;

    this.cycleImages = true;
    this.useWhiteImages = useWhiteImages;
    this.terminals = new Array();
    this.noCycling = false;

    // stop cycling at some point so that someone doesn't leave their browser
    // up over the weekend and use all of our bandwidth
    setTimeout('maps["' + this.name + '"].stopCycling()', 2 * 60 * 1000);

    if (this.useWhiteImages == true)
        $('.MapSectionBlue').addClass('MapSectionWhite').removeClass('MapSectionBlue');
    else
        $('.MapSectionWhite').addClass('MapSectionBlue').removeClass('MapSectionWhite');

    this.currentTerminalIndex = -1;

    this.cycleToNextTerminal = function() {
        if (this.noCycling != true) {
            this.showNextTerminalInternal();
            setTimeout('if (maps["' + this.name + '"].cycleImages == true) { maps["' + this.name + '"].cycleToNextTerminal(); }', 4000);
        }
    }

    this.stopCycling = function() {
        this.noCycling = true;
    }

    this.showNextTerminal = function() {
        this.cycleImages = false;
        this.showNextTerminalInternal();
    }

    this.showPrevTerminal = function() {
        this.cycleImages = false;
        this.showPrevTerminalInternal();
    }

    this.showTerminal = function() {
        var terminal = this.terminals[this.currentTerminalIndex];
        $('#terminalName').html(terminal[0]);
        $('#address').html(terminal[1]);
        $('#cityStZip').html(terminal[2]);
        $('#phone').html(terminal[3]);
        if (this.useWhiteImages == true)
            $('#Map').css('background-image', "url('" + terminal[5] + "')");
        else
            $('#Map').css('background-image', "url('" + terminal[4] + "')");
    }

    this.showMap = function() {
        window.open(this.terminals[this.currentTerminalIndex][6], this.terminals[this.currentTerminalIndex][0]);
    }

    this.showNextTerminalInternal = function() {
        if (this.currentTerminalIndex >= this.terminals.length - 1)
            this.currentTerminalIndex = 0;
        else
            this.currentTerminalIndex++;
        this.showTerminal();
    }

    this.showPrevTerminalInternal = function() {
        if (this.currentTerminalIndex > 0)
            this.currentTerminalIndex--;
        else
            this.currentTerminalIndex = this.terminals.length - 1;
        this.showTerminal();
    }
}