//-----------------------------------------------------------------------------
// In diesem Dokument stehen einige universell einsetzbare JavaScript-Funktinen
//
// Autor:     DI Stefan Valentin Baumgartner
// Copyright: DI Stefan Valentin Baumgartner
// Datum:     20. April 2009
//-----------------------------------------------------------------------------

// Datum und Zeit der letzten Änderung des Dokuments anzeigen (zentriert im Frame),
// von dem aus diese Funtion aufgerufen wird

// Datum der letzten Änderung der HTML-Datei anzeigen
function letzteAenderung(){
Datum = document.lastModified;
document.write("Letzte &Auml;nderung am " + Datum);
return 0;
}

// Zurück-Navigationslink zentriert im Frame einfügen
function zurueck(){
document.write("<div align='center'>&lt;&nbsp;<a href='javascript:history.back()'>Zur&uuml;ck zur vorherigen Seite</a>&nbsp;&gt;</div>");
return 0;
}

// Zurück-Navigationslink zentriert im Frame einfügen - eigener Text wird als Parameter übergeben werden
function zurueckText(text){
document.write("<div align='center'>&lt;&nbsp;<a href='javascript:history.back()'>" + text + "</a>&nbsp;&gt;</div>");
return 0;
}



// === Panorambild-Darstellung und Scrolling ==========================================================================

var i = 0;
var move_dir = 0;
var aktiv;
var PixelsPerSecond = '30'		/* speed of scrolling of panorama in pixels per second */


function stop_scrolling(){
  window.clearInterval(aktiv);
}

function scrolling(div_id,frameWidth,imageWidth){
  difference = Number(imageWidth)-Number(frameWidth);
  if (move_dir == 0){document.getElementById(div_id).style.backgroundPosition=-i+"px";i++;}
  if (move_dir == 1){document.getElementById(div_id).style.backgroundPosition=-i+"px";i--;}
  if (i == 0){move_dir=0;}
  if (i == difference){move_dir=1;}
}

function scroll_right(div_id,pixelPerSecond,imageWidth){
  stop_scrolling();
  var frameWidth = document.getElementById(div_id).offsetWidth;
  difference = Number(imageWidth)-Number(frameWidth);
  move_dir = 0;
  if (i == difference){move_dir = 1;}
  time_intervall = Math.round(1000/Number(pixelPerSecond));
  aktiv = window.setInterval(function(){scrolling(div_id,frameWidth,imageWidth);},time_intervall);
}

function scroll_left(div_id,pixelPerSecond,imageWidth){
  stop_scrolling();
  move_dir = 1;
  var frameWidth = document.getElementById(div_id).offsetWidth;
  if (i == 0){move_dir = 0;}
  time_intervall = Math.round(1000/Number(pixelPerSecond));
  aktiv = window.setInterval(function(){scrolling(div_id,frameWidth,imageWidth);},time_intervall);
}

function m_point(){
  document.body.style.cursor='pointer';
}

function m_auto(){
  document.body.style.cursor='auto';
}


function init(){

  div_id = document.getElementById("panorama");

  /* Preload background image and get image size */
  imageURL = document.getElementById("panorama").style.backgroundImage;
  first_index = imageURL.indexOf("(");
  last_index = imageURL.lastIndexOf(")");
  imageURL = imageURL.substring(first_index+2,last_index-1);
  
  bgImage = new Image();
  bgImage.src = imageURL;
  bgImageWidth = bgImage.width;
  bgImageHeight = bgImage.height;

  /* Navigationsbuttons zu Panorama hinzufügen  */
  var text = '<div style="position:absolute;bottom:5px;right:5px;">';
  text = text+'<img src="javascript/images/pfeil_links.gif" onclick="scroll_left'+"('panorama','"+PixelsPerSecond+"','"+bgImageWidth+"')"+';" onmouseover="m_point();" onmouseout="m_auto();" alt="links" style="vertical-align:middle;margin-right:5px;">';
  text = text+'<img src="javascript/images/stop.gif" onclick="stop_scrolling();" onmouseover="m_point();" onmouseout="m_auto();" alt="stop" style="vertical-align:middle;margin-right:5px;">';
  text = text+'<img src="javascript/images/pfeil_rechts.gif" onclick="scroll_right'+"('panorama','"+PixelsPerSecond+"','"+bgImageWidth+"')"+';" onmouseover="m_point();" onmouseout="m_auto();" alt="rechts" style="vertical-align:middle;">';
  text = text+'</div>'; 
  document.getElementById("panorama").innerHTML = text;
  
  /* Start scrolling */
  scroll_right('panorama',PixelsPerSecond,bgImageWidth);    
}
