defaultStatusBarMessage = "";

function setDefaultStatusBarMessage(message) { defaultStatusBarMessage = message;}
function initializeStatusBar() { defaultStatus=defaultStatusBarMessage; }
function resetStatusBar() { window.status=defaultStatusBarMessage; }

function doBigImage(paintingObj, galleryName)
{

    var queryString =   "?" + 
                        "imageSrc=" + escape(paintingObj.img.src) + "&" +
                        "title=" + escape(paintingObj.title) + "&" +
                        "medium=" + escape(paintingObj.medium) + "&" +
                        "sizeStr=" + escape(paintingObj.sizeStr) + "&" +
                        "galleryName=" + escape(galleryName);
    
    window.location =   "bigImage.html" + queryString;

    return
}

function doBigImage_noMedium(paintingObj, galleryName)
{

    var queryString =   "?" + 
                        "imageSrc=" + escape(paintingObj.img.src) + "&" +
                        "title=" + escape(paintingObj.title) + "&" +
                        "sizeStr=" + escape(paintingObj.sizeStr) + "&" +
                        "galleryName=" + escape(galleryName);
    
    window.location =   "bigImage_noMedium.html" + queryString;

    return
}

function doGalleryTr1(i1)
{
/*
    Do a row with one image, i1 is the index of the painting object within the paintings array.
*/
    document.write(
            "<tr>" + 
                "<td align=\"center\">" + 
                    "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
                    "<tr>" + 
                      "<td>" + 
                        "<!-- IMAGE TABLE -->" +
                        "<table width=\"130\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
                          "<tr>" + 
                            "<td class=\"thumbnailCell\" align=\"center\" valign=\"bottom\"><a href=\"javascript:doBigImage(paintings[" + i1 + "],galleryName)\"><img src=\"" + paintings[i1].thumb.src + "\" border=\"0\"></a></td>" +
                          "</tr>" +
                          "<tr>" + 
                            "<td height=\"10\"><font class=\"thumbText\">&nbsp;</font></td>" +
                          "</tr>" +
                          "<tr>" + 
                            "<td align=\"center\" nowrap><font class=\"thumbText\"><i>" + paintings[i1].title + "</i></font></td>" +
                          "</tr>");
                          
    if(paintings[i1].medium != -1)  
        document.write(
                          "<tr>" +
                            "<td align=\"center\" nowrap><font class=\"thumbText\">" + paintings[i1].medium + "</font></td>" +
                          "</tr>");
                          
    document.write(
                          "<tr>" + 
                            "<td align=\"center\" nowrap><img alt=\"sold\" src=\"images/reddot_placeholder.gif\">" + 
                              "<font class=\"thumbText\">" + paintings[i1].sizeStr + "</font> <img alt=\"sold\" src=\"images/reddot_placeholder.gif\"></td>" +
                          "</tr>" +
                        "</table>" + 
                      "</td>" +
                    "</tr>" +
                    "</table>" +
                "</td>" +
            "</tr>" +
            "<tr>" + 
                "<td height=\"50\"><img src=\"images/spacer.gif\" height=\"1\" width=\"1\"></td>" +
            "</tr>"     
    );
}

