/******************************************************************************/
/* Browser-Typ ermitteln und in Variablen speichern                           */
/******************************************************************************/
var IsIE5 = (document.getElementById && document.all);
var IsNS6 = (document.getElementById && !document.all);

/******************************************************************************/
/* Sichtbarkeit eines Elemetes festlegen (von 0 bis 100)                      */
/******************************************************************************/
function ChangeOpacity(element, percentage)
{
  if (IsIE5)
  {
    if (element.style.filter == "")
    {
      element.style.filter = "alpha(opacity=100)";
    }

    element.filters.alpha.opacity = percentage;
  }

  if (IsNS6)
  {
    element.style.MozOpacity = percentage / 100;
  }
}

/******************************************************************************/
/* Sichtbarkeit eines Elementes ermitteln (von 0 bis 100)                     */
/******************************************************************************/
function GetOpacity(element)
{
  if ((IsIE5) && (element.style.filter != ""))
  {
    return element.filters.alpha.opacity;
  }

  if (IsNS6)
  {
    return element.style.MozOpacity * 100;
  }

  return 100;
}

/******************************************************************************/
/* Fading-Effekte                                                             */
/******************************************************************************/
var fadeStatus = new Array();

function incOpacity(id)
{
  e = document.getElementById(id);

  if (GetOpacity(e) < 100)
  {
    ChangeOpacity(e, GetOpacity(e) + 5);

    fadeStatus[id]['Status'] = 'INC_OPACITY';
    fadeStatus[id]['Timer'] = setTimeout("incOpacity('" + id + "')", 50);
  }
  else
  {
    fadeStatus[id]['Status'] = 'VISIBLE';
    fadeStatus[id]['Timer'] = null;
  }
}

function decOpacity(id)
{
  e = document.getElementById(id);

  if (GetOpacity(e) > 0)
  {
    ChangeOpacity(e, GetOpacity(e) - 5);

    fadeStatus[id]['Status'] = 'DEC_OPACITY';
    fadeStatus[id]['Timer'] = setTimeout("decOpacity('" + id + "')", 50);
  }
  else
  {
    fadeStatus[id]['Status'] = 'HIDDEN';
    fadeStatus[id]['Timer'] = null;
  }
}

function elementFadeIn(id)
{
  if (fadeStatus[id] == null)
  {
    var e = document.getElementById(id);
    ChangeOpacity(e, 0);

    fadeStatus[id] = new Array();
    fadeStatus[id]['Status'] = 'HIDDEN';
    fadeStatus[id]['Timer'] = null;
  }

  switch (fadeStatus[id]['Status'])
  {
    case 'HIDDEN':
      incOpacity(id);
      break;
    case 'DEC_OPACITY':
      clearTimeout(fadeStatus[id]['Timer']);
      incOpacity(id);
      break;
  }
}

function elementFadeOut(id)
{
  if (fadeStatus[id] == null)
  {
    fadeStatus[id] = new Array();
    fadeStatus[id]['Status'] = 'VISIBLE';
    fadeStatus[id]['Timer'] = null;
  }

  switch (fadeStatus[id]['Status'])
  {
    case 'VISIBLE':
      decOpacity(id);
      break;
    case 'INC_OPACITY':
      clearTimeout(fadeStatus[id]['Timer']);
      decOpacity(id);
      break;
  }
}

/******************************************************************************/
/* Shot-Picker Stuff                                                          */
/******************************************************************************/
var timer = 0;
var ShotIndex = 0;
var VisibleShotIndex = 0;
var ShotsCount = 0;
var Shots = null;
var ShotUrl = "";

var ChangeInterval = 9000;

// function initializeShotPicker(shots, shotUrl) // Eigentlich ist es so richtig, untere Zeile lassen wir für eine Weile für Rückwärtskompatibilität
function initializeShotPicker()  // Deprecated
{
  Shots = arguments[0];
  ShotsCount = Shots.length - (Shots.length % 2);

  if (arguments.length > 1)
    ShotUrl = arguments[1];
  else
    ShotUrl = "shots";

  var e1 = document.getElementById('ShotPickerImage1');
  var e2 = document.getElementById('ShotPickerImage2');

  e1.style.visibility = 'visible';
  e2.style.visibility = 'visible';

  ChangeOpacity(e1, 100);
  ChangeOpacity(e2, 100);

  loadNextImage(ChangeInterval - 1000);
}

function loadNextImage(delay)
{
  ShotIndex++;

  if (ShotIndex >= ShotsCount)
    ShotIndex = 0;

  if (Shots[ShotIndex][5] == false)
  {
    Shots[ShotIndex][4] = new Image;
    Shots[ShotIndex][4].onLoad = onShotLoaded();
    Shots[ShotIndex][4].src = '/img/' + ShotUrl + '/' + Shots[ShotIndex][0] + Shots[ShotIndex][1] + '.jpg';
  }

  timer = setTimeout('onChangeImage();', delay);
}

function onShotLoaded()
{
  Shots[ShotIndex][5] = true;
}

function onChangeImage()
{
  if (Shots[ShotIndex][5] == true)
  {
    if ((ShotIndex % 2) == 0)
    {
      document.getElementById('ShotPickerImage1').src = Shots[ShotIndex][4].src;
      elementFadeIn('ShotPickerImage1');
    }
    else
    {
      document.getElementById('ShotPickerImage2').src = Shots[ShotIndex][4].src;
      elementFadeOut('ShotPickerImage1');
    }

    VisibleShotIndex = ShotIndex;
    
    loadNextImage(ChangeInterval);
  }
  else
  {
    timer = setTimeout('onChangeImage();', 100);
  }
}

function showHint()
{
  clearTimeout(timer);

  document.getElementById('ShotPickerPopupTitle').innerHTML = Shots[VisibleShotIndex][2];
  document.getElementById('ShotPickerPopupLabel').innerHTML = Shots[VisibleShotIndex][3];
  document.getElementById('ShotPickerPopupLink1').href = '/film/detail/' + Shots[VisibleShotIndex][0] + '.htm';
  document.getElementById('ShotPickerPopupLink2').href = '/film/moreshots.act?sanr=' + Shots[VisibleShotIndex][0];
  document.getElementById('ShotPickerPopup').style.visibility = 'visible';
}

function hideHint()
{
  timer = setTimeout('onChangeImage();', 2000);

  document.getElementById('ShotPickerPopup').style.visibility = 'hidden';
}

function shotClicked()
{
  document.location.href = '/film/moreshots.act?sanr=' + Shots[VisibleShotIndex][0];
}


