
// Package Manager Class
PackageManagerClass = function() {
    this.pages = new Array();
    this.categories = new Object();
    this.packages = new Object();
    this.NULL_PAGE = new PGc("", "", "");
}
PackageManagerClass.prototype.addPage = function(pg) {
    this.pages[this.pages.length] = pg;
    for(var ci=0; ci < pg.categories.length; ci++) {
        var c = pg.categories[ci];
        this.categories[c.id] = c;
        for(var pi = 0; pi < c.packages.length; pi++) {
            var p = c.packages[pi];
            this.packages[p.id] = p;
        }
    }
}
PackageManagerClass.prototype.getPage = function(id) {
    var ret = null;
    for(var i=0; i < this.pages.length; i++) {
        if(this.pages[i].id == id) {
            ret = this.pages[i];
            break;
        }
    }
    return (ret == null) ? this.NULL_PAGE : ret;
}
// Page Class
PGc = function(id, name, sortOrder) {
    this.id = id;
    this.name = name;
    this.sortOrder = sortOrder;
    this.categories = new Array();
    this.packages = new Object();
}
// add category
PGc.prototype.ac = function(category) {
    this.categories[this.categories.length] = category;
    category.page = this;
    for(var i = 0; i < category.packages.length; i++) {
        var p = category.packages[i];
        this.packages[p.id] = p;
    }
}
PGc.prototype.getURL = function() {
    return "overview-" + this.id + ".jsp";
}
// Category Class
Cc = function(id, name, sortOrder, categoryIcon) {
    this.id = id;
    this.name = name;
    this.sortOrder = sortOrder;
    this.categoryIcon = categoryIcon;
    this.packages = new Array();
    this.page = null;
    this.message = null;
}
// The default message to be shown when no packages are selected.
Cc.prototype.defaultMessage = "Press the button for detailed information and to request more information.";
// this method updates the message on the page.
Cc.prototype.updateMessage = function(msg) {
    if(gebi) {
        // if no argument provided, don't change message, just update it.
        if(arguments.length > 0) {
            this.message = msg;
        }
        // get default message if needed
        var msg2 = this.message;
        if(msg2 == null) {
            msg2 = this.defaultMessage;
        }
        var cn = "packagesInfo";
        // only update if packages are collapsed
        if(document.getElementById(this.id).className != "packages") {
            msg2 = "Please select the items you are interested in.  They will appear in your cart to the right.";
        } else if(this.message != null) {
            cn += " selected";
        }
        document.getElementById(this.id + "Info").className = cn;
        // change message
        document.getElementById(this.id + "Info").innerHTML = msg2;
    }
}
// add package
Cc.prototype.ap = function(p) {
    this.packages[this.packages.length] = p;
    p.category = this;
}
Cc.prototype.getURL = function() {
    return this.page.getURL() + "?expand=" + escape(this.id) + "#" + escape(this.id);
}
// Package Class
Pc = function(id, name, sortOrder, classIcon, categoryIcon, excludes) {
    this.id = id;
    this.name = name;
    this.sortOrder = sortOrder;
    this.classIcon = classIcon;
    if(this.classIcon == "") {
        this.classIcon = "med-white";
    }
    this.categoryIcon = categoryIcon;
    // Packages that cannot be selected at the same time
    this.excludes = new Array();
    if(excludes) {
        var ex = excludes.split(/[\s,]+/)
        for(var i=0; i < ex.length; i++) {
            if(ex[i].length > 0) {
                var idx = this.excludes.length;
                this.excludes[idx] = ex[i];
            }
        }
    }
    this.category = null;
}
Pc.prototype.getCategoryIcon = function() {
    return (this.categoryIcon == null) ? this.category.categoryIcon : this.categoryIcon;
}
Pc.prototype.getURL = function() {
    return this.category.getURL();
}
Pc.prototype.compareTo = function(p) {
    var r = this.category.page.sortOrder - p.category.page.sortOrder;
    if(r==0) {
        r = this.category.sortOrder - p.category.sortOrder;
        if(r == 0) {
            r = this.sortOrder - p.sortOrder;
            if(r == 0) {
                if(this.name < p.name) {
                    r = -1;
                } else if(this.name > p.name) {
                    r = 1;
                }
            }
        }
    }
    return r;
}
// classes used on this page
packageManager = new PackageManagerClass();
var pg, c;
pg = new PGc("homecinemas", "Home Cinemas", 1);
  c = new Cc("cinema-base", "1: Dedicated Home Cinema Base", 1, "dedicated-theater");
    c.ap(new Pc("cinema-base-bronze", "Bronze Home Cinema Base", 1, "med-bronze", "dedicated-theater", "cinema-base-silver,cinema-base-gold,cinema-base-diamond"));
    c.ap(new Pc("cinema-base-silver", "Silver Home Cinema Base", 2, "med-silver", "dedicated-theater", "cinema-base-bronze,cinema-base-gold,cinema-base-diamond"));
    c.ap(new Pc("cinema-base-gold", "Gold Home Cinema Base", 3, "med-gold", "dedicated-theater", "cinema-base-silver,cinema-base-bronze,cinema-base-diamond"));
    c.ap(new Pc("cinema-base-diamond", "Diamond Cinema Base", 4, "med-diamond", "dedicated-theater", "cinema-base-bronze,cinema-base-silver,cinema-base-gold"));
  pg.ac(c);
  c = new Cc("cinema-theme", "2: Design Theme", 2, "cinema-theme");
    c.ap(new Pc("cinema-theme-none", "No Theme Design", 1, "med-white", "none", "cinema-theme-standard,cinema-theme-complete,cinema-theme-custom"));
    c.ap(new Pc("cinema-theme-standard", "Standard Design", 2, "med-bronze", "cinema-theme", "cinema-theme-none,cinema-theme-complete,cinema-theme-custom"));
    c.ap(new Pc("cinema-theme-complete", "Full Room Design", 3, "med-gold", "cinema-theme", "cinema-theme-none,cinema-theme-standard,cinema-theme-custom"));
    c.ap(new Pc("cinema-theme-custom", "Custom Theme Design", 4, "med-diamond", "cinema-theme", "cinema-theme-none,cinema-theme-standard,cinema-theme-complete"));
    c.ap(new Pc("cinema-theme-starlit", "Starlit Ceiling", 5, "starlit", "blank", ""));
    c.ap(new Pc("cinema-theme-curtains", "Motorized Curtains", 6, "med-white", "curtains", ""));
  pg.ac(c);
  c = new Cc("cinema-seats", "3: Theater Seating", 3, "cinema-seats");
    c.ap(new Pc("cinema-seats-flipdown", "Flip-Down Seating", 1, "med-white", "cinema-seats", "cinema-chairs,cinema-chairs-motorized"));
    c.ap(new Pc("cinema-chairs", "Theater Chairs", 2, "med-white", "cinema-chairs", "cinema-seats-flipdown,cinema-chairs-motorized"));
    c.ap(new Pc("cinema-chairs-motorized", "Motorized Reclining Chairs", 3, "med-gold", "cinema-chairs", "cinema-seats-flipdown,cinema-chairs"));
    c.ap(new Pc("cinema-no-tiers", "No Tiers (Flat Seating)", 4, "med-white", "cinema-flat", "cinema-tiered"));
    c.ap(new Pc("cinema-tiered", "Tiered Seating", 5, "med-white", "cinema-tier", "cinema-no-tiers"));
    c.ap(new Pc("cinema-bass-shaker", "Bass Shakers Option", 6, "med-white", "cinema-shaker", ""));
  pg.ac(c);
  c = new Cc("cinemas-control", "4: Controlling Your Home Cinema", 4, "cinema-control");
    c.ap(new Pc("cinema-control-basic", "Basic Remote", 1, "med-white", "cinema-remote", "cinema-control-color,cinema-control-touchpanel,cinema-control-wireless-touchpanel"));
    c.ap(new Pc("cinema-control-color", "Color Touchscreen Remote", 2, "med-white", "cinema-cremote", "cinema-control-basic,cinema-control-touchpanel,cinema-control-wireless-touchpanel"));
    c.ap(new Pc("cinema-control-touchpanel", "Advanced Touchpanel Control", 3, "med-white", "cinema-panel", "cinema-control-basic,cinema-control-color,cinema-control-wireless-touchpanel"));
    c.ap(new Pc("cinema-control-wireless-touchpanel", "Wireless Touchpanel Control", 4, "med-yellow-ring", "cinema-wpanel", "cinema-control-basic,cinema-control-color,cinema-control-touchpanel"));
  pg.ac(c);
  c = new Cc("cinemas-extra", "5: Cinema Add-Ons", 5, "cinema-extra");
    c.ap(new Pc("cinema-extra-calibration", "Cinema Calibration", 1, "med-white", "calibrate", ""));
    c.ap(new Pc("cinema-extra-marquee", "Theater Marquee", 2, "med-yellow-ring", "cinema-extra", ""));
    c.ap(new Pc("cinema-extra-posters", "Movie Poster Displays", 3, "med-blue-ring", "cinema-extra", ""));
    c.ap(new Pc("cinema-extra-refreshments", "\"Refreshments Counter\"", 4, "med-marble", "cinema-extra", ""));
    c.ap(new Pc("cinema-extra-ticketbooth", "\"Ticket Booth\"", 5, "med-orange-ring", "cinema-extra", ""));
  pg.ac(c);
