//$Id: slideshow.js,v 1.1 2004/10/27 16:07:44 luccio Exp $
//---------------------------------------------------PUBLIC
function add_slideshow(i, title, text){
   ss[i] = new Slideshow(title, text);
}

function add_slide(slideshow, filename, title, comments, legal){
   ss[slideshow].nslides++;
   ss[slideshow].slides[ss[slideshow].nslides] = new Slide(filename, title, comments, legal);
}

//---------------------------------------------------PRIVATE
var ss = new Array; //ss[i].slides[j].xxx

function Slideshow(title, text){
  this.title   = title;
  this.text    = text;
  this.slides  = new Array();
  this.nslides = 0;
}

function Slide(filename, title, comment, legal){
  this.filename = filename;
  this.title    = title;
  this.comment  = comment;
  this.legal    = legal;
}

//--extract parameters from URL: page.html[?slideshow,slide[,back_link]]
var _slideshow = 1;
var _slide     = 1;
var back_link  = "";
var url = location.href.split("?");
var parameters = null;
if(url[1]) parameters = url[1].split(",");
if(parameters){
   _slideshow = parameters[0];
   if(parameters[1]) _slide = parseInt(parameters[1]);
   if(parameters[2]) back_link = parameters[2];
}

//--browsing functions
function coord(slide){ return "" + _slideshow + "," + slide;}
function first(){ return coord(1);}
function prev(){
   if(_slide == 1) return coord(1);
   else return coord(_slide - 1);
}
function next(){
    if(_slide == ss[_slideshow].nslides) return coord(_slide);
    else return coord(_slide + 1);
}
function back(){ return back_link; }

//--display functions
function has_title    (){ return ss[_slideshow].title;}
function has_text     (){ return ss[_slideshow].text;}
function has_comment  (){ return ss[_slideshow].slides[_slide].comment;}
function has_legal    (){ return ss[_slideshow].slides[_slide].legal;}

function print_title  (){ document.write(ss[_slideshow].title);}
function print_text   (){ document.write(ss[_slideshow].text);}
function print_comment(){ document.write(ss[_slideshow].slides[_slide].comment);}
function print_legal  (){ document.write(ss[_slideshow].slides[_slide].legal);}

function print_status (){ return "<table border='0'><tr>"
                            + "<td bgcolor='#000000' style='color: #eeeeee'>"
                            + "<small>"
                            + "&nbsp;&nbsp;<b>" + _slide + "</b>&nbsp;/&nbsp;"
                            + ss[_slideshow].nslides + "&nbsp;&nbsp;"
                            + "</small>"
                            + "</table>";}
function print_slide_cur (){return "<span id='slide-cur'>" + _slide + "</span>";}
function print_slide_tot (){return "<span id='slide-tot'>" + ss[_slideshow].nslides + "</span>";}

function print_image(){
   document.write("<img  border='0' src='"
                  + folder_images
                  + ss[_slideshow].slides[_slide].filename + "'/>");
}

function write_thumbnaillist(html_document, slideshow){
  for (var i=1; i<=ss[slideshow].nslides; i++){
    document.write("<a href='",
                   html_document, "?", slideshow, ",", i,
                   //folder_images, ss[slideshow].slides[i].filename,
                   "'/>");
    document.write("<img border='0' src='",
                   folder_thumbnails,
                   ss[slideshow].slides[i].filename, "'></a>\n");
  }
}

function write_thumbnailtable(html_document, slideshow, back_link){
  var thumbnails_by_row = 5;
  document.write("<table border='0'>");// bgcolor='#000000'>");
  for (var i=1; i<=ss[slideshow].nslides; i++){
    if((i % thumbnails_by_row) == 1){
      document.write("<tr>");
    }
    document.write("<td align='center' valign='top'>");
    document.write("<a href='",
                   html_document, "?", slideshow, ",", i, ",", back_link,
                   "'/>");
    document.write("<img border='0' src='",
                   folder_thumbnails,
                   ss[slideshow].slides[i].filename, "'></a>");
    if(ss[slideshow].slides[i].title){
      document.write("<br/><small><i>", ss[slideshow].slides[i].title,"</i></small>\n");
    }
  }
  document.write("</table>");
}
