/*
//////////////////////////////////////////////////////////////////////////////
// 
// Copyright (c) March 2005
// 
// All rights reserved. This material contains unpublished,
// copyrighted work, which includes confidential and proprietary
// information of HyperTrust NV
// 
// HyperTrust NV, Geldenaaksebaan 329, 3001 Leuven, Brabant, BELGIUM
// 
// $Revision: $
// Last modified by $Author: $ on $Date:  $
// 
///////////////////////////////////////////////////////////////////////////////
*/

///////////////////////////////////////////////////////////////////////////////
// FilmStrip
///////////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------------
// global vars
var g_step    = 2;
var g_timeout = 10;
var g_x = 0;
var g_y = 0;

//-----------------------------------------------------------------------------
// filmstrip class
function HTFilmStrip()
{
  // members
  this.m_layer_id             = 'm_filmstrip_layer';
  this.m_state                = "hidden";
  this.m_dimension            = {Width:0,Height:0}
  this.m_ancor_location       = {X:0,Y:0};

  // functions
  this.WriteBegin         = HTFilmStrip_WriteBegin;
  this.WriteEnd           = HTFilmStrip_WriteEnd;
  this.Place              = HTFilmStrip_Place;
  this.Show               = HTFilmStrip_Show;
  this.Hide               = HTFilmStrip_Hide;
  this.OnShown            = null;
  this.OnHidden           = null;
  this.Animate            = HTFilmStrip_Animate; 
  this.Paint              = HTFilmStrip_Paint;
  this.CalculateLocation  = HTFilmStrip_CalculateLocation;
  
  // set mouse event
  if (window.Event)
    document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove = GetCursorPosition;
}

//-----------------------------------------------------------------------------
// get the cursor position
function GetCursorPosition(e)
{
  g_x = (window.Event) ? e.pageX : event.clientX;
  g_y = (window.Event) ? e.pageY : event.clientY;
}

//-----------------------------------------------------------------------------
// write the film strip div
function HTFilmStrip_WriteBegin()
{
  if (!document.layers)
    document.write('<div id="' + this.m_layer_id + '" style="position: absolute; visibility: hidden; z-index: 1">');
}

//-----------------------------------------------------------------------------
// write the film strip div
function HTFilmStrip_WriteEnd()
{
  if (!document.layers)
    document.write('</div>');
}

//-----------------------------------------------------------------------------
// place the film strip div
function HTFilmStrip_Place()
{
  //  the locations
  this.CalculateLocation();
  
  // set the location of the film strip
  this.Location = {X:this.m_ancor_location.X,Y:this.m_ancor_location.Y - this.m_dimension.Height};

  // paint the filmstrip
  this.Paint();

  // draw the show layer
  var layer = HTGetElementByID('m_show_layer');
  if (layer != null)
  {
    layer.style.left        = this.m_ancor_location.X;
    layer.style.top         = this.m_ancor_location.Y;
    layer.style.right       = this.m_ancor_location.X + this.m_dimension.Width;
    layer.style.bottom      = this.m_ancor_location.Y + this.m_dimension.Height;
    layer.style.visibility  = 'visible';
    layer.style.zIndex      = 4;
  }

  // draw the show image
  var layer = HTGetElementByID('m_show_image');
  if (layer != null)
    HTSetDimensions(layer, this.m_dimension.Width, this.m_dimension.Height);

}

//-----------------------------------------------------------------------------
// show the filmstrip
function HTFilmStrip_Show(i_hiding)
{
  // If the panel is already shown, we do not need to do anything...
  if (this.m_state == "shown" || this.m_state == "showing")
    return;

  if (i_hiding == null)
    return;
    
  // set the state
  this.m_state = "showing";

  // Animate the panel
  this.Animate(); 
}

//-----------------------------------------------------------------------------
// hide
function HTFilmStrip_Hide(i_showing)
{
  // If the panel is already hidden, we do not need to do anything...
  if (this.m_state == "hidden" || this.m_state == "hiding")
    return;

  if (i_showing != null)
  {
    if (this.m_state == "shown" && this.m_ancor_location.X <= g_x &&
        g_x <= this.m_ancor_location.X + this.m_dimension.Width &&
        this.m_ancor_location.Y <= g_y &&
        g_y <= this.m_ancor_location.Y + this.m_dimension.Height)
      return;
  }

  if (this.m_state = "shown");
  {
    HTHideLayer('m_hide_layer_top');
    HTHideLayer('m_hide_layer_left');
    HTHideLayer('m_hide_layer_bottom');
    HTHideLayer('m_hide_layer_right');
  }
  // set the state
  this.m_state = "hiding";

  // show the layer
  HTShowLayer('m_show_layer', 4);

  // Animate the panel
  this.Animate();
}

//-----------------------------------------------------------------------------
// Animate the filmstrip
function HTFilmStrip_Animate( i_layer )
{
  // Check from where this method has been called
  if (!i_layer)
  {
    if (!this)
      return;
    i_layer = this;
  }

  // filmstrip is showing
  if (i_layer.m_state == "showing")
  {
    i_layer.Location.Y = i_layer.Location.Y + g_step;
    i_layer.Paint();

    if (i_layer.Location.Y >= i_layer.m_ancor_location.Y)
    {
      i_layer.m_state = "shown";
      HTShowLayer('m_show_layer', 0);
      HTShowLayer('m_hide_layer_top');
      HTShowLayer('m_hide_layer_left');
      HTShowLayer('m_hide_layer_bottom');
      HTShowLayer('m_hide_layer_right');

      return;
    }
  }
  
  // filmstrip is hidng
  else if (i_layer.m_state == "hiding")
  {
    i_layer.Location.Y = i_layer.Location.Y - g_step;
    i_layer.Paint();
    
    if (i_layer.Location.Y <= i_layer.m_ancor_location.Y - i_layer.m_dimension.Height)
    {
      i_layer.m_state = "hidden";
      return;
    }
  }
  
  // noting
  else
    return;

  // set timeout and call function again
  setTimeout(function(){HTFilmStrip_Animate(i_layer)}, g_timeout);
}

//-----------------------------------------------------------------------------
// Paint filmstrip
function HTFilmStrip_Paint()
{
  // Retrieve the layer for the panel
  var layer = HTGetElementByID(this.m_layer_id);
  if (layer == null)
    return;

  layer.style.visibility  = "visible";
  layer.style.left        = this.Location.X + "px";
  layer.style.top         = this.Location.Y + "px";
  layer.style.clip        = "rect( " + (this.m_ancor_location.Y - this.Location.Y) + "px " + this.m_dimension.Width + "px " +  this.m_dimension.Height + "px 0px)";
}


//-----------------------------------------------------------------------------
// Calculates the location of the filmstrip
// Also sets the dimension
function HTFilmStrip_CalculateLocation()
{
  var layer = HTGetElementByID(this.m_layer_id);
  if (layer != null)
    this.m_dimension = HTGetDimensions(layer);

  var layer = HTGetElementByID('m_image');
  if (layer != null)
  {
    image_location   = HTGetPosition(layer);
    image_dimension  = HTGetDimensions(layer);

    var posx = image_location.X + (image_dimension.Width - this.m_dimension.Width)/2;
    var posy = image_location.Y + image_dimension.Height;

    this.m_ancor_location = {X:posx,Y:posy};
  }
}