packageManager.addPage(pg);
pg = new PGc("mediarooms", "Media Rooms", 2);
  c = new Cc("mediaroom-base", "1: Media Room Base", 1, "media-room");
    c.ap(new Pc("media-base", "Basic Media Room", 1, "med-white", "media-room", ""));
  pg.ac(c);
  c = new Cc("mediaroom-tv", "2: Media Room TV Type", 2, "media-room");
    c.ap(new Pc("media-plasma", "Plasma Television", 1, "med-gold", "plasma", "media-lcd,media-rearproj,media-frontproj"));
    c.ap(new Pc("media-lcd", "LCD Television", 2, "med-silver", "lcd", "media-plasma,media-rearproj,media-frontproj"));
    c.ap(new Pc("media-rearproj", "Rear Projection Television", 3, "med-white", "rearpro", "media-plasma,media-lcd,media-frontproj"));
    c.ap(new Pc("media-frontproj", "Front Projection System", 4, "med-black", "frontpro", "media-plasma,media-lcd,media-rearproj"));
  pg.ac(c);
  c = new Cc("mediaroom-speakers", "3: Media Room Speakers", 3, "media-room");
    c.ap(new Pc("media-speaker-onwall", "On-Wall Speakers", 1, "med-white", "speaker-onwall", "media-speaker-inwall,media-speaker-inceiling,media-speaker-bookshelf,media-speaker-surroundbar,media-speaker-floor"));
    c.ap(new Pc("media-speaker-inwall", "In Wall Speakers", 2, "med-white", "speaker-inwall", "media-speaker-onwall,media-speaker-inceiling,media-speaker-bookshelf,media-speaker-surroundbar,media-speaker-floor"));
    c.ap(new Pc("media-speaker-inceiling", "In Ceiling Speakers", 3, "med-white", "speaker-inceiling", "media-speaker-onwall,media-speaker-inwall,media-speaker-bookshelf,media-speaker-surroundbar,media-speaker-floor"));
    c.ap(new Pc("media-speaker-bookshelf", "Bookshelf Speakers", 4, "med-white", "speaker-bookshelf", "media-speaker-onwall,media-speaker-inwall,media-speaker-inceiling,media-speaker-surroundbar,media-speaker-floor"));
    c.ap(new Pc("media-speaker-surroundbar", "5-Channel Surround Bar", 5, "med-white", "speaker-sbar", "media-speaker-onwall,media-speaker-inwall,media-speaker-inceiling,media-speaker-bookshelf,media-speaker-floor"));
    c.ap(new Pc("media-speaker-floor", "Floor-Standing Speakers", 6, "med-white", "speaker-floor", "media-speaker-onwall,media-speaker-inwall,media-speaker-inceiling,media-speaker-bookshelf,media-speaker-surroundbar"));
    c.ap(new Pc("media-speaker-infloorsub", "In-Floor Subwoofer", 7, "med-white", "speaker-infloorsub", ""));
  pg.ac(c);
  c = new Cc("mediaroom-extras", "4: Media Room Extras", 4, "media-room");
    c.ap(new Pc("media-painting", "TV Concealing Painting", 1, "med-white", "painting", "media-mirror,media-moto-screen"));
    c.ap(new Pc("media-mirror", "TV Concealing Mirror", 2, "med-white", "mirror", "media-painting,media-moto-screen"));
    c.ap(new Pc("media-moto-screen", "Motorized Screen", 3, "med-gold", "motoscreen", "media-painting,media-mirror"));
    c.ap(new Pc("media-moto-blinds", "Motorized Window Blinds", 4, "med-gray-ring", "motoscreen", ""));
    c.ap(new Pc("media-gameport", "Video Game Port", 5, "med-white", "games-video", ""));
    c.ap(new Pc("media-wireless", "Wireless Remote Control", 6, "med-white", "cinema-remote", ""));
  pg.ac(c);
  c = new Cc("othertv", "Television for other areas of the house", 5, "other-video");
    c.ap(new Pc("othertv-kitchen", "Kitchen TV", 1, "med-white", "other-video", ""));
    c.ap(new Pc("othertv-exercise", "Exercise Room TV", 2, "med-green-ring", "other-video", ""));
    c.ap(new Pc("othertv-bedroom", "Bedroom Suite TV", 3, "med-blue-ring", "other-video", ""));
    c.ap(new Pc("othertv-office", "Home Office TV", 4, "med-bronze", "other-video", ""));
    c.ap(new Pc("othertv-bathroom", "Bathroom TV", 5, "med-diamond", "other-video", ""));
    c.ap(new Pc("othertv-guestroom", "Guest Room Suite TV", 6, "med-purple-ring", "other-video", ""));
    c.ap(new Pc("othertv-children", "Children\'s Room TV", 7, "med-yellow-ring", "other-video", ""));
    c.ap(new Pc("othertv-gameroom", "Gameroom TV", 8, "med-orange-ring", "other-video", ""));
    c.ap(new Pc("othertv-bar", "TV Over the Bar", 9, "med-gray-ring", "other-video", ""));
    c.ap(new Pc("othertv-garage", "Garage TV", 10, "med-silver", "other-video", ""));
    c.ap(new Pc("othertv-pool", "Poolside TV", 11, "med-blue", "other-video", ""));
  pg.ac(c);