function doGalleryTr2(i1, i2)
{
/*
    Do a row of 2 images
    i1 and i2 are the indices of the painting objects within the paintings array.
*/
    document.write(
            "<tr>" + 
                "<td align=\"center\">" + 
                    "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
                    "<tr>" + 
                      "<td valign=\"top\">" + 
                        "<!-- IMAGE TABLE -->" +
                        "<table width=\"130\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
                          "<tr>" + 
                            "<td class=\"thumbnailCell\" align=\"center\" valign=\"bottom\"><a href=\"javascript:doBigImage(paintings[" + i1 + "],galleryName)\"><img src=\"" + paintings[i1].thumb.src + "\" border=\"0\"></a></td>" +
                          "</tr>" +
                          "<tr>" + 
                            "<td height=\"10\"><font class=\"thumbText\">&nbsp;</font></td>" +
                          "</tr>" +
                          "<tr>" + 
                            "<td align=\"center\" nowrap><font class=\"thumbText\"><i>" + paintings[i1].title + "</i></font></td>" +
                          "</tr>");
                          
    if(paintings[i1].medium != -1)
        document.write(   "<tr>" + 
                            "<td align=\"center\" nowrap><font class=\"thumbText\">" + paintings[i1].medium + "</font></td>" +
                          "</tr>");
                          
    document.write(       "<tr>" + 
                            "<td align=\"center\" nowrap><img alt=\"sold\" src=\"images/reddot_placeholder.gif\">" + 
                              "<font class=\"thumbText\">" + paintings[i1].sizeStr + "</font> <img alt=\"sold\" src=\"images/reddot_placeholder.gif\"></td>" +
                          "</tr>" +
                        "</table>" + 
                      "</td>" +
                      "<td width=\"30\"><img src=\"images/spacer.gif\" height=\"1\" width=\"1\"></td>" +
                      "<td valign=\"top\">" + 
                        "<!-- IMAGE TABLE -->" +
                        "<table width=\"130\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
                          "<tr>" + 
                            "<td class=\"thumbnailCell\" align=\"center\" valign=\"bottom\"><a href=\"javascript:doBigImage(paintings[" + i2 + "],galleryName)\"><img src=\"" + paintings[i2].thumb.src + "\" border=\"0\"></a></td>" +
                          "</tr>" +
                          "<tr>" + 
                            "<td height=\"10\"><font class=\"thumbText\">&nbsp;</font></td>" +
                          "</tr>" +
                          "<tr>" + 
                            "<td align=\"center\" nowrap><font class=\"thumbText\"><i>" + paintings[i2].title + "</i></font></td>" +
                          "</tr>");
                          
    if(paintings[i2].medium != -1)
        document.write(   "<tr>" + 
                            "<td align=\"center\" nowrap><font class=\"thumbText\">" + paintings[i2].medium + "</font></td>" +
                          "</tr>");
                          
    document.write(       "<tr>" + 
                            "<td align=\"center\" nowrap><img alt=\"sold\" src=\"images/reddot_placeholder.gif\">" + 
                              "<font class=\"thumbText\">" + paintings[i2].sizeStr + "</font><img alt=\"sold\" src=\"images/reddot_placeholder.gif\"></td>" +
                          "</tr>" +
                        "</table></td>" +
                    "</tr>" +
                  "</table>" +
                "</td>" + 
            "</tr>" +
            "<tr>" + 
                "<td height=\"50\"><img src=\"images/spacer.gif\" height=\"1\" width=\"1\"></td>" +
            "</tr>"
    );
}

function beginGalleryTable(titleImgSrc)
{
    titleImg = new Image();
    titleImg.src=titleImgSrc;
    
    // Begin the table
    document.write(
        "<table width=\"650\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
        "<!-- ACCOUNT FOR THE DIFFERENCE IN HEIGHT FROM THE HOME PAGE GRAPHIC -->" +
        "<tr><td><img src=\"images/spacer.gif\" height=\"27\"></td></tr>" +
        "<tr>" + 
            "<td align=\"center\"><img src=\"" + titleImg.src + "\" alt=\"" + titleImg.src + "\"></td>" +
        "</tr>" +
        "<tr>" + 
            "<td width=\"100%\"><hr noshade width=\"100%\"></td>" +
        "</tr>" +
        "<tr><td height=\"25\"><img src=\"images/spacer.gif\"></td></tr>" +
        "<tr>" + 
            "<td align=\"center\">" +
                "<table align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">" +
                "<tr>" + 
                  "<td><hr noshade width=\"25\"></td>" +
                  "<td><font class=\"thumbnailDirections\">Click thumbnail to enlarge image</font></td>" +
                  "<td><hr noshade width=\"25\"></td>" +
                "</tr>" +
              "</table>" +
            "</td>" +
        "</tr>" +
        "<tr><td height=\"50\"><img src=\"images/spacer.gif\" height=\"1\" width=\"1\"></td></tr>"
        );
}

