var nSpeed = 10; // Geschwindigkeit in Millisekunden
var nFaktor = 6; // Delay Animation

var gX,gY;

var vgObjHistory;

var aHistrory = new Array();

window.onscroll = fWrXY;


function fCalcXY(vObj)
{
	//document.getElementById('debug').value = '';

  // objekt lesen
  var obj = document.getElementById(vObj);

  // stylesheet koordinaten lesen
  var objX = obj.style.left.replace('px','');
  var objY = obj.style.top.replace('px','');
  var objW = obj.style.width.replace('px','');

  objX = Math.round(Number(objX));
  objY = Math.round(Number(objY));


  // Bildschirmgroesse lesen
  var wH = window.innerHeight;
  var wW = window.innerWidth;

  // IE abfangen)
  if (isNaN(wH))
  {wH = document.documentElement.clientHeight;
   wW = document.documentElement.clientWidth;}

  // Ziel - Koordinaten berechnen
  var offset = (wW - objW) / 2;
  var x = Math.round(objX - offset + (wW/ 20));
  var y = Math.round(objY);

  // Ziel gloabl speichern
  gX = x;
  gY = y;

 }

function fHistoryAdd(vgObjHistory)
{
	var n = aHistrory.length;
	
	aHistrory[n] = vgObjHistory;
	
	//alert(n + " " + aHistrory[n]);
}

function fGetHist()
{
	
	
	if (aHistrory) 
	{
		var n = aHistrory.length;
		
		
		if (n>0) 
		{
			var objHistory = aHistrory[n-1];
			
			// letztes Element lšschen
			aHistrory.length = aHistrory.length -1;
			
			return objHistory;
		}
		
	}
	
	
	return 'seite'; 

}

function fMoveHist()
{
	fMove(fGetHist());
}

function fMove(vObj,vObjHist)
{
  gX = 0;
  gY = 0;

//  vgObjHistory = vObjHist;
  
  if(vObjHist)
  fHistoryAdd(vObjHist);

  //Koordinaten berrechnen und global speichern
  fCalcXY(vObj);



  // scrollen
  fScroll(gX,gY);

}

function fSwim(ObjHistory)
{
	
	fHistoryAdd(ObjHistory);
	
	
	var x = document.getElementById('surfX').value;
	var y = document.getElementById('surfY').value;

	//alert(x.length);

	if (x.length == 0 || y.length == 0)
	{
		alert('Beide Felder ausfuellen!');
		return false;
	}

	if (isNaN(x) || isNaN(y))
	{
		alert('Nur Zahlen eingeben!');
		return false;
	}

	// scrollen
 	fScroll(x,y);

}

function debug(t)
{
	document.getElementById('debug').value = document.getElementById('debug').value + '\n' + t;
}

function fJump(vObj)
{

  gX = 0;
  gY = 0;

  //Koordinaten berrechnen und gloabl speichern
  fCalcXY(vObj);

  //alert(gX+' '+gY);

  // Zur Position springen
  window.scrollTo(gX,gY);
}

function fScroll(vx,vy)
{
	var wX;
  	var wY;

   	var bX = false;
   	var bY = false;

   	var scrX;
   	var scrY;

   	// Firefox / Safari
  	if (window.pageYOffset) {
    	wX = window.pageXOffset;
    	wY = window.pageYOffset;
 	 }

 	// IE
 	if (isNaN(wX)) {
    	wY = document.documentElement.scrollTop;
    	wX = document.documentElement.scrollLeft;
  	}

	// Animiertes Scrollen
	// Gesamtstrecke jeweils durch 2
	scrX = Math.abs((vx-wX) / nFaktor);
	scrX = Math.round(scrX);
	if (scrX < 2 ) scrX = 1;

	scrY = Math.abs((vy-wY) / nFaktor);
	scrY = Math.round(scrY);
	if (scrY < 2 ) scrY = 1;

	if (wY < vy)
	{
		// nach oben

		if (wY < vy) {window.scrollBy(0, scrY);}
	}

	if (wY > vy)
  	{
  		// nach unten
		if (wY > vy) {window.scrollBy(0, scrY * -1);}
  	}

  	if (wX < vx)
	{
		// nach links
		if (wX < vx) {window.scrollBy(scrX,0);}
	}

	if (wX > vx)
  	{
  		// nach rechts
		if (wX > vx) {window.scrollBy(scrX * -1,0);}
  	}



  	if (wX == vx && wY == vy)
  	{
	//alert(wX + ' ' + wY);
	return true;}
  	else
  	{	//parent.back.fWrXY(wX,wY);
  		tScroll = setTimeout("fScroll(" + vx +"," + vy + ")", nSpeed);
  		}

  }


  function fWrXY()
  {
  	var wX;
  	var wY;


   	// Firefox / Safari
  	if (window.pageYOffset) {
    	wX = window.pageXOffset;
    	wY = window.pageYOffset;
 	 }

 	// IE
 	if (isNaN(wX)) {
    	wY = document.documentElement.scrollTop;
    	wX = document.documentElement.scrollLeft;
  	}

  	parent.back.fWrXY(wX,wY);

 }

 var bigpicWin = null;

function sImg(url, picwidth, picheight, description)
{
  if (!bigpicWin || bigpicWin.closed)
  {
    usrwidth = screen.width;
    usrheight = screen.height;

    winwidth = picwidth;
    winheight = picheight;

    var X = (usrwidth - winwidth) / 2;
    var Y = (usrheight - winheight) / 2;

    properties = "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width="+winwidth+",height="+winheight+",";

    checkie = navigator.appName.indexOf("icrosoft");
    if (checkie == -1)
    {
      properties = properties+"screenX="+X+",screenY="+Y;
    }
    else
    {
      properties = properties+"left="+X+",top="+Y;
    }

    bigpicWin = window.open('','bigpicWin',properties);

    bigpicWin.document.open();
    bigpicWin.document.write('<HTML><HEAD>');
    bigpicWin.document.write('<TITLE>klez.e</TITLE>');
    bigpicWin.document.write('</HEAD>');
    bigpicWin.document.write('<BODY MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN="0" TOPMARGIN="0" BOTTOMMARGIN="0">');
    bigpicWin.document.write('<A HREF="JavaScript:self.close()"><IMG SRC="'+url+'" HSPACE="0" VSPACE="0" BORDER="0" alt="FENSTER SCHLIESSEN !!!"></A>');
    bigpicWin.document.write('</BODY>');
    bigpicWin.document.write('</HTML>');
    bigpicWin.document.close()

    bigpicWin.focus();
  }
  else
  {
    bigpicWin.focus();
  }
}