packageManager.addPage(pg);
pg = new PGc("ambiance", "Tailored Ambiance", 3);
  c = new Cc("audio", "Whole House Audio", 1, "house-audio");
    c.ap(new Pc("audio-silver", "Silver Whole House Audio", 1, "med-silver", "house-audio", "audio-gold,audio-diamond"));
    c.ap(new Pc("audio-gold", "Gold Whole House Audio", 2, "med-gold", "house-audio", "audio-silver,audio-diamond"));
    c.ap(new Pc("audio-diamond", "Diamond Whole House Audio", 3, "med-diamond", "house-audio", "audio-gold,audio-silver"));
    c.ap(new Pc("audio-media", "Music Server", 4, "med-orange-ring", "house-audio", ""));
    c.ap(new Pc("audio-sat", "Satellite Radio for the Home", 5, "sat-audio", "satellite-home", ""));
  pg.ac(c);
  c = new Cc("outdooraudio", "Outdoor Audio", 2, "outdoor-speaker");
    c.ap(new Pc("outdooraudio-silver", "Silver Outdoor Audio", 1, "med-silver", "outdoor-speaker", "outdooraudio-gold"));
    c.ap(new Pc("outdooraudio-gold", "Gold Outdoor Audio", 2, "med-gold", "outdoor-speaker", "outdooraudio-silver"));
    c.ap(new Pc("outdooraudio-rock", "\'Rock\' Garden (Outdoor Audio)", 3, "med-marble", "outdoor-speaker", ""));
  pg.ac(c);
  c = new Cc("lighting", "Lighting Control", 3, "lighting");
    c.ap(new Pc("lighting-oneroom", "Single Room Lighting Control", 1, "med-yellow-ring", "lighting", ""));
    c.ap(new Pc("lighting-house", "Whole House Lighting Control", 2, "med-yellow-ring", "lighting-house", ""));
  pg.ac(c);
