/* $Id$ */

/*
 * Slideshow
 */
function Slideshow ()
{
  /*
   * Used for internal referencing
   */
  var that = this;
  /*
   * List of image URIs
   */
  that.uris = null;
  /*
   * ID of the project
   */
  that.project_id = null;
  /*
   * Name of the project
   */
  that.project_name = null;
  
  /*
   * Sets up the class
   * @param array uris list of image URIs
   * @param integer project_id ID of the project
   * @param string project_name name of the project
   */
  that.setup = function (uris, project_id, project_name)
    {
      var link = null;            // <a> element
      var list = null;            // <ul> element
      var list_item = null;       // <li> element
      
      if ($.browser.msie &&
          ($.browser.version == "6.0" || $.browser.version == "7.0"))
        {
          return;

        }
      
      that.uris = uris;
      that.project_id = project_id;
      that.project_name = project_name;
      
      list = $("#project" + that.project_id + " ul[class=pf_page_links]").first ();

      if (!list)
        return;

      link = $('<a class="main_link jslink">&gt;Screenshots</a>');
      $(link).click (that.click);

      list_item = $('<li/>');
      list_item.append (link);

      /*
       * Add the screenshot link to the list
       */
      
      if (list.children ().first ())
        $(list_item).insertBefore (list.children ().first ());
      else
        list.append (list_item);
      
    }

  /*
   * Creates the lightbox
   */
  that.click = function () 
    {
      var i = null;             // Index
      var link = null;          // <a> element

      for (i in that.uris)
        {
          link = document.createElement ("a");
          link.setAttribute ("href", that.uris[i]);
          link.setAttribute ("title", that.project_name);
          link.className = "screenshot";
          link.appendChild (document.createTextNode ("screenshot"));
        
          $("#project" + that.project_id).append (link);

          $(link).hide ();
        
        }

      $("#project" + that.project_id + " a[class=screenshot]").lightbox ({start: true});

    }
  
}
