function createCookie(name,value,days) 
{
    if (days) 
    {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) 
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) 
{
    createCookie(name,"",-1);
}

function GetAlbumId ( album_url )
{
    switch (album_url)
    {
        case "http://picasaweb.google.com/gallery002/Moscow":               return "5101266026844810001";
        case "http://picasaweb.google.com/gallery002/LakePowell":           return "5093457530216482993";
        case "http://picasaweb.google.com/gallery002/NewYearEve2007Gala":   return "5030849569785304465";
        case "http://picasaweb.google.com/gallery002/ThanksgivingVacation": return "5015961167028771521";
        case "http://picasaweb.google.com/gallery002/MiscSpringtimePhotos": return "5067195982773896241";
        case "http://picasaweb.google.com/gallery002/KaraokePartyGutkinS":  return "5181511790896556977";
        case "http://picasaweb.google.com/gallery002/ThanksgivingOnHawaiI": return "5181735966714572081";
        case "http://picasaweb.google.com/gallery002/EmilSRacing":          return "5181510004190160849";

        default:                                                            return "";
    }
}    

function SetSlideshowWidth  ( val )  {        createCookie ( 'slideshow_width',  val, 0 ); }
function GetSlideshowWidth  ()       { return readCookie   ( 'slideshow_width'          ); }

function SetSlideshowHeight ( val )  {        createCookie ( 'slideshow_height', val, 0 ); }
function GetSlideshowHeight ()       { return readCookie   ( 'slideshow_height'         ); }

function setSlideshowSize ( width, height )
{
  SetSlideshowWidth  ( width  );
  SetSlideshowHeight ( height );

  location.reload ();
}

function InsertSizeLink ( width, height, cur_width, cur_height )
{
  var start_str = "<a ";

  if ( width == cur_width && height == cur_height )
  {
    start_str += "style=\"font-weight:bold;\" ";
  }

  document.write ( "&nbsp;&nbsp;" + start_str + 
                   "href=\"javascript:setSlideshowSize('" + width + "','" + height + "');\">" +
                                                     "["  + width +  "x"  + height +  "]</a>" );
  
}

function EmbedSlideshow ()
{
  var album_url = GetUrlParams ();
  if (album_url == "#")
  {
      history.back();
  }

  var album_id  = GetAlbumId ( album_url );
  if (album_id  == "")
  {
      document.write ( 'Invalid Picasa Album URL - <a href="' + album_url + '">' + album_url + '</a>' );
      return;
  }

  var url1_split = album_url.split("google.com/");
  var url2_split = url1_split[1].split("/");

  var username = url2_split[0];

  var width    = GetSlideshowWidth  ();
  var height   = GetSlideshowHeight ();

  if ( !width || !height )
  {
    width    = '800';
    height   = '600';
  }

  InsertSizeLink ( '500', '500', width, height )
  InsertSizeLink ( '600', '600', width, height )
  InsertSizeLink ( '700', '600', width, height )
  InsertSizeLink ( '800', '600', width, height )
  InsertSizeLink ( '800', '800', width, height )

  document.write ( "&nbsp;&nbsp;<br><br>" );

  document.write ( 
      '<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&RGB=0x000000&feed=http\%3A\%2F\%2F'
    + 'picasaweb.google.com\%2Fdata\%2Ffeed\%2Fapi'
    + '\%2Fuser\%2F'    + username
    + '\%2Falbumid\%2F' + album_id
    + '\%3Fkind\%3Dphoto\%26alt\%3Drss" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' )
}

