// --------------------------------------------------------
// mendelssohn-dessau.de javascript library 
//
// laste edited: 2007/11/22
//
// Tobias Stoeber <stoeber@softclick-it.de>
// --------------------------------------------------------

// ------------------------------------
// debugging
// ------------------------------------

var debug = 0;

// ********************************************************
// setFocus (1 = focus on search input field in top)
// ********************************************************
setFocus = 1;

// ********************************************************
// empty function
// ********************************************************
function empty() {}

// ********************************************************
// mouse position
// ********************************************************

var p_height = window.innerHeight;
p_height = (isNaN(p_height) ? parseInt(document.body.clientHeight) : p_height) - 10;

var p_width = window.innerWidth;
p_width = (isNaN(p_width) ? parseInt(document.body.clientWidth) : p_width) - 10;

var mouseX = 0;
var mouseY = 0;

function mousePos(e)
{
	if ( !e )
	  e = window.event;

	mouseX = e.clientX;	
	mouseY = e.clientY;	
}

document.onmousemove=mousePos;

function calcMousePos(x,y,myobjid)
{
	var myobj = document.getElementById(myobjid);

	var o_top = parseInt(myobj.style.top);
	var o_left = parseInt(myobj.style.left);
	var o_width = parseInt(myobj.style.width);
	var o_height = parseInt(myobj.style.height);

	// debugging only
        if ( debug )
	  alert( 'Page: ' + p_width + 'x' + p_height + "\n" + "Obj: " + o_left + ' x ' + o_top + ' - ' + o_width + ' x ' + o_height );

	// adjust x 
	var mousePosX = mouseX;
	var maxPosX = p_width - o_width - 30;

	var dbg = '';
	if ( debug )
	  dbg = "MaxX: " + maxPosX + " MouseX:" + mousePosX + " ObjX: " + o_width + " PageX: " + p_width +"\n";

	while ( (mousePosX > maxPosX) && (mousePosX > 10))
	{
		if ( debug )
		  dbg += "Mouse X: " + mousePosX + "\n";
		mousePosX -= 10;
	}

	// adjust y
	var mousePosY = mouseY + 15;
	var maxPosY = p_height - o_height - 30;

	if ( debug )
	  dbg += "MaxY: " + maxPosY + " MouseY:" + mousePosY + " ObjY: " + o_height + " PageY: " + p_height +"\n";

	while ( (mousePosY > maxPosY) && (mousePosY > 10))
	{
		if ( debug )
		  dbg += "Mouse Y: " + mousePosY + "\n";

		mousePosY -= 10;
	}

	if ( debug )
	  dbg += "Final Mouse: " + mousePosX + "x" + mousePosY + "\n";

	myobj.style.left = (mousePosX - 50);
	myobj.style.top = mousePosY;

	if ( debug )
	  dbg += "Final Div Pos: " + myobj.style.left + "x" + myobj.style.top + "\n";

	// debugging only
	if ( debug )
	  alert(dbg);
}


// ********************************************************
// change visibility of objects
// ********************************************************
function changeVisibility(objID) {

  if ( document.getElementById(objID).style.visibility == "visible" )
  {
    // alert(objID + ' is visible');
    document.getElementById(objID).style.visibility = "hidden";
    document.getElementById(objID).style.display = "none";
  }
  else
  {
    // alert(objID + ' is hidden');
    document.getElementById(objID).style.visibility = "visible";
    document.getElementById(objID).style.display = "inline";
  }
}

// ********************************************************
// change image in right columns of 3-column template
// ********************************************************

function browseRightImage(imgURL, imgHeadline) {

  // load image by setting url
  document.imgRight.src = imgURL;

  // exchange alternativ text (alt attrib)
  document.imgRight.alt = imgHeadline;

  // exchange title (title attrib)
  document.imgRight.title = imgHeadline;

}

// ********************************************************
// change image in navigation level 1
// ********************************************************

function changeImgNav(imgId, imgURL, act, iCnt) {

  // get object
  imgObj = document.getElementById(imgId);
  aObj = document.getElementById('navldiv');

  // load image by setting url
  imgObj.src = imgURL;

  // debuggin only
  window.status = 'Pos Y: (' + mouseX + ',' + mouseY + ') / ' + iCnt; 

  if ( act == 'out' )
  {
    aObj.style.backgroundPosition = "0px 0px";
  }
  else
  {
    aObj.style.backgroundPosition = "0px " + ((iCnt - 1) * 34) + "px";
  }
}

// ********************************************************
// change image
// ********************************************************

function changeImg(imgId, imgURL) {

  // get object
  imgObj = document.getElementById(imgId);

  // load image by setting url
  imgObj.src = imgURL;
}

