// $$$ BEGIN CONTENTS $$$
///////////////////////////////////////////////////////////////////
//        DO NOT REMOVE OR ALTER THIS COPYRIGHT NOTICE!          //
//             Copyright © Tel-Aviv Municipality                 //
//   The entire contents of this file is the sole property       //
//   of Tel-Aviv Municipality and is not to be copied,altered,   //
//   used, reused, or studied in whole or in part by any means   //
//      for any purpose except within Tel-Aviv municipality.     //
///////////////////////////////////////////////////////////////////
// --------------------------------------------------------
// Convention: jf_mapshot_...
// --------------------------------------------------------
// NOTES:   Set gb_iriaMapDebug to true to see mapshot list
//          Set gb_iriaMapShots to display mapshots with links
// --------------------------------------------------------
// Access    Function          Purpose
// --------------------------------------------------------
// CLASSES
// class_mapshot               Class for mapshots list
//   METHODS
//    m_mapshot_update         Updates current mapshot index
//
// FUNCTIONS
// PUBLIC jf_mapshot_new       To create a new mapshot
// PUBLIC jf_mapshot_back      To go back one mapshot
// PUBLIC jf_mapshot_forward   To go forward one mapshot
// PUBLIC jf_mapshot_list      To display mapshot list
//
// PRIVATE jf_mapshot_links    To display a set of map thumbnails with hyperlinks
// PRIVATE jf_mapshot_restore  To restore map with parameters
// PRIVATE jf_mapshot_goto     To go to a specific map
// PRIVATE jf_mapshot_html     To return a template to display map parameters
// --------------------------------------------------------
// $$$ END CONTENTS $$$
var is_mode;                   // back, next
var ir_mapshot;                // array of mapshot objects using class_mapshot
var ii;                        // current mapshot number

is_mode     = '';
ir_mapshot  = new Array();

// Current Index
ii = ir_mapshot.length - 1;

// All the parameters required to restore a map
function class_mapshot()
{
 this.eLeft      = top.MapFrame.eLeft;
 this.eBottom    = top.MapFrame.eBottom;
 this.eRight     = top.MapFrame.eRight;
 this.eTop       = top.MapFrame.eTop;

 this.lastLeft   = top.MapFrame.lastLeft;
 this.lastRight  = top.MapFrame.lastRight;
 this.lastTop    = top.MapFrame.lastTop;
 this.lastBottom = top.MapFrame.lastBottom;

 this.xDistance  = top.MapFrame.xDistance;
 this.yDistance  = top.MapFrame.yDistance;

 this.image      = new Image();
 this.image.src  = top.MapFrame.theImage.src;

 // Methods
 this.update     = m_mapshot_update();
}

function m_mapshot_update()
{
 ii      = ir_mapshot.length - 1;
 is_mode = '';
}

function jf_mapshot_new()
{
 // Purpose: To create a new mapshot
 ii                            = ir_mapshot.length - 1;
 ir_mapshot[ir_mapshot.length] = new class_mapshot();
 ir_mapshot[0].image.src       = top.MapFrame.is_href;
}

function jf_mapshot_back()
{
 // Purpose: To go back one mapshot
 if (ii > -1)
 {
  is_mode                 = 'back' ;
  ir_mapshot[0].image.src = top.MapFrame.is_href;

  ii                      = (ii < 1) ? 0 : ii;
  jf_mapshot_restore(ir_mapshot, ii);
  ii--;
 }
 else {ii = -1;}

 // debug to display the history
 if(gb_iriaMapDebug || gb_iriaMapShots) {top.jf_mapshot_list();}
}

function jf_mapshot_forward()
{
 // Purpose: To go forward one mapshot
 if(is_mode == 'back' && (ii < ir_mapshot.length - 1)) {ii++;}
 ii++;
 if (ii < 0) {ii = (ir_mapshot.length>1) ? 1 : 0;}
 if (ii < ir_mapshot.length && ii > -1)
 {
  top.MapFrame.ib_forward = true;
  jf_mapshot_restore(ir_mapshot, ii);
 }
 else {ii = ir_mapshot.length - 1;}

 is_mode = 'next';
 if(gb_iriaMapDebug || gb_iriaMapShots) {top.jf_mapshot_list();}
}