packageManager.addPage(pg);
pg = new PGc("games", "Games &amp; Entertainment", 4);
  c = new Cc("videogames", "Video Game Centers", 1, "games-video");
    c.ap(new Pc("vgame-outlet", "Video Game Outlet Add-On", 1, "med-white", "games-video", ""));
    c.ap(new Pc("vgame-basic", "Basic Video Game Center", 2, "med-silver", "games-video", "vgame-hdtv"));
    c.ap(new Pc("vgame-hdtv", "Hi-Def Video Game Center", 3, "med-gold", "games-video", "vgame-basic"));
  pg.ac(c);
  c = new Cc("golf", "Indoor Golf Simulator", 2, "games-golf");
    c.ap(new Pc("golf-sim", "Indoor Golf Simulator", 1, "med-white", "games-golf", "golf-complete"));
    c.ap(new Pc("golf-complete", "Complete Golf Simulator", 2, "med-green", "games-golf", "golf-sim"));
  pg.ac(c);
  c = new Cc("arcade", "Home Arcade", 3, "games-arcade");
    c.ap(new Pc("arcade-game", "Arcade Game", 1, "med-gray", "games-arcade", ""));
    c.ap(new Pc("pinball-machine", "Pinball Machine", 2, "med-gray", "games-pinball", ""));
  pg.ac(c);
