$(document).ready(function() {

    function imageBlock(imageName, href, mapName, map, target) {
        this.imageName = imageName;
        this.href = href;
        this.mapName = mapName;
        this.map = map;
        this.target = target;
    }

    var imageLocation = "images/";

    var smallImagePool = new Array();
    var mediumImagePool = new Array();
    var largeImagePool = new Array();

    ///////////////////////////////////////Setup image pools//////////////////////////////////////////

    //Setup image Pools
    mediumImagePool.push(new imageBlock("bottom_panel_01.jpg", "michelle_galletti.html", null, null, null));
    mediumImagePool.push(new imageBlock("bottom_panel_01_gold_coast.jpg", "http://my.console.com.au/myConsolesignin/tabid/975/Default.aspx?returnurl=%2fmyConsole%2fSupport%2fCreateSupportCase%2ftabid%2f985%2fDefault.aspx", null, null, "_blank"));

    //Setup map html
    var gatewayTourMap = "<map name=\"gatewaytour\">";
    gatewayTourMap += "<area shape=\"rect\" href=\"sales_overview.html\" coords=\"53,60,254,88\">";
    gatewayTourMap += "<area shape=\"rect\" href=\"pm_overview.html\" coords=\"54,90,269,118\">";
    gatewayTourMap += "</map>";

    largeImagePool.push(new imageBlock("gateway_tour.jpg", null, "gatewaytour", gatewayTourMap, null));

    //Setup image pool for the very right image (smallImagePool)
    //This is always the right most image and its location is fixed.
    smallImagePool.push(new imageBlock("bottom_panel_04.jpg", "whats_new.html", null, null, null));

    /////////////////////////////////////////////////////////////////////////////////////////////////

    //Randomly pick 1 from each image pool

    var indexA = Math.floor(Math.random() * mediumImagePool.length);
    var indexB = Math.floor(Math.random() * largeImagePool.length);
    var indexC = Math.floor(Math.random() * smallImagePool.length);

    //Retrieve images from the iamge pools
    var imageBlock_A = imageBlock_B = imageBlock_C = null;

    imageBlock_A = mediumImagePool[indexA];
    imageBlock_B = largeImagePool[indexB];
    imageBlock_C = smallImagePool[indexC];

    function convertToHtml(imageBlockObj) {
        var imageHTML = "";

        var targetAttr = (imageBlockObj.target != null) ? " target =\"" + imageBlockObj.target + "\"" : "";

        if (imageBlockObj.mapName == null) {
            imageHTML = "<img src=\"" + imageLocation + imageBlockObj.imageName + "\">";
            imageHTML = (imageBlockObj.href != null) ? "<a href=\"" + imageBlockObj.href + "\"" + targetAttr + ">" + imageHTML + "</a>" : imageHTML;
        }
        else {
            imageHTML = "<img src=\"" + imageLocation + imageBlockObj.imageName + "\" usemap=\"#" + imageBlockObj.mapName + "\">";
            imageHTML += imageBlockObj.map;
        }

        return imageHTML;
    }

    var imageA = imageB = imageC = "";

    imageA = convertToHtml(imageBlock_A);
    imageB = convertToHtml(imageBlock_B);
    imageC = convertToHtml(imageBlock_C);

    //Seed to randomise the order imageA and imageB
    var toggleImage = Math.floor(Math.random() * 2);

    //Assign images to the divs
    if (toggleImage == 1) {
        $('#randomAdBoxA').append(imageA);
        $('#randomAdBoxB').append(imageB);
    }
    else {
        $('#randomAdBoxA').append(imageB);
        $('#randomAdBoxB').append(imageA);
    }

    $('#randomAdBoxC').append(imageC);
}); 
                        
                 