function jf_mapshot_list()
{
 // Purpose: To display mapshot list
 var li, li_upb;
 var ls_html, ls_row, ls_hdr;
 var lr;
 var lw;

 lr = new Array();
 li_upb = ir_mapshot.length;

 if (li_upb>0)
 {
  if (gb_iriaMapShots)
  {
   if (ir_mapshot.length > 1) {jf_mapshot_links();}
  }
  else
  {
   for(li=0;li<li_upb;li++)
   {
    ls_row  = "<TD ALIGN=right>" + parseInt(li)  + "</TD>";
    ls_row += "<TD CLASS=smalls ALIGN=center><IMAGE SRC=" + ir_mapshot[li].image.src + " WIDTH=48px onClick='top.jf_mapshot_goto(" + parseInt(li) + ")'></TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].eLeft      + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].eBottom    + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].eRight     + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].eTop       + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].lastLeft   + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].lastBottom + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].lastRight  + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].lastTop    + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].xDistance  + "</TD>";
    ls_row += "<TD CLASS=smalls>" + ir_mapshot[li].yDistance  + "</TD>";
    ls_row += "<TD CLASS=smalls ALIGN=center>" + ir_mapshot[li].image.src + "</TD>";
    lr[lr.length] = "<TR>" + ls_row + "</TR>";
   }
   ls_hdr  = "<TD CLASS=TDHdr>no</TD>";
   ls_hdr += "<TD CLASS=TDHdr>map            </TD>";
   ls_hdr += "<TD CLASS=TDHdr>minx<BR>eLeft  </TD>";
   ls_hdr += "<TD CLASS=TDHdr>miny<BR>eBottom</TD>";
   ls_hdr += "<TD CLASS=TDHdr>maxx<BR>eRight </TD>";
   ls_hdr += "<TD CLASS=TDHdr>maxy<BR>eTop   </TD>";
   ls_hdr += "<TD CLASS=TDHdr>last<BR>Left   </TD>";
   ls_hdr += "<TD CLASS=TDHdr>last<BR>Bottom </TD>";
   ls_hdr += "<TD CLASS=TDHdr>last<BR>Right  </TD>";
   ls_hdr += "<TD CLASS=TDHdr>last<BR>Top    </TD>";
   ls_hdr += "<TD CLASS=TDHdr>xDistance      </TD>";
   ls_hdr += "<TD CLASS=TDHdr>yDistance      </TD>";
   ls_hdr += "<TD CLASS=TDHdr>image          </TD>";
   ls_hdr  = "<TR>" + ls_hdr + "</TR>";

   ls_html = jf_mapshot_html(msgList[186], ii, ls_hdr + lr.join('\n'));

   with (top.TextFrame.document)
   {
    open();
    write(ls_html);
    close();
   }
   jf_aimsClick_txt()
  }
 }
 else {alert(msgList[187]);}
}