packageManager.addPage(pg);
pg = new PGc("communication", "Communication", 5);
  c = new Cc("phones", "Phone Systems", 1, "phone");
    c.ap(new Pc("phones-basic", "Basic Phone Management", 1, "", "phone", "phones-silver,phones-gold,phones-diamond"));
    c.ap(new Pc("phones-gold", "Gold Phone System", 2, "med-gold", "phone", "phones-silver,phones-basic,phones-diamond"));
    c.ap(new Pc("phones-diamond", "Business/Home Office Phone System", 3, "med-diamond", "phone", "phones-silver,phones-gold,phones-basic"));
    c.ap(new Pc("phones-fax", "Dedicated Fax Line", 4, "pc-sec", "phone", ""));
  pg.ac(c);
  c = new Cc("pcnetworking", "Computer Networking", 2, "pc-network");
    c.ap(new Pc("pcnetworking-basic", "Basic PC Networking", 1, "", "pc-network", ""));
    c.ap(new Pc("pcnetworking-wireless", "Wireless PC Networking", 2, "", "pc-wireless", ""));
  pg.ac(c);
  c = new Cc("intercom", "Intercom", 3, "intercom");
    c.ap(new Pc("intercom", "Basic Intercom", 1, "", "intercom", ""));
    c.ap(new Pc("intercom-phone", "Phone Based Intercom", 2, "", "intercom", ""));
  pg.ac(c);
packageManager.addPage(pg);
pg = new PGc("management", "Home Management", 6);
  c = new Cc("customconsult", "Custom Consulting", 1, "plans");
    c.ap(new Pc("customconsult-package", "Custom Consulting", 1, "", "plans", ""));
  pg.ac(c);
  c = new Cc("homeauto", "Home Automation (Smart Home)", 2, "home-auto");
    c.ap(new Pc("homeauto-basic", "Basic Home Automation", 1, "", "home-auto", ""));
  pg.ac(c);
  c = new Cc("thermostat", "Temperature Control", 3, "thermostat");
    c.ap(new Pc("thermostat", "Temperature Control", 1, "", "thermostat", ""));
  pg.ac(c);
packageManager.addPage(pg);
// Removes all references to avoid memory errors later.
function cleanUpPackageTree() {
    for(var pgi = 0; pgi < packageManager.pages.length; pgi++) {
        var pg = packageManager.pages[pgi];
        for(var ci=0; ci < pg.categories.length; ci++) {
            var c = pg.categories[ci];
            for(var pi = 0; pi < c.packages.length; pi++) {
                var p = c.packages[pi];
                p.category = null;
            }
            c.packages.length = 0;
            c.page = null;
        }
        pg.categories.length = 0;
        pg.packages = null;
    }
    packageManager.pages.length = 0;
    packageManager.categories = null;
    packageManager.packages = null;
}
// Setup (calls initialize on page loading)
if(window && Listener) {
    // add as a higher-than-default priority method.
    Listener.add(window, "onunload", cleanUpPackageTree, this, 1, 1);
}