// Javascript-Funktion zu Oeffnen eines Popupfenster
// (C) 2000-2002 T. Stoeber <tobi@to-st.de>
//
// Fenster ohne MenuBar, Toolbar, Groesse aendernbar, zentriert
// NS ab 4.x, MSIE ab 4.x, andere Mozilla compatible ab 4.x
//
// Parameter:
// URL der zu oeffnenden Seite
// Breie des Fensters (Aussen) in px
// Hoehe des Fenster (Aussen) in px

function PopWin(URL,winName,BX,BY)
{
  var PopWnd;

  if ((navigator.appVersion.substring(0,3) >= 4.0 && navigator.appName == 'Netscape') ||
      (navigator.appVersion.substring(0,3) >= 4.0 && navigator.appName.substring(0,9) == 'Microsoft') ||
      (navigator.appVersion.substring(0,3) >= 4.0 && navigator.appCodeName == 'Mozilla'))
  {
    if ( PopWnd && PopWnd.closed == false )
    {
      PopWnd.document.location.href = URL;
      PopWnd.moveTo( (screen.width - BX) / 2, (screen.height - BY) / 2);
      PopWnd.focus();
    }
    else
    {
       var AFR = "width=" + BX + ",height=" + BY + ",menubar=no,resizable=yes,toolbar=no,scrollbars=yes,status=yes,dependent=yes";
       PopWnd = window.open(URL, winName, AFR);
       PopWnd.moveTo( (screen.width - BX) / 2, (screen.height - BY) / 2);
       PopWnd.focus();
    }
  }
  else
  {
    // aeltere und andere Browser minimale Variante,
    PopWnd = window.open(URL, winName, "width=" + BX + ",height=" + BY);
  }
}

function PopWinImgShop(URL,winName,BX,BY)
{
  var PopWndImg;

  if ((navigator.appVersion.substring(0,3) >= 4.0 && navigator.appName == 'Netscape') ||
      (navigator.appVersion.substring(0,3) >= 4.0 && navigator.appName.substring(0,9) == 'Microsoft') ||
      (navigator.appVersion.substring(0,3) >= 4.0 && navigator.appCodeName == 'Mozilla'))
  {
    if ( PopWndImg && PopWndImg.closed == false )
    {
      PopWndImg.focus();
      PopWndImg.resizeBy(10,10);;
      PopWndImg.moveTo( (screen.width - BX) / 2, (screen.height - BY) / 2);

      PopWndImg.document.getElementById('image').src = URL;
    }
    else
    {
       var AFR = "width=" + BX + ",height=" + BY + ",menubar=no,resizable=yes,toolbar=no,scrollbars=no,status=no,dependent=yes";
       PopWndImg = window.open('about:blank', winName, AFR);
       PopWndImg.moveTo( (screen.width - BX) / 2, (screen.height - BY) / 2);
       PopWndImg.focus();

       PopWndImg.document.open();
       PopWndImg.document.write('<body style="margin:0px;bgcolor:#ACACAC;">');
       PopWndImg.document.write('<div style="height:' + BY + 'px;width:' + BX + 'px;text-align:center;vertical-align:middle;">');
       PopWndImg.document.write('<img src="' + URL + '" id="image" onClick="self.close();">');
       PopWndImg.document.write('</div>');
       PopWndImg.document.write('</body>');
       PopWndImg.document.close();
    }
  }
  else
  {
    // aeltere und andere Browser minimale Variante,
    PopWndImg = window.open('about:blank', winName, "width=" + BX + ",height=" + BY);

    PopWndImg.document.open();
    PopWndImg.document.write('<body style="margin:0px;bgcolor:#ACACAC;">');
    PopWndImg.document.write('<div style="height:' + BY + 'px;width:' + BX + 'px;text-align:center;vertical-align:middle;">');
    PopWndImg.document.write('<img src="' + URL + '" id=\"image\">');
    PopWndImg.document.write('</div>');
    PopWndImg.document.write('</body>');
    PopWndImg.document.close();
  }
}




// function to change statusline

function changeStatusLine(lineText)
{
  // alert(lineText);
  window.status = lineText;
  // window.defaultStatus = '';
  return true;
}

// class Page

function Page()
{
  // Properties
  // has no properties
  // Methods

  this.Height = function()
  {
    var Height = window.innerHeight;
    Height = (isNaN(Height) ? document.body.clientHeight : Height) - 4;
    return Height;
  }

  this.Width = function()
  {
    var Width = window.innerWidth;
    Width = (isNaN(Width) ? document.body.clientWidth : Width) - 4;
    return Width;
  }

  this.Top = function()
  {
    var Top = window.pageYOffset;
    Top = (isNaN(Top) ? document.body.scrollTop: Top);
    return Top;
  }

  this.Left = function()
  {
    var Left = window.pageXOffset;
    Left = (isNaN(Left) ? document.body.scrollLeft: Left);
    return Left;
  }
}


