//requestVars start

/*
 * Greatly extended by Narasinga Rao <narasinga.rao@gmail.com>
 * @copyright   2010-01-01

 * @author      Jesse Berman
 * @copyright   2008-01-31
 * @version     1.0
 * @license     http://www.gnu.org/copyleft/lesser.html
 */


/*
 * Portions by Dieter Raber <dieter@dieterraber.net>
 * copyright   2004-12-27
 */


/* pwa.js: a drop-in JavaScript utility that displays galleries from picasaweb.google.com in your website */

/* NOTE: This version hides all the link-backs to Picasa */

/* This JavaScript file, when called from a webpage, will load all the thumbnail images of all the galleries
   in a user's Picasa Web Albums account into an HTML table that's 4 rows wide.  Clicking on any of the
   galleries will display thumbnails of all the photos in that gallery, and clicking on any of those thumbnails
   will display the photo.  

   To call this file from your own webpage, use the following syntax:

   <!--script type="text/javascript">username='."'".'YourPicasawebUsername'."'".'; photosize='."'".'800'."'".'; columns='."'".'4'."'".';</script-->
   <!--script type="text/javascript" src="http://www.yoursite.com/pwa.js"></script-->

   Make sure you change YourPicasawebUsername to your actual Picasaweb username.  For more information about
   Picasa, check out picasaweb.google.com.  Also, www.yoursite.com should point to your actual site name, and
   the location of the pwa.js file.  The script looks for the images back.jpg, next.jpg, and home.jpg, in the
   same directory as pwa.js, to create the navigation arrows.  Please make sure those exist!  I'm providing
   samples in the SourceForce repository, but feel free to substitute your own.

Note: "Photosize" is the size of the image to be displayed when viewing single images.  I like 800.  :-)
Note: "columns" is the number of columns of photos to be displayed on your site in the gallery and album views.
You may omit either of these values; if you do, the default settings are 800 for photosize and 4 for columns.

 */
var nextDefinitionNo = 1;
var reloadFullPage = 1;
var reloadSinglePhotoFullPage=0;
function getBorderTableLink(dataLink)
{
    $("<table border='0' cellpadding='0' cellspacing='0' style='margin:0px 0px;padding:0;'><tr><td style='background-color:#AAAAAA; background-image:url(pub/boxes/cedar-1.gif);'>");
    $("              <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>");
    $("                     <td style='margin:0;padding:0;background-image: url(pub/boxes/blackline.gif);height:14px;' valign='top'><img src='pub/boxes/ctl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''><img src='pub/boxes/ctr1-ffffff.gif'   hspace='0' vspace='0' align='right' width='15' height='14' alt=''></td>");
    $("               </tr></table>");
    $("               <table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>");
    $("                           <td width='100%' style='background-color:#FFffff; font-size:140%; color:#000000; font-weight:bold; font-family:Verdana, Arial, Helvetica, sans-serif; border:2px #000000 solid;'>"+dataLink+"</td>");
    $("               </tr></table>");
    $("               <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>");
    $("                       <td style='padding:0;margin:0;background-image: url(pub/boxes/botline.gif);height:14px;' valign='top'><img src='pub/boxes/cbl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''><img src='pub/boxes/cbr1-ffffff.gif'  hspace='0' vspace='0' align='right' width='15' height='14' alt='' border='0'></td>");
    $("   </tr></table></td></tr></table>");
}

function getAlbumTableLink(width,tableContent,caption)
{
    html ="";
    html += "<table border='0' cellpadding='0' cellspacing='0' style='margin:0px 0px;padding:0;'><tr><td style='background-color:#AAAAAA; background-image:url(pub/boxes/cedar-1.gif);'>";
    html += "              <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>";
    html += "                     <td style='margin:0;padding:0;background-image: url(pub/boxes/blackline.gif);height:14px;' valign='top'><img src='pub/boxes/s1-ctl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''><img src='pub/boxes/s1-ctr1-ffffff.gif'   hspace='0' vspace='0' align='right' width='15' height='14' alt=''></td>";
    html += "               </tr></table>";
    html += "               <table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>";
    html += "                           <td width='100%' style='background-color:#FFffff; font-size:140%; color:#000000; font-weight:bold; font-family:Verdana, Arial, Helvetica, sans-serif; border:2px #000000 solid;'>"+tableContent+"</td>";
    html += "               </tr></table>";
    html += "               <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>";
    html += "                       <td style='padding:0;margin:0;background-image: url(pub/boxes/2-lines.gif);height:14px;' valign='bottom'><img src='pub/boxes/s1-cbl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''><img src='pub/boxes/s1-cbr1-ffffff.gif'  hspace='0' vspace='0' align='right' width='15' height='14' alt='' border='0'></td>";
    html += "   </tr></table></td></tr></table>";
    return html;
}
function getImageTableLink(width,imageLink,caption)
{
    $("<table border='0' cellpadding='0' cellspacing='0' style='margin:0px 0px;padding:0;'><tr><td style='background-color:#AAAAAA; background-image:url(pub/boxes/cedar-1.gif);'>");
    $("              <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>");
    $("                     <td style='margin:0;padding:0;background-image: url(pub/boxes/blackline.gif);height:14px;' valign='top'><img src='pub/boxes/ctl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''><img src='pub/boxes/ctr1-ffffff.gif'   hspace='0' vspace='0' align='right' width='15' height='14' alt=''></td>");
    $("               </tr></table>");
    $("               <table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>");
    $("                           <td width='100%' style='background-color:#FFffff; font-size:140%; color:#000000; font-weight:bold; font-family:Verdana, Arial, Helvetica, sans-serif; border:2px #000000 solid;'><img src='"+imageLink+"' width='"+width+"'></td>");
    $("               </tr></table>");
    $("               <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>");
    $("                       <td style='padding:0;margin:0;background-image: url(pub/boxes/botline.gif);height:14px;' valign='top'><img src='pub/boxes/cbl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''><img src='pub/boxes/cbr1-ffffff.gif'  hspace='0' vspace='0' align='right' width='15' height='14' alt='' border='0'></td>");
    $("   </tr></table></td></tr></table>");
}
function readGet(){var _GET = new Array();var uriStr  = window.location.href.replace(/&amp;/g, '&');var paraArr, paraSplit;if(uriStr.indexOf('?') > -1){var uriArr  = uriStr.split('?');var paraStr = uriArr[1];}else{return _GET;}if(paraStr.indexOf('&') > -1){paraArr = paraStr.split('&');}else{paraArr = new Array(paraStr);}for(var i = 0; i < paraArr.length; i++){paraArr[i] = paraArr[i].indexOf('=') > -1 ? paraArr[i] : paraArr[i] + '=';paraSplit  = paraArr[i].split('=');_GET[paraSplit[0]] = decodeURI(paraSplit[1].replace(/\+/g, ' '));}return _GET;}var _GET = readGet();
//requestVars end

function resize(which, max) {
    // not used anymore! was scaling photos after they were loaded. using browser-native inline scaling instead,
    // until google fixes their image size request to work with any imgmax, rather than just 800 :-(
    var elem = document.getElementById(which);
    if (elem == undefined || elem == null) return false;
    if (max == undefined) max = 658;
    if (elem.width > elem.height) {
        if (elem.width > max) elem.width = max;
    } else {
        if (elem.height > max) elem.height = max;
    }
}

//$Update: May 10, 2007$

function $(a){document.write(a);}
var photosize;
if(!photosize){photosize = 800;}

var columns;
if(!columns || isNaN(columns) || columns < 1) {columns = 4;}


