// fuer externe Links aus external.js, wird in opacity() aufgerufen
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 

var IE;
var weite;
function initSeite()
{

/* opacity('inhalt', 0, 100, 1000); */
externalLinks();

if (typeof darfScroll == "undefined")
  return;
 
scrollHeader();

IE = document.all?true:false;

if (!IE) document.captureEvents(Event.MOUSEMOVE)
 document.onmousemove = getMouseXY;

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  weite= myWidth;
}

var headposx=0;
var richtung=-1;
var scrollspeed=50;
var Step=1;

function scrollHeader()
{
 var obj = document.getElementById("header").style; 
 obj.backgroundPosition=headposx+'px';
 if ((tempY<150)&&(tempY>5))
 Step=Math.floor((0.8+((80-scrollspeed)/15.0)))*richtung;
 else
  {
   Step=-1;
   scrollspeed=50;
  }
 headposx+=Step;
 if (headposx<-6949)
   headposx=0;
 setTimeout(scrollHeader,scrollspeed);
}

var tempX;
var tempY;

function getMouseXY(e) {

if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  

/*
document.Show.MouseX.value = tempX;
document.Show.MouseY.value = tempY;
*/

if (tempY<150)
 scrollH();

}

function scrollH()
{
var wert=160.0*(tempX-(weite/2))/weite;
   scrollspeed=80-Math.abs(wert); 
   if (wert<0)
   richtung=1;
   else
   richtung = -1;
   
/*
    document.Show.Scroll.value = scrollspeed;
    document.Show.Step.value = Step;
*/
  

}



function closeObject(id)
{
   var thisObj = eval("document.getElementById('" + id + "').style");
   var ie;
 
   thisObj.visibility = "hidden";

 
}

  /* Array aller Bildernamen */
var namen=new Array("../grafiken/index/IMG_8388_Edit.jpg","../grafiken/index/IMG_7892_Edit.jpg");

  /* Definition des Bilder-Arrays */
var bilder=new Array();

function ladeindexbilder()
  /* Laedt die Bilder */
{
  var i;               
  for (i=0;i<2;i++)          
  {
    bilder[i]=new Image();   
    bilder[i].src=namen[i]; 
  }
}


function zeige(nr)
  /* zeigt ein Bild an */
{
  document.images[0].src=bilder[nr].src;
    /* Bild austauschen */
}


function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
    // fuer externe Links aus external.js
    externalLinks();

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


window.onload = initSeite;