function endGalleryTable()
{
    document.write(
      "<tr>" + 
        "<td align=\"right\" nowrap>" + 
          "<!-- <img src=\"reddot.gif\"> <font class=\"redDotKey\">Indicates that the item has been sold</font> -->" +
        "</td>" +
      "</tr>" +
      "<tr>" + 
        "<td height=\"10\">&nbsp;</td>" +
      "</tr>" +
      "<tr>" + 
        "<td width=\"100%\"><hr noshade width=\"100%\"></td>" +
      "</tr>" +
      "<tr>" + 
        "<td align=\"center\" width=\"100%\">" + 
            "<table width=\"650\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
            "<!-- LINKS -->" +
            "<tr>" + 
              "<td align=\"center\" nowrap><a href=\"index.html\" onmouseover=\"window.status='R e t u r n   t o   t h e   h o m e   p a g e'; return true;\" onmouseout=\"resetStatusBar();\">Home</a></td>" +
              "<td align=\"center\" nowrap><font class=\"pipe\">&nbsp;|&nbsp;</font></td>" +
              "<td align=\"center\" nowrap><a href=\"artwork.html\">Artwork</a></td>" +
              "<td align=\"center\" nowrap><font class=\"pipe\">&nbsp;|&nbsp;</font></td>" +
              "<td align=\"center\" nowrap><a href=\"exhibitions.html\" onmouseover=\"window.status='E x h i b i t i o n s   a n d   G a l l e r i e s'; return true;\" onmouseout=\"resetStatusBar();\">Exhibitions and Galleries</a></td>" +
              "<td align=\"center\" nowrap><font class=\"pipe\">&nbsp;|&nbsp;</font></td>" +
              "<td align=\"center\" nowrap><a href=\"about.html\" onmouseover=\"window.status='R e a d   A b o u t   T h e   A r t i s t'; return true;\" onmouseout=\"resetStatusBar();\">About The Artist</a></td>" +
              "<td align=\"center\" nowrap><font class=\"pipe\">&nbsp;|&nbsp;</font></td>" +
              "<td align=\"center\" nowrap><a href=\"guestbook.html\" onmouseover=\"window.status='S i g n   T h e   G u e s t   B o o k'; return true;\" onmouseout=\"resetStatusBar();\">Guest Book</a></td>" +
              "<td align=\"center\" nowrap><font class=\"pipe\">&nbsp;|&nbsp;</font></td>" +
              "<td align=\"center\" nowrap><a href=\"contact.html\" onmouseover=\"window.status='T o   C o n t a c t   U s . . .'; return true;\" onmouseout=\"resetStatusBar();\">Contact Us</a></td>" +
            "</tr>" +
          "</table></td>" +
      "</tr>" +
    "</table>"
    );
}

function doGalleryTable(titleImgSrc)
{
    beginGalleryTable(titleImgSrc);
    
    // Do all the images.
    for(var i = 0; i < paintings.length; i += 2) // Print two images per row
    {
        if ( i == paintings.length - 1 )
        {
            // Last image, there is an odd # of images, 
            // print 1 image instead of 2.
            doGalleryTr1(i);
        }
        else
        {
            // There are at least 2 more images for us to print,
            // so do a row of 2 images.
            doGalleryTr2(i, i + 1);
        }
    }
    
    endGalleryTable();
}

function getParam(param)
{
    /*
        Action: 
            Parses the query string for a string that 
            resembles "param=value".
            
        Post-condition:
            Returns the value of a given parameter in the 
            query string.
    */
    
    var queryString = location.search.substring(1);
    var startPos = queryString.indexOf(param);
    var endPos;
    var value = "";
    
    if (startPos > -1)
    {
        // Account for no "&" after param=value
        if (queryString.indexOf("&", startPos) > -1)
            endPos = queryString.indexOf("&", startPos);
        else
            endPos = queryString.length;
    
        // Get the param=value string
        var keyValPair = queryString.substring(startPos, endPos);
        
        // split into separate param and value
        var arr = keyValPair.split("=");
        
        value = arr[1];
    }
    
    return value;
}
function Painting(thumbSrc,imgSrc,title,mediumType,sizeStr)
{   
    this.mediumTypes = new Array;
    this.mediumTypes[0] = "Oil on Canvas";
    this.mediumTypes[1] = "Oil on Paper";
    this.mediumTypes[2] = "Oil on Sealed Board";
    this.mediumTypes[3] = "Acrylic on Canvas";
    this.mediumTypes[4] = "Acrylic and Oil on Canvas";
    this.mediumTypes[5] = "Oil and Sand on Paper";
    
    this.img = new Image();
    this.img.src = imgSrc;
    
    this.thumb = new Image();
    this.thumb.src = thumbSrc;
    
    this.title = title;
    
    if (mediumType != -1)
        this.medium = this.mediumTypes[mediumType];
    else
        this.medium = -1;
    
    this.sizeStr = sizeStr;
}