//Global variables
var photolist = new Array(); //this is used globally to store the entire list of photos in a given album, rather than pass the list around in a URL (which was getting rediculously long as a result)
var presentShowPhoto = "-1";
var album_name = ""; //this is used globally to store the album name, so we don't have to pass it around in the URL anymore either.
var my_numpics = ""; //this is used globally to store the number of items in a particular album, so we don't have to pass it around in the URL anymore either.
var prev = ""; //used in the navigation arrows when viewing a single item
var next = "";//used in the navigation arrows when viewing a single item
function AlbumPhotos( nValue, username, albumName, authkey, iconBase, albumTitle, alink )
{
    this.nValue = nValue;
    this.username = username;
    this.albumname = albumName;
    this.authkey = authkey;
    this.iconBase = iconBase;
    this.albumTitle = albumTitle;
    this.alink = alink;
}
function picasaalbumwebCore(j, groupAlbumId, alink )
{ //returns the list of all albums for the user


    // for each of the albums in the feed, grab its album cover thumbnail and the link to that album,
    // then display them in a table with 4 columns (along with the album title)

    //This was the old way of grabbing the photos; since Google updated the feed, the media entry is better. :-)
    //
    //var img_begin = j.feed.entry[i].summary.$t.indexOf('src="')+5;
    //var img_end = j.feed.entry[i].summary.$t.indexOf('?imgmax');
    //var img_base = j.feed.entry[i].summary.$t.slice(img_begin, img_end);
    var img_base = j.feed.entry[0].media$group.media$content[0].url;
    var anotherLink = j.feed.link[1].href;
    var iconBase = j.feed.icon.$t;
    var albumName = anotherLink.replace ( /.*\//g, "" );
    albumName = albumName.replace( /\?.*/g, "" );
    var albumTitle = j.feed.title.$t;
    var albumLink = j.feed.link[0].href;
    var newAlbumLink = albumLink.replace( "alt=json&", "" );
    albumLink = newAlbumLink.replace( "alt=json", "" );
    var albumid = albumLink.replace( /.*albumid\//g, "" );
    albumid = albumid.replace( /\/.*/g, "" );
    var authkey = "";
    if( albumid.match( "authkey" ) ) {
        authkey = albumid.replace( /.*authkey\=/, "" );
        authkey = "&authkey="+authkey;
    }
    albumid = albumid.replace( /\?.*/g, "" );
    var username = albumLink.replace( /.*user\//g, "" );
    username = username.replace( /\/.*/g, "" );
    var nValue = "";
    if( _GET['n'] ) {
        nValue = "n="+getValue('n')+"&";
    }
    if( groupAlbumId != "" ) {
        groupAlbumId += "&groupAlbumId="+groupAlbumId;
    }
    return new AlbumPhotos( nValue, username, albumName, authkey, iconBase, albumTitle, alink );
}
function picasaalbumweb( j )
{
    var albPhotos = picasaalbumwebCore( j, "", "" );
    showAlbumThumbSize( '', '', albPhotos, 160, "albumsFun", '' );
}
function showAlbumThumbSize( globalUniqueKey, uniqueKey, albPhotos, imgmax, eachAlbumCallBackFunction, name )
{
    var imgLink = albPhotos.iconBase+"?imgmax="+imgmax+"&crop=1";
    var aHref = "?"+albPhotos.nValue+"child=1&username="+albPhotos.username+"&album="+albPhotos.albumname+albPhotos.authkey+"&albumCallBackFn="+eachAlbumCallBackFunction+albPhotos.alink;
    if( reloadFullPage == 0 ) {
        aHref = "javascript:"+eachAlbumCallBackFunction+"NoArg()";
    }
    var hrefLink = "<a class='standard' href='"+aHref+"'><img src='"+imgLink+"' class='pwimages' /></a>";
    var htmlCore = getAlbumTableLink(imgLink,hrefLink,"");
    var title=name;
    if ( title == "" ) {
        title=albPhotos.albumTitle;
    }
    htmlCore += "<center><a class='standard' href='"+aHref+"'>"+title+"</a></center>";
    //alert( htmlCore );
    if( uniqueKey == "" ) { 
        document.write(htmlCore);
    }
    else {
        //alert( "UniqueKey Dest= "+uniqueKey);
        var cell = document.getElementById(uniqueKey);
        if( cell == null ) {
            document.write(htmlCore);
        }
        else {
            removeAllChilds( cell );
            cell.innerHTML = htmlCore;
        }
    }
    //$("<b>***"+albPhotos.albumname+"***</b>");
    //    alert(html);
}

function picasaweb(j)
{
    //returns the list of all albums for the user
    $("<div style='margin-left:3px'>Gallery Home</div><!--div style='text-align:right; margin-right:5px; margin-top:-14px'><a target=PICASA class='standard' href='http://picasaweb.google.com/"+username+"/'>View this gallery in Picasa</a></div--><br/>");
    $("<table border=0><tr>");

    for(i=0;i<j.feed.entry.length;i++){

        // for each of the albums in the feed, grab its album cover thumbnail and the link to that album,
        // then display them in a table with 4 columns (along with the album title)

        //This was the old way of grabbing the photos; since Google updated the feed, the media entry is better. :-)
        //
        //var img_begin = j.feed.entry[i].summary.$t.indexOf('src="')+5;
        //var img_end = j.feed.entry[i].summary.$t.indexOf('?imgmax');
        //var img_base = j.feed.entry[i].summary.$t.slice(img_begin, img_end);

        var img_base = j.feed.entry[i].media$group.media$content[0].url;

        var id_begin = j.feed.entry[i].id.$t.indexOf('album/')+8;
        //var id_begin = j.feed.entry[i].id.$t.indexOf('albumid/')+8;
        var id_end = j.feed.entry[i].id.$t.indexOf('?');
        var id_base = j.feed.entry[i].id.$t.slice(id_begin, id_end);

        $("<td valign=top><a class='standard' href='?album="+id_base+"'><img src='"+img_base+"?imgmax=160&crop=1' class='pwimages' /></a>");
        $("<br/><table border=0><tr><td></td></tr></table><center><a class='standard' href='?album="+id_base+"'>"+ j.feed.entry[i].title.$t +"</a></center></td>");
        if (i % columns == columns-1) {
            $("</tr><tr><td><br/></td></tr> <tr><td></td></tr> <tr>");
        }
    }
    $("</tr></table>");

}


function getphotolist( j )
{
    // This function is called just before displaying an item; it returns info about the item's current state within its parent
    // album, such as the name of the album it's in, the index of the photo in that album, and the IDs of the previous and next
    // photos in that album (so we can link to them using navigation arrows).  This way we don't have to pass state information
    // around in the URL, which was resulting in hellishly long URLs (sometimes causing "URI too long" errors on some servers).

    // Get the number of pictures in the album.  Added 7/18/2007.
    my_numpics = j.feed.openSearch$totalResults.$t;

    // Also get the name of the album, so we don't have to pass that around either.  Added 7/18/2007.
    album_name = j.feed.title.$t;

    for(i=0;i<j.feed.entry.length;i++){
        // get the list of all photos referenced in the album and display;
        // also stored in an array (photoids) for navigation in the photo view (passed via the URL)
        var id_begin = j.feed.entry[i].id.$t.indexOf('photoid/')+8;
        var id_end = j.feed.entry[i].id.$t.indexOf('?');
        var id_base = j.feed.entry[i].id.$t.slice(id_begin, id_end);
        photolist[i]=id_base;

        // now get previous and next photos relative to the photo we're currently viewing
        if (i>0)
        {
            var prev_begin = j.feed.entry[i-1].id.$t.indexOf('photoid/')+8;
            var prev_end = j.feed.entry[i-1].id.$t.indexOf('?');
            prev = j.feed.entry[i-1].id.$t.slice(id_begin, id_end);
        }
        if (i<j.feed.entry.length-1)
        {
            var next_begin = j.feed.entry[i+1].id.$t.indexOf('photoid/')+8;
            var next_end = j.feed.entry[i+1].id.$t.indexOf('?');
            next = j.feed.entry[i+1].id.$t.slice(id_begin, id_end);
        }

    }
}


function albumsFun( j )
{
    albumsFunShowCore( '', j, 160, 4, "false", "", "", -1, 0, 0, 0, 0, "", "", 1 );
}
function getValue( attr )
{
    var value = _GET[attr];
    value = value.replace( /#.*/g, "" );
    return value;
}
function albumsFunShow( j )
{
    albumsFunShowCore( '', j, 160, 4, "false", "", "", -1, 0, 0, 0, 0, "", "", 0 );
}
function albumsFunShowCoreNoArg( globalUniqueKey, username, album, authkey, tag, callBackFn)
{
    var authkeyTag = "";
    if( authkey != "" ) {
        authkeyTag = "authkey="+ getValue('authkey')+'&';
    }        
    var tagTag = "";
    if( tag != "" ) {
        tagTag = "tag="+tag+'&';
    }
    html = '<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+album+'?'+authkeyTag+tagTag+'category=photo&alt=json&callback='+callBackFn+'"></script>';//albums
    $(html);
}
function albumsFunShowCore( globalUniqueKey, j, imgmax, columns, downloadable, alink, targetLink, maxPhotos, randomFlag, noHeaderLinks, borders, imgThumbWidth, albumCallBackFn, photoCallBackFn, galleryLinkFlag )
{
    //get the number of photos in the album
    var np = j.feed.openSearch$totalResults.$t;
    var item_plural = "s";
    if (np == "1") { item_plural = ""; }

    var album_begin = j.feed.entry[0].summary.$t.indexOf('href="')+6;
    var album_end = j.feed.entry[0].summary.$t.indexOf('/photo#');
    var album_link = j.feed.entry[0].summary.$t.slice(album_begin, album_end);
    var photoids = new Array();

    var nValue = "";
    var nValueSingle = "";
    if( _GET['n'] ) {
        nValueSingle = "n="+getValue('n');
        nValue = nValueSingle + "&";
    }
    var htmlOut = "";
    //htmlOut += "<div style='margin-left:3px'> @ "+ j.feed.title.$t +"&nbsp;&nbsp;["+np+" item"+item_plural+"]</div><!--div style='text-align:right; margin-right:5px; margin-top:-14px'><a target=PICASA class='standard' href='"+album_link+"'>View this album in Picasa</a></div--><br/>";

    ///////////////////////////////////////////////////////////////////
    var img_base = j.feed.entry[0].media$group.media$content[0].url;
    var anotherLink = j.feed.link[1].href;
    var iconBase = j.feed.icon.$t;
    var albumName = anotherLink.replace ( /.*\//g, "" );
    albumName = albumName.replace( /\?.*/g, "" );
    var albumTitle = j.feed.title.$t;
    var albumLink = j.feed.link[0].href;
    var newAlbumLink = albumLink.replace( "alt=json&", "" );
    albumLink = newAlbumLink.replace( "alt=json", "" );
    var albumid = albumLink.replace( /.*albumid\//g, "" );
    albumid = albumid.replace( /\/.*/g, "" );
    var authkey = "";
    var authkeyalbum = "";
    if( albumid.match( "authkey" ) ) {
        authkey = albumid.replace( /.*authkey\=/, "" );
        authkeyalbum = "?authkey="+authkey;
        authkey = "&authkey="+authkey;
    }
    albumid = albumid.replace( /\?.*/g, "" );
    var username = albumLink.replace( /.*user\//g, "" );
    username = username.replace( /\/.*/g, "" );
    var usernameOnly = username;
    username = "&username="+ username;
    ////////////////////////////////////////////////////////////////// 

    var photo_link = "http://picasaweb.google.com/"+usernameOnly+"/"+albumName+authkeyalbum; // "albumLink;  j.entry.summary.$t.slice(photo_begin, photo_end);
    var album_base_path = window.location.protocol + "//" + window.location.hostname+window.location.pathname +"?"+nValue+"child=1&album="+ albumName+"&slideshow=1"+username+authkey+alink;
    var downloadAlbumLink = "";
    var downloadAlbumLinkWithDVI = "";
    var downloadAlbumLinkWithTD = "";
    if( downloadable == "true" || downloadable >= 1 ) {
        downloadAlbumLink = "picasa://downloadfeed?url=http%3A//picasaweb.google.com/data/feed/back_compat/user/"+usernameOnly+"/album/"+albumName+"?kind=photo&alt=rss"+authkey+"&imgdl=1";
        downloadAlbumLinkWithDVI = "<div style='text-align:center;'><a href='"+downloadAlbumLink+"'>Download Album</a></div>";
        downloadAlbumLinkWithTD = "<td align='center'><a class='standard' href='" + downloadAlbumLink+ "'>Download Album</a></td>";
    }
    if( noHeaderLinks != 1 ) {
        htmlOut += "<table border=0 width='100%'><tr>";
        if( galleryLinkFlag == 1 ) {
            htmlOut += "<td align='left' width='25%'><a class='standard' href='" + window.location.protocol + "//" + window.location.hostname+window.location.pathname+"?"+nValueSingle+alink+"'>Gallery Home</a> @ <br>"+ j.feed.title.$t +"&nbsp;&nbsp;["+np+" item"+item_plural+"]</td>";
        }
        htmlOut += "<td align='left' width='25%'><a class='standard' href='" + album_base_path + "'>Slide Show</a></td>";
        htmlOut += downloadAlbumLinkWithTD;
        htmlOut += "<td align='right' width='25%'><a class='standard' href='" + photo_link+ "'>View this album in Picasa</a></td>";
        htmlOut += "</tr></table>";
    }

    var albumCallBackFnAttr = "";
    if( albumCallBackFn != "" ) {
        albumCallBackFnAttr = "&albumCallBackFn=" + albumCallBackFn;
    }
    var photoCallBackFnAttr = "";
    if( photoCallBackFn != "" ) {
        photoCallBackFnAttr = "&photoCallBackFn=" + photoCallBackFn;
    }

    //htmlOut += "<div style='text-align:left;'><a class='standard' href='" + album_base_path + "'>Slide Show</a></div>"+downloadAlbumLinkWithDVI+"<div style='text-align:right;'><a target=PICASA class='standard' href='"+photo_link+"'>View this album in Picasa</a></div><br/>";
    htmlOut += "<table border='0'><tr>";
    if( maxPhotos == -1 ) {
        maxPhotos = j.feed.entry.length;
    }
    else {
        if( maxPhotos > j.feed.entry.length ) {
            maxPhotos = j.feed.entry.length;
        }
    }
    for(index=0;index<maxPhotos;index++){
        var i=index;
        if( randomFlag == 1 ) {
            i = Math.floor(Math.random()*j.feed.entry.length)
        }
        var img_base = j.feed.entry[i].media$group.media$content[0].url;

        var id_begin = j.feed.entry[i].id.$t.indexOf('photoid/')+8;
        var id_end = j.feed.entry[i].id.$t.indexOf('?');
        var id_base = j.feed.entry[i].id.$t.slice(id_begin, id_end);
        photoids[i]=id_base;


        // display the thumbnail (in a table) and make the link to the photo page, including the gallery name so it can be displayed.
        // (apparently the gallery name isn't in the photo feed from the Picasa API, so we need to pass it as an argument in the URL) - removed the gallery name 7/18/2007
        var album = albumName;
        var link_url = "?"+nValue+"child=1&album="+album+username+"&photoid="+id_base+authkey+albumCallBackFnAttr+photoCallBackFnAttr; //+"&photoids="+photoids;
        // disable the navigation entirely for really long URLs so we don't hit against the URL length limit.
        // note: this is probably not necessary now that we're no longer passing the photoarray inside the URL. 7/17/2007
        // Not a bad idea to leave it in, though, in case something goes seriously wrong and we need to revert to that method.
        if (link_url.length > 2048) { link_url = link_url.slice(0, link_url.indexOf('&photoids=')+10)+id_base; }
        // http://picasaweb.google.com/rosevzw/RoseDinner2009#slideshow
        //$("<p><center><SPAN STYLE='font-size: 9px'>"+j.feed.entry[i].summary.$t+"</span></center>");
        var captionHTML = "";
        var fullCaption = "";
        var captionHTMLInternal = "";
        if( j.feed.entry[i].media$group.media$description.$t ) {
            var caption = j.feed.entry[i].media$group.media$description.$t;
            fullCaption = caption;
            var caplength = caption.length;
            if( caplength > 22 ) {
                caption = caption.substring(0,22);
                caption += "...";
            } 
            var fullCapHTML = "<a class='info'>"+caption+"<span>"+fullCaption+"</span></a>";
            captionHTML = "<p><center>"+fullCapHTML+"</center></p>";
            captionHTML = "<p><center><SPAN STYLE='font-size: 12px'>"+caption+"</span></center></p>";

            var mouse_definition = "MouseDefinition"+nextDefinitionNo;
            LL_infoID[nextDefinitionNo] = mouse_definition;
            var boxheight = 21 * (caplength+0.5)/22;
            var divDefn = "<div id=\""+mouse_definition+"\" style=\"top: 1px; left: 1px; width: 160px; padding:11;\" class=\"infoboxstyle\">"+fullCaption+"</div>";
            captionHTMLInternal = divDefn+"<a href='javascript:Null()' onMouseover='LL_showinfo("+nextDefinitionNo+")' onMouseout='LL_hideallinfo()'>"+caption+"</a>";
            captionHTML = "<p><center><SPAN STYLE='font-size: 12px'>"+captionHTMLInternal+"</span></center></p>";

            nextDefinitionNo++;
        }
        var targetLinkHTML = targetLink;
        if( targetLink == "" ) {
            targetLinkHTML = link_url+alink;
        }
        var imgThumbWidthHTML = "";
        if( imgThumbWidth!=0 ) {
            imgThumbWidthHTML = " width="+imgThumbWidth+" ";
        }
        if( captionHTML == "" ) {
            htmlOut += "<td valign=top><table border='"+borders+"'><tr><td><a href='"+targetLinkHTML+"'><img src='"+img_base+"?imgmax="+imgmax+"&crop=1' class='pwimages'"+imgThumbWidthHTML+"/></a></td></tr></table>";
        }
        else {
            var prevDefnNo = nextDefinitionNo-1;
            var imgCaptionHTML = "<a href='"+targetLinkHTML+"' onMouseover='LL_showinfo("+prevDefnNo+")' onMouseout='LL_hideallinfo()'><img src='"+img_base+"?imgmax="+imgmax+"&crop=1' class='pwimages'"+imgThumbWidthHTML+"/></a>";
            htmlOut += "<td valign=top><table border='"+borders+"'><tr><td>"+imgCaptionHTML;
            htmlOut += "</td></tr></table>";
        }
        htmlOut += captionHTML;
        htmlOut += "</td>";

        ////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////
        /*
           if( j.feed.entry[i].media$group.media$description.$t ) {
           var caption = j.feed.entry[i].media$group.media$description.$t;
           var caplength = caption.length;
           if( caplength > 22 ) {
           caption = caption.substring(0,22);
           caption += "...";
           } 
           htmlOut += "<p><center><SPAN STYLE='font-size: 12px'>"+j.feed.entry[i].media$group.media$description.$t+"</span></center></p>";
           }
           htmlOut += "</td>";
         */


        if (index % columns == columns-1) {
            if( index == maxPhotos-1 ) {
            }
            else {
                htmlOut += "</tr><tr><td><br/></td></tr><tr>";
            }
        }
    }
    htmlOut += "</tr></table>";
    //alert( htmlOut );
    //document.getElementById("picasaSpan").innerHTML = htmlOut;
    if( globalUniqueKey == '' ) {
        $(htmlOut);
    }
    else {
            var cell = document.getElementById(globalUniqueKey);
            if(  cell == null ) {
                $(htmlOut);
            }
            else {
                removeAllChilds( cell );
                cell.innerHTML = htmlOut;
            }
    }
}
function removeAllChilds( cell )
{
    if( cell ) {
        /*
        if ( cell.hasChildNodes() )    {
            for( var x = cell.childNodes.length-1; x>=0; x-- ) {
                var childNode = cell.childNodes[x];
                if( childNode.hasChildNodes() ) {
                    removeAllChilds( childNode );
                }
                cell.removeChild( childNode );   
                if( childNode.outerHTML ) {
                    childNode.outerHTML = "";
                }
                childNode = null;
                alert( "Deleting for node="+x);
            } 
        }
        */
        cell.innerHTML = "";
    }
}
function insertAndExecute(id, text)
{
    domelement = document.getElementById(id);
    domelement.innerHTML = text;
    var scripts = [];

    ret = domelement.childNodes;
    for ( var i = 0; ret[i]; i++ ) {
        if ( scripts && nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
            scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
        }
    }

    for(script in scripts)
    {
        evalScript(scripts[script]);
    }
}
function nodeName( elem, name ) {
    return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
}
function evalScript( elem ) {
    data = ( elem.text || elem.textContent || elem.innerHTML || "" );

    var head = document.getElementsByTagName("head")[0] || document.documentElement,
        script = document.createElement("script");
    script.type = "text/javascript";
    script.appendChild( document.createTextNode( data ) );
    head.insertBefore( script, head.firstChild );
    head.removeChild( script );

    if ( elem.parentNode ) {
        elem.parentNode.removeChild( elem );
    }
}

function getElementsByTagNameId()
{
    //Init
    var elements;

    var sc = document;

    //Get all children of the scope node
    elements = sc.getElementsByTagName('div');
    var str = "";
    for( i=0; i < elements.length; i++ ){
        var id = elements[i].getAttribute('id');
        if(id != null){
            str += id + "---";
        }
    }
    //alert( str );
}
function placeHTMLTextInDIVId( htmlOut, globalUniqueKey )
{
    if( globalUniqueKey == '' ) {
        document.write(htmlOut);
        //$(htmlOut);
    }
    else {
        var cell = document.getElementById(globalUniqueKey);
        if(  cell == null ) {
            //alert("TF: "+globalUniqueKey);
            var htmlNextOut = '<div id="'+globalUniqueKey+'">';
            htmlNextOut += htmlOut;
            htmlNextOut += "</div>";
            document.write(htmlNextOut);
            htmlNextOut = '<div id="scriptDivImage">';
            htmlNextOut += "</div>";
            document.write(htmlNextOut);
            //$(htmlNextOut);
        }
        else {
            //alert("TT: "+globalUniqueKey);
            removeAllChilds( cell );
            cell.innerHTML = htmlout;
            /*
            var x = cell.getElementsByTagName("script"); 
            for(var i=0;i<x.length;i++) {  
                eval(x[i].text);  
            }*/
        }
    }
}
function placeHTMLTextInDIVIdEvaluate( htmlOut, url, globalUniqueKey )
{
    globalUniqueKey = "scriptDivImage";
    if( globalUniqueKey == '' ) {
        document.write(htmlOut);
        //$(htmlOut);
    }
    else {
        var cell = document.getElementById(globalUniqueKey);
        if(  cell == null ) {
            //alert(htmlOut);
            var htmlNextOut = '<div id="'+globalUniqueKey+'">';
            htmlNextOut += htmlOut;
            htmlNextOut += "</div>";
            document.write(htmlNextOut);
            //$(htmlNextOut);
        }
        else {
            //alert("TF: "+globalUniqueKey);
            removeAllChilds( cell );
            //alert( url );
            /*
            cell.innerHTML = htmlOut;
            var x = cell.getElementsByTagName("script"); 
            for(var i=0;i<x.length;i++) {  
                alert( x[i].text );
                eval(x[i].text);  
            }
            */
            
            var e = document.createElement("script");
            e.src = url;
            e.setAttribute( "language", "javascript" );
            e.setAttribute( "type", "text/javascript" );
            cell.appendChild(e);
            var x = cell.getElementsByTagName("script"); 
            for(var i=0;i<x.length;i++) {  
                eval(x[i].text);  
            }
            //var scripts = cell.getElementsByTagName("script");
            //var script = scripts[0];
            //alert("htmlOut: "+script.text);
            //eval(script.text);
            //insertAndExecute( globalUniqueKey, htmlOut );
        }
    }
}
function getImageTableLinkWithDynamicLoading(buttonsHtml, width,imageLink,caption,tailor)
{
    var htmlOut = "";
    htmlOut += buttonsHtml;
    htmlOut += "<table border='0' cellpadding='0' cellspacing='0' style='margin:0px 0px;padding:0;'><tr><td style='background-color:#AAAAAA; background-image:url(pub/boxes/cedar-1.gif);'>";
    htmlOut += "              <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>";
    htmlOut += "                     <td style='margin:0;padding:0;background-image: url(pub/boxes/blackline.gif);height:14px;' valign='top'><img src='pub/boxes/ctl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''/><img src='pub/boxes/ctr1-ffffff.gif'   hspace='0' vspace='0' align='right' width='15' height='14' alt=''/></td>";
    htmlOut += "               </tr></table>";
    htmlOut += "               <table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>";
    htmlOut += "                           <td width='100%' style='background-color:#FFffff; font-size:140%; color:#000000; font-weight:bold; font-family:Verdana, Arial, Helvetica, sans-serif; border:2px #000000 solid;'><img id='dynamicImageTableLinkImageLink' src='"+imageLink+"' width='"+width+"'/></td>";
    htmlOut += "               </tr></table>";
    htmlOut += "               <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>";
    htmlOut += "                       <td style='padding:0;margin:0;background-image: url(pub/boxes/botline.gif);height:14px;' valign='top'><img src='pub/boxes/cbl1-ffffff.gif' hspace='0' vspace='0' align='left' width='15' height='14' alt=''/><img src='pub/boxes/cbr1-ffffff.gif'  hspace='0' vspace='0' align='right' width='15' height='14' alt='' border='0'/></td>";
    htmlOut += "   </tr></table></td></tr></table>";
    htmlOut += tailor;
    return htmlOut;
    //alert("Updating the photo");
    //alert("Updated the photo");
}
function loadNextPrevPhoto( username, album, authkeyTag, tagTag, callBackFn, photoId )
{
    //var html = '<script type="text/javascript" src="http://picasaweb.google.com/data/entry/base/user/'+username+'/album/'+album+'/photoid/'+photoId+'?'+authkeyTag+tagTag+'alt=json&callback='+callBackFn+'"></script>';
    var url= 'http://picasaweb.google.com/data/entry/base/user/'+username+'/album/'+album+'/photoid/'+photoId+'?'+authkeyTag+tagTag+'alt=json&callback='+callBackFn;
    var html = '<script type="text/javascript" src="'+url+'"></script>';
    var globalUniqueKey = "dynamicImageTableLink";
    //document.write( html );
    //$(html);
    placeHTMLTextInDIVIdEvaluate( html, url, globalUniqueKey );
}
function photoFunShow(j)
{
    photoFunShowCore( '', j, 658, "", "", 0, "" );
}
function photoFunShowCoreSubSequent(globalUniqueKey, j, max_width, alink, eachAlbumCallBackFunction, gallaryPathLinkFlag, photoCallBackFn )
{
    //var photo_id = getValue('photoid');
    //photo_id = photo_id.replace( /#.*/g, "" );
    //if( presentShowPhoto == "-1" ) {
        //presentShowPhoto = photo_id;
    //}
    //for(i=0;i<photo_array.length;i++){
        //if (photo_array[i]==presentShowPhoto)
        //{
            //var p1 = photo_array[i-1]; //ID of the picture one behind this one; if null, we're at the beginning of the album
            //photo_id = i + 1; //this is the count of the current photo
            //var n1 = photo_array[i+1]; //ID of the picture one ahead of this one; if null, we're at the end of the album
        //}
    //}
    //hotoFunShowCoreWithPhotoId(globalUniqueKey, j, max_width, alink, eachAlbumCallBackFunction, gallaryPathLinkFlag, photoCallBackFn, photo_id );
}
function photoFunShowCore(globalUniqueKey, j, max_width, alink, eachAlbumCallBackFunction, gallaryPathLinkFlag, photoCallBackFn )
{
    var photo_id = getValue('photoid');
    photo_id = photo_id.replace( /#.*/g, "" );
    photoFunShowCoreWithPhotoId(globalUniqueKey, j, max_width, alink, eachAlbumCallBackFunction, gallaryPathLinkFlag, photoCallBackFn, photo_id );
}
function photoFunShowCoreWithPhotoId(globalUniqueKey, j, max_width, alink, eachAlbumCallBackFunction, gallaryPathLinkFlag, photoCallBackFn, photo_id )
{
    //returns exactly one photo

    //alert("Calling photoFunShowCore");
    var album_begin = j.entry.summary.$t.indexOf('href="')+6;
    var album_end = j.entry.summary.$t.indexOf('/photo#');
    var album_link = j.entry.summary.$t.slice(album_begin, album_end);
    var photoid_begin = j.entry.id.$t.indexOf('photoid/')+8;
    var photoid_end = j.entry.id.$t.indexOf('?');
    var photoid_base = j.entry.id.$t.slice(photoid_begin, photoid_end);
    //alert( "Photo ID="+photoid_base );
    photo_id = photoid_base;
    var img_title = j.entry.title.$t;

    //get the dimensions of the photo we're grabbing; if it's smaller than our max width, there's no need to scale it up.
    var img_width = j.entry.media$group.media$content[0].width;
    var img_height = j.entry.media$group.media$content[0].height;


    var img_base = j.entry.media$group.media$content[0].url;
    //alert( "ImgBase="+img_base);

    // is this a video? If so, we will display that in the breadcrumbs below.
    var is_video = 0;
    if (j.entry.media$group.media$content.length > 1)
    {
        //$('This is a '+j.entry.media$group.media$content[1].medium+'.<br/>');
        if (j.entry.media$group.media$content[1].medium == "video")
        {
            is_video = 1;
        }
    }

    var nValue = "";
    var nValueSingle = "";
    if( _GET['n'] ) {
        nValueSingle = "n="+getValue('n');
        nValue = nValueSingle + "&";
    }  


    var photo_begin = j.entry.summary.$t.indexOf('href="')+6;
    var photo_end = j.entry.summary.$t.indexOf('"><img');
    var photo_link = j.entry.summary.$t.slice(photo_begin, photo_end);
    var descriptionText = j.entry.media$group.media$description.$t;
    var album = getValue('album'); 
    var mainUserName = getValue('username');
    var username = "&username="+ getValue('username');

    //album name is now taken from the global variable instead. 7/18/2007
    //
    //var album_name_begin = j.entry.summary.$t.indexOf(username)+username.length+1;
    //var album_name_end = j.entry.summary.$t.indexOf('/photo#');
    //var album_name = j.entry.summary.$t.slice(album_name_begin, album_name_end);

    var my_next = next;
    var my_prev = prev;
    var photo_array = photolist;
    //var my_numpics = getValue('np');
    //instead, we now get this through the global variable my_numpics. 7/18/2007

    //$("photo ids: "+getValue('photoids')+".<br/><br/>");
    //$("photolist: "+photo_array+".<br/><br/>");

    //var my_galleryname = getValue('galleryname');
    //var my_fixed_galleryname = my_galleryname.slice(1, my_galleryname.length-1);
    //var my_galleryname = album_name;
    var my_fixed_galleryname = album_name;
    var authkey = "";
    var authkeyKey = "";
    var authkeyKeyStr = "";
    if( _GET['authkey'] ) {
        authkey = "authkey="+getValue('authkey');
        authkeyKey = "&"+authkey;
        authkeyKeyStr = authkey+"&";
    }
    var eachAlbumAttr = "";
    if( eachAlbumCallBackFunction != "" ) {
        eachAlbumAttr = "&albumCallBackFn="+eachAlbumCallBackFunction;
    }
    var album_base_path = window.location.protocol + "//" + window.location.hostname+window.location.pathname +"?"+nValue+"album="+ album+"&child=1"+username+authkeyKey+eachAlbumAttr;

    // Get the filename for display in the breadcrumbs
    var LastSlash = 0;
    var img_filename = img_title;
    for(i=0;i<img_base.length-1;i++){
        if (img_base.charAt(i)=="/")
        {
            LastSlash = i;
        }
    }
    if (LastSlash != 0)
    {
        img_filename = img_base.slice(LastSlash+1, img_base.length);
    }
    // replace some commonly-used URL characters like %20
    img_filename = img_filename.replace("%20"," ");
    img_filename = img_filename.replace("%22","\"");
    img_filename = img_filename.replace("%27","\'");


    //find preceding two and following two pictures in the array; used for the navigation arrows.
    //the arrows are already linked to the previous and next pics, which were passed in with the URL.
    //however, we need the ones that are two behind and two ahead so that we can pass that info along when we link to another photo.
    //
    //NOTE: as of 7/16/2007, the photo array is taken from global photolist (loaded in the getphotolist function) rather than from the URL.
    //This has eliminated the need for really long URLs, which were hitting up against the URL length limit in some extreme cases.
    for(i=0;i<photo_array.length;i++){
        if (photo_array[i]==photo_id)
        {
            var p1 = photo_array[i-1]; //ID of the picture one behind this one; if null, we're at the beginning of the album
            if( i==0 ) {
                p1 = photo_id;
            }
            var current_index = i + 1; //this is the count of the current photo
            var n1 = photo_array[i+1]; //ID of the picture one ahead of this one; if null, we're at the end of the album
            if( i+1 == photo_array.length ) {
                n1 = photo_id;
            }
        }
    }
    //alert("Length:"+photo_array.length+" P1="+p1+"  N1="+n1);

    //these will be passed along if we move to the next or previous photo - removed the gallery name 7/18/2007
    //var prev = album_base_path + "&photoid=" + p1 + "&np=" + my_numpics + "&galleryname=" + my_galleryname.replace("'","%27") + "&prev="+p2+ "&next="+photo_id; //+"&photoids="+photo_array;
    //var next = album_base_path + "&photoid=" + n1 + "&np=" + my_numpics + "&galleryname=" + my_galleryname.replace("'","%27") + "&prev="+photo_id+ "&next="+n2; //+"&photoids="+photo_array;
    var prev = album_base_path + "&photoid=" + p1; //+"&photoids="+photo_array;
    var next = album_base_path + "&photoid=" + n1; //+"&photoids="+photo_array;
    var abp = album_base_path;

    //Display the breadcrumbs
    var my_item_plural = "";
    if (my_numpics != 1)
    {
        my_item_plural = "s";
    }
    var item_label = "picture";
    var item_label_caps = "Picture";
    if (is_video == 1) //if it's a video, don't say it's a picture, say it's an "item" instead
    {
        item_label = "item";
        item_label_caps = "Item";
    }
    //if (photo_array.length == 1) { var current_index_text = "Total of " + my_numpics + " " + item_label + my_item_plural; } else { var current_index_text = item_label_caps + " " + current_index + " of " + my_numpics; }
    var current_index_text = item_label_caps + " " + current_index + " of " + my_numpics;
    if (is_video == 1) { current_index_text = current_index_text + "&nbsp;&nbsp;[VIDEO]"; }  //show in the breadcrumbs that the item is a video
    var gallaryPathLink = "";
    if( gallaryPathLinkFlag == 1 ) {
        gallaryPathLink = window.location.protocol + "//" + window.location.hostname+window.location.pathname +"?"+nValueSingle+alink;
        gallaryPathLink = "<a class='standard' href='"+gallaryPathLink+"'>Gallery Home</a> @ ";
    }
    var htmlOut = "<center>";
    var buttonsHtml = "";
    //buttonsHtml += "<div style='margin-left:3px'>"+gallaryPathLink+"<a class='standard' href='" + album_base_path +alink+ "'>" + my_fixed_galleryname + "</a> @ <!--" + img_filename + "-->" + current_index_text + "</div><div style='text-align:right; margin-right:3px;'><a target=PICASA class='standard' href='"+photo_link+"'>View this image in Picasa</a></div><br/>";
    buttonsHtml += "<table border='0' width='100%'><tr><td align='left'>"+gallaryPathLink+"<a class='standard' href='" + album_base_path +alink+ "'>" + my_fixed_galleryname + "</a> <span id='pictureIndexDynamic'>@ " + current_index_text + "</span></td><td align='right'><a target=PICASA id='pictureLinkDynamic' class='standard' href='"+photo_link+"'>View this image in Picasa</a></td></tr></table><br/>";
    //$("<div style='margin-left:3px'><a class='standard' href='"+ window.location.protocol + "//" + window.location.hostname+window.location.pathname+"?"+nValueSingle+alink+"'>Gallery Home</a><a class='standard' href='" + album_base_path +alink+ "'>" + my_fixed_galleryname + "</a> @ <!--" + img_filename + "-->" + current_index_text + "</div><!--div style='text-align:right; margin-right:3px; margin-top:-14px'><a target=PICASA class='standard' href='"+photo_link+"'>View this image in Picasa</a></div--><br/>");



    if (p1 == null) //we're at the first picture in the album; going back takes us to the album index
    { prev = album_base_path }

    if (n1 == null) //we're at the last picture in the album; going forward takes us to the album index
    { next = album_base_path }
    
    var prevHRef = prev+alink;
    var nextHRef = next+alink;
    var tagTag = "";
    if( _GET['tag'] ) {
        tagTag = "tag="+ getValue('tag')+'&';
    }
    if( reloadSinglePhotoFullPage == 0 ) {
        var argStr = "'"+mainUserName+"', '"+album+"', '"+authkeyKeyStr+"', '"+tagTag+"', '"+photoCallBackFn+"'"; 
        prevHRef = "javascript:loadNextPrevPhoto(";
        prevHRef += argStr+", '"+p1+"'";
        prevHRef += ")";
        nextHRef = "javascript:loadNextPrevPhoto(";
        nextHRef += argStr+", '"+n1+"'";
        nextHRef += ")";
    }
    //the navigation panel: back, home, and next.
    buttonsHtml += "<table border=0><tr valign=top>";
    if (photo_array.length > 1) { 
        buttonsHtml += "<td><a id='prevHRefDynamicImageLink' class='standard' href=\""+prevHRef+"\"><img border=0 alt='Previous item' src='pub/scripts/prev.gif'/></a> </td><td></td>"; 
    }
    buttonsHtml += "<td> <a class='standard' href='"+abp+alink+"'><img border=0 alt='Back to album index' src='pub/scripts/home.jpg'/></a> </td>";
    if (photo_array.length > 1) { 
        buttonsHtml += "<td></td><td> <a id='nextHRefDynamicImageLink' class='standard' href=\""+nextHRef+"\"><img border=0 alt='Next item' src='pub/scripts/next.gif'/></a></td>"; 
    }
    buttonsHtml += "</tr></table><br/>";

    var display_width = max_width;
    if (img_width < display_width)
    { display_width = img_width; } //don't scale up photos that are narrower than our max width; disable this to set all photos to max width

    //at long last, display the image and its description. photos larger than max_width are scaled down; smaller ones are left alone
    //$("<center><!--<a border=0 target=PICASA href='"+photo_link+"'>--><img id='picture' width="+display_width+" src='"+img_base+"?imgmax="+photosize+"' class='pwimages' /><!--</a>--></center>");
    var tailor = "<br/>";
    if( descriptionText ) {
        tailor += "<p><center><div style='margin-left:2px'>&copy; "+copyRightTitle+": "+descriptionText+"</div></center></p>";
    }
    htmlOut += getImageTableLinkWithDynamicLoading( buttonsHtml, display_width, img_base+"?imgmax="+photosize, "", tailor );
    htmlOut +="</center>";


    //now we will trap left and right arrow keys so we can scroll through the photos with a single keypress ;-) JMB 7/5/2007
    htmlOut += '<script language="Javascript"> function testKeyCode( evt, intKeyCode ) { if ( window.createPopup ) return evt.keyCode == intKeyCode; else return evt.which == intKeyCode; } document.onkeydown = function ( evt ) { if ( evt == null ) evt = event; if ( testKeyCode( evt, 37 ) ) { window.location = "' + prev + '"; return false; } if ( testKeyCode( evt, 39 ) ) { window.location = "' + next + '"; return false; } } </script>';
    var globalUniqueKey = "dynamicImageTableLink";
    if( reloadSinglePhotoFullPage == 0 ) {
        //alert( "Called here="+htmlOut );
        var flag = false;
        var cell = document.getElementById( "dynamicImageTableLinkImageLink" );
        if( cell != null ) {
            cell.setAttribute( "src", img_base+"?imgmax="+photosize );
            cell.setAttribute( "width", display_width );
            flag = true;
        }
        var cell = document.getElementById( "pictureIndexDynamic" );
        if( flag == true || cell != null ) { 
            cell.innerHTML = "@ " + current_index_text;
        }
        var cell = document.getElementById( "pictureLinkDynamic" );
        if( flag == true || cell != null ) { 
            cell.setAttribute( "href", photo_link );
        }
        var cell = document.getElementById( "prevHRefDynamicImageLink" );
        if( flag == true || cell != null ) { 
            cell.setAttribute( "href", prevHRef );
        }
        var cell = document.getElementById( "nextHRefDynamicImageLink" );
        if( flag == true || cell != null ) { 
            cell.setAttribute( "href", nextHRef );
        }
        //alert( "Flag="+flag );
        if( !flag ) {
            placeHTMLTextInDIVId( htmlOut, globalUniqueKey );
        }
    }
    else {
        placeHTMLTextInDIVId( htmlOut, globalUniqueKey );
    }


    // an attempt at resampling the photo, rather than relying on the browser's internal resize function. doesn't work, unfortunately.
    //
    //$("<?php $filename='"+img_base+"?imgmax="+photosize+"'; $width = 658; $height = 1600; list($width_orig, $height_orig) = getimagesize($filename); ");
    //$("$ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } ");
    //$("$image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); ");
    //$("imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p, null, 100); ?>");

}
function photoCallBackFn( j )
{
    photoFunShowCore('',j, 658, "", "", 1,"" );
}
function photo(j,width,alink,albumCallBackFn,photoCallBackFn)
{
    photoFunShowCore('',j,width,alink,albumCallBackFn,1,photoCallBackFn);
}
function callAllAlbums( globalUniqueKey, albumsArray, groupAlbumId )
{
    var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);
    //var BROWSER_IS_IE = 0;
    //if (browser=="Microsoft Internet Explorer")  {
    //    BROWSER_IS_IE = 1;
    //}
    var htmlOut = '';
    if( globalUniqueKey != "" ) {
        htmlOut += '<div id="'+globalUniqueKey+'">';
    }
    //if( ! BROWSER_IS_IE ) {
        htmlOut += "<table border=0 align='center' cellspacing='2' cellpadding='2'><tr>";
    //}
    str="";
    var i=0;
    for(i=0;i<columns;i++) {
        str += "<td><br/></td>";
    }
    for( i=0; i<albumsArray.length; i++ ) {
        var authkeyTagTmp = "";
        if( albumsArray[i].kname != "" ) {
            authkeyTagTmp = 'authkey='+albumsArray[i].kname+'&';
        }
        var tagTmp = "";
        if( albumsArray[i].tag != "" ) {
            tagTmp = 'tag='+albumsArray[i].tag+'&';
        }
        var username = albumsArray[i].uname;
        var albumName = albumsArray[i].aname;
        var callBackFn = albumsArray[i].callBackFn;
        if( callBackFn == "" || callBackFn == null || callBackFn == undefined ) {
            callBackFn = "picasaalbumweb";
        }
        //if( ! BROWSER_IS_IE ) {
            htmlOut += "<td valign='top' align='center'>";
        //}
        var uniqueKey = albumsArray[i].uniqueKey;
        if( uniqueKey == "" ) {
            uniqueKey = uname+"_"+aname+"_tmp";
        }
        //alert( "UniqueKey Src = "+uniqueKey);
        htmlOut += '<div id="'+uniqueKey+'">';
        htmlOut += '<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+albumName+'?'+authkeyTagTmp+""+tagTmp+'category=photo&alt=json&callback='+callBackFn+'"></script>';//picasaweb
        htmlOut += '</div>';
        //if( ! BROWSER_IS_IE ) {
            htmlOut += "</td>";
        //}
        if (i % columns == columns-1) {
            //if( ! BROWSER_IS_IE ) {
                htmlOut+="</tr><tr>"+str+"</tr><tr>";
            //}
        }
    }
    //if( ! BROWSER_IS_IE ) {
        for(; i!=0 && i<columns; i++ ) {
            htmlOut += str+"";
        }
        htmlOut += "</tr></table>";
    //}
    if( globalUniqueKey != "" ) {
        htmlOut += "</div>";
    }
    document.write( htmlOut );
}
function initializeShow( albumVar )
{
    var username = albumVar.uname;
    var album = albumVar.aname;
    var authTag = "";
    if( albumVar.kname != "" ) {
        authTag = "authkey="+albumVar.kname+'&';
    }
    var tagTag = "";
    if( albumVar.tag != "" ) {
        tagTag = "tag="+albumVar.tag+'&';
    }
    var callBackFn = albumVar.callBackFn;
    if( callBackFn == "" || callBackFn == null || callBackFn == undefined ) {
        callBackFn = "albumsFunShow";
    }
    $('<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+album+'?'+authTag+tagTag+'category=photo&alt=json&callback='+callBackFn+'"></script>');//albums
}
function showPicasaAlbum( albumVar )
{
    if( _GET['child'] && _GET['album'] ) {
        var found = 0;
        if( albumVar.aname.toLowerCase() == getValue('album').toLowerCase() && albumVar.uname.toLowerCase() == getValue('username').toLowerCase() ) {
            if( _GET['tag'] ) {
                if( albumVar.tag == getValue('tag') ) {
                    found = 1;
                }
            }
            else {
                found = 1;
            }
        }
        if( found == 0 ) {
            initializeShow( albumVar );
        }
        else if( _GET['photoid'] && _GET['album'] ) {
            var photoId = getValue('photoid');
            photoId = photoId.replace( /#.*/g, "" );
            var username = getValue('username');
            username = username.replace( /#.*/g, "" );
            var album = getValue('album');
            var authkeyTag = "";
            if( _GET['authkey'] ) {
                authkeyTag = "authkey="+ getValue('authkey')+'&';
            }        
            var tagTag = "";
            if( _GET['tag'] ) {
                tagTag = "tag="+ getValue('tag')+'&';
            }
            var callBackFn = albumVar.eachPhotoCallBackFn;
            if( callBackFn == "" || callBackFn == null || callBackFn == undefined ) {
                callBackFn = "photoFunShow";
            }
            $('<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+album+'?'+authkeyTag+tagTag+'category=photo&alt=json&callback=getphotolist"></script>');//get the list of photos in the album and put it in the global "photolist" array so we can properly display the navigation arrows; this eliminates the need for really long URLs :-) 7/16/2007
            $('<script type="text/javascript" src="http://picasaweb.google.com/data/entry/base/user/'+username+'/album/'+album+'/photoid/'+photoId+'?'+authkeyTag+tagTag+'alt=json&callback='+callBackFn+'"></script>');//photo        
        }
        else {
            initializeShow( albumVar );
        }
    }
    else if( _GET['slideshow'] && _GET['album'] && _GET['username'] ) {
        var found = 0;
        if( albumVar.aname == getValue('album') && albumVar.uname == getValue('username') ) {
            if( _GET['tag'] ) {
                if( albumVar.tag == getValue('tag') ) {
                    found = 1;
                }
            }
            else {
                found = 1;
            }
        }
        if( found == 0 ) {
            initializeShow( albumVar );
            return;
        }
        var username = getValue('username');
        username = username.replace( /#.*/g, "" );
        var album = getValue('album');
        var authkeyTag = "";
        if( _GET['authkey'] ) {
            authkeyTag = "authkey="+ getValue('authkey');
        }        
        var tagTag = "";
        if( _GET['tag'] ) {
            tagTag = "tag="+ getValue('tag')+'&';
        }
        getSlideShow( albumVar, username, album, authkeyTag, 'yes', ''  );
    }
    else {
        initializeShow( albumVar );  
    }
}
function getSlideShow( albumVar, username, albumName, authKeyTag, extraInfo, noautoplayFlag )
{
    var authKeyTag1 = "";
    var authKeyTag2 = "";
    if( authKeyTag != "" ) {
        authKeyTag1 = "%26"+authKeyTag;
        authKeyTag2 = "?"+authKeyTag;
    }
    var width = albumVar.slideShowWidth;
    var slideShowCaptions = albumVar.slideShowCaptions;
    var height = albumVar.slideShowHeight;
    var nValueSingle = "";
    if( _GET['n'] ) {
        nValueSingle = "n="+getValue('n');
    }
    if( extraInfo == 'yes' ) {
        var photo_link = "http://picasaweb.google.com/"+username+"/"+albumName+authKeyTag2; // "albumLink;  j.entry.summary.$t.slice(photo_begin, photo_end);
        var htmlOut = "<div style='margin-left:3px'><a class='standard' href='" + window.location.protocol + "//" + window.location.hostname+window.location.pathname+"?"+nValueSingle+"'>Gallery Home</a></div><div style='text-align:right; margin-right:5px; margin-top:-14px'><a target=PICASA class='standard' href='"+photo_link+"'>View this album in Picasa</a></div><br/>";
        $(htmlOut);
    }
    var targetLink = "";
    if( albumVar.targetLink == "" ) {
        targetLink = "http://picasaweb.google.com/"+username+"/"+albumName+authKeyTag2;
    }
    else {
        targetLink = albumVar.targetLink;
    }
    if( noautoplayFlag == "" ) {

    }
    else {
        noautoplayFlag = "&noautoplay="+noautoplayFlag;
    }
    var fullScreenText="";
    fullScreenText = "<a href='"+targetLink+"#slideshow"+"'><img border=0 alt='Back to album index' src='pub/scripts/fullscreen.gif'>Full Screen</a>";
    var htmlVar = "";
    htmlVar += "<div style='width:"+width+"px;font-family:arial,sans-serif;font-size:13px;'><div><embed type='application/x-shockwave-flash' src='http://picasaweb.google.com/s/c/bin/slideshow.swf' width='"+width+"' height='"+height+"' flashvars='host=picasaweb.google.com"+noautoplayFlag+"&captions="+slideShowCaptions+"&RGB=0x000000&feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F"+username+"%2Falbum%2F"+albumName+"%3Fkind%3Dphoto%26alt%3Drss"+authKeyTag1+"' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></div><!--span style='float:left;'><a href='http://picasaweb.google.com/"+username+"/"+albumName+authKeyTag2+"' style='color:#3964c2'>View Album</a></span--><!--div style='text-align:right;'><a href='http://picasaweb.google.com/lh/getEmbed' style='color:#3964c2'>Get your own</a></div--></div>";
    $("<center>");
    getBorderTableLink( htmlVar );
    $("&copy; "+copyRightTitle+"&nbsp;&nbsp;&nbsp;"+fullScreenText);
    $("</center>");
    // $(htmlVar);
}
function callPicasaAlbumForPMWiki( globalUniqueKey, albumsArray, groupAlbumId )
{
    if( _GET['child'] && _GET['album'] ) {
        var found = -1;
        for( i=0; i<albumsArray.length; i++ ) {
            if( albumsArray[i].aname.toLowerCase() == getValue('album').toLowerCase() && albumsArray[i].uname.toLowerCase() == getValue('username').toLowerCase() ) {
                if( _GET['tag'] ) {
                    if( albumsArray[i].tag == getValue('tag') ) {
                        found = i;
                        break;
                    }
                }
                else {
                    found = i;
                    break;
                }
            }
        }
        if( found == -1 ) {
            callAllAlbums( globalUniqueKey, albumsArray, groupAlbumId );
        }
        else if( _GET['photoid'] && _GET['album'] ) {
            var albumVar = albumsArray[found];
            var photoId = getValue('photoid');
            photoId = photoId.replace( /#.*/g, "" );
            var username = getValue('username');
            var album = getValue('album');
            var authkeyTag = "";
            if( _GET['authkey'] ) {
                authkeyTag = "authkey="+ getValue('authkey')+'&';
            }        
            var tagTag = "";
            if( _GET['tag'] ) {
                tagTag = "tag="+ getValue('tag')+'&';
            }
            var callBackFn = "photoCallBackFn";
            if( _GET['photoCallBackFn'] ) {
                callBackFn = getValue('photoCallBackFn');
                callBackFn = callBackFn.replace( /#.*/g, "" );
            }
            $('<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+album+'?'+authkeyTag+tagTag+'category=photo&alt=json&callback=getphotolist"></script>');//get the list of photos in the album and put it in the global "photolist" array so we can properly display the navigation arrows; this eliminates the need for really long URLs :-) 7/16/2007
            $('<script type="text/javascript" src="http://picasaweb.google.com/data/entry/base/user/'+username+'/album/'+album+'/photoid/'+photoId+'?'+authkeyTag+tagTag+'alt=json&callback='+callBackFn+'"></script>');//photo        
        }
        else if( !_GET['photoid'] && _GET['album'] ) {
            var albumVar = albumsArray[found];
            var album = getValue('album');
            var username = getValue('username');
            var authkeyTag = "";
            if( _GET['authkey'] ) {
                authkeyTag = "authkey="+ getValue('authkey')+'&';
            }
            var tagTag = "";
            if( _GET['tag'] ) {
                tagTag = "tag="+ getValue('tag')+'&';
            }
            var callBackFn = "albumsFun";
            if( _GET['albumCallBackFn'] ) {
                callBackFn = getValue('albumCallBackFn');
                callBackFn = callBackFn.replace( /#.*/g, "" );
            }
            if( _GET['slideshow'] ) {
                getSlideShow( albumVar, username, album, authkeyTag, 'yes', '' );
            }
            else {
                $('<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/album/'+album+'?'+authkeyTag+tagTag+'category=photo&alt=json&callback='+callBackFn+'"></script>');//albums
            }
        }
    }
    else {
        callAllAlbums( globalUniqueKey, albumsArray, groupAlbumId );  
    }
}
function callPicasaAlbum( globalUniqueKey, albumsArray )
{
    callPicasaAlbumForPMWiki( globalUniqueKey, albumsArray, "" );
}

//$Update: January 31, 2008$