function jf_mapshot_links()
{
 // Purpose: To display a set of map thumbnails with hyperlinks
 var li, li_upb;
 var ls_html;
 var lr;

 lr     = new Array();
 li_upb = ir_mapshot.length;

 if (li_upb > 0)
 {
  for(li=0;li<li_upb;li++)
  {
   lr[li] = "<TD ALIGN=center CLASS=smalls><A onMouseOver='javascript:f_over(this);top.jf_mapshot_goto(" + parseInt(li) + ")' STYLE='border: 1 solid #FFFFFF;'><IMG SRC=" + ir_mapshot[li].image.src + " WIDTH=64px /></A></TD>";
  }
  ls_html = '<HTML>';
  ls_html += '<HEAD>';
  ls_html += '<STYLE TYPE=text/css>';
  ls_html += ' BODY, TD {font-family: Arial, Verdana, Sans-Serif; font-size: 8pt; text-align: center;}';
  ls_html += ' BODY     {margin-top: 0px;}';
  ls_html += ' TD       {padding: 0px; vertical-alignment: top;}';
  ls_html += ' hyper    {border: 1 solid #FFFFFF;}';
  ls_html += '#slides   {width: 100%; height: 80px; overflow-y: hidden; overflow-x: auto; scrollbar-height: 8px;}';
  ls_html += '</STYLE>';

  ls_html += '<S' + 'CRIPT LANGUAGE=javascript>\n';

  ls_html += 'function f_over(aobj)';
  ls_html += '{';
  ls_html += ' f_out(); ';
  ls_html += ' aobj.style.border = "1 outset #000000"';
  ls_html += '}\n';

  ls_html += 'function f_out()';
  ls_html += '{';
  ls_html += ' var ii;';
  ls_html += ' for (ii=0;ii<document.all.length;ii++) {document.all[ii].style.border = "";}';
  ls_html += '}\n';
  ls_html += '</SCRIPT>';

  ls_html += '</HEAD>';
  ls_html += '<BODY>';
  ls_html += '<DIV ID=slides><TABLE CELLSPACING=1 BORDER=0>' + lr.join('\n') + '</TR></TABLE></DIV>';
  ls_html += '</BODY>';
  ls_html += '</HTML>';

  with (top.TextFrame.document)
  {
   open();
   write(ls_html);
   close();
  }
 }
}

function jf_mapshot_restore(ar, ai)
{
 // Purpose: To restore map with parameters
 ar[0].image.src           = top.MapFrame.is_href;

 top.MapFrame.eLeft        = ar[ai].eLeft;
 top.MapFrame.eBottom      = ar[ai].eBottom;
 top.MapFrame.eRight       = ar[ai].eRight;
 top.MapFrame.eTop         = ar[ai].eTop;

 top.MapFrame.lastLeft     = ar[ai].lastLeft;
 top.MapFrame.lastRight    = ar[ai].lastRight;
 top.MapFrame.lastTop      = ar[ai].lastTop;
 top.MapFrame.lastBottom   = ar[ai].lastBottom;

 top.MapFrame.xDistance    = ar[ai].xDistance;
 top.MapFrame.yDistance    = ar[ai].yDistance;

 top.MapFrame.theImage.src = ar[ai].image.src;
}

function jf_mapshot_goto(ai)
{
 jf_mapshot_restore(ir_mapshot, ai)
}

function jf_mapshot_html(as_title, ai_current, as_table)
{
 // Purpose: To return a template to display map parameters
 var ls_html;

 ls_html = '<HTML>';
 ls_html += '<HEAD>';
 ls_html += '<STYLE TYPE=text/css>';
 ls_html += ' BODY, TD {font-family: Arial, Verdana, Sans-Serif; font-size: 8pt; text-align: center;}';
 ls_html += ' BODY     {margin-top: 0px;}';
 ls_html += ' TABLE    {padding: 0px; vertical-alignment: top;}';
 ls_html += ' TD       {padding: 0px; vertical-alignment: top; background: #FFFFFF; color: #000000;}';
 ls_html += '.TDHdr    {padding: 0px; vertical-alignment: top; background: #FFFFFF; color: #000000; text-align: center; font-weight: 800; font-size: 8pt;}';
 ls_html += '.smalls   {padding: 0px; vertical-alignment: top; background: #FFFFFF; color: #000000; text-align: left;   font-weight: 400; font-size: 7pt; font-family: SmallFonts, Smalls;}';
 ls_html += '#slides   {width: 100%; height: 80px; hidden; overflow: auto; scrollbar-width: 8px;}';

 ls_html += '</STYLE>';
 ls_html += '</HEAD>';
 ls_html += '<BODY>';
 ls_html += '<CENTER>';

 ls_html += '<DIV ID=slides>';
 ls_html += '<TABLE CELLSPACING=1>';
 ls_html += as_table;
 ls_html += '</TABLE>';
 ls_html += '</DIV>';

 ls_html += '</BODY>';
 ls_html += '</CENTER>';
 ls_html += '</HTML>';

 return ls_html;
}

