/*
xajax.loadingFunction = function(){xajax.$('loadingMessage').style.display='block';};
function hideLoadingMessage()
{
	xajax.$('loadingMessage').style.display = 'none';
}
xajax.doneLoadingFunction = hideLoadingMessage;
*/

function anfang() 
{
    xajax_startup('body');
    return false;
}

lastupd_menschen = "25.01.2009";
lastupd_tiere = "25.08.2007";
lastupd_sensationen = "25.01.2009"; //MAX von testfotos, sonne, wolken, unterwegs, nightshots...
	lastupd_sonsteso = "25.01.2009";
	lastupd_dachboden = "15.05.2008";
	lastupd_berlin = "25.01.2009";
	lastupd_madrid2007 = "20.02.2007";
    lastupd_weststrand = "15.05.2008";
    lastupd_domrep = "28.08.2007";
    lastupd_lissabon = "10.12.2007";
    lastupd_madrid2008 = "23.04.2008";
    lastupd_malediven = "29.04.2008";
    lastupd_london = "25.01.2009";
lastupd_flora = "23.04.2008";
	lastupd_landschaft = "10.12.2007";
	lastupd_pflanzen = "23.04.2008";

function updates(wo)
{
	if(wo=='start') {
		document.getElementById('lu1').innerHTML = lastupd_menschen;
		document.getElementById('lu2').innerHTML = lastupd_tiere;
		document.getElementById('lu3').innerHTML = lastupd_sensationen;
		document.getElementById('lu4').innerHTML = lastupd_flora;
	}
	
	if(wo=='sensationen') {
		document.getElementById('lu1').innerHTML = lastupd_sonsteso;
		document.getElementById('lu2').innerHTML = lastupd_dachboden;
		document.getElementById('lu4').innerHTML = lastupd_berlin;
		document.getElementById('lu6').innerHTML = lastupd_madrid2007;
		document.getElementById('lu7').innerHTML = lastupd_weststrand;
		document.getElementById('lu8').innerHTML = lastupd_domrep;
		document.getElementById('lu9').innerHTML = lastupd_lissabon;
		document.getElementById('lu10').innerHTML = lastupd_madrid2008;
		document.getElementById('lu11').innerHTML = lastupd_malediven;
		document.getElementById('lu12').innerHTML = lastupd_london;
	}

	if(wo=='flora') {
		document.getElementById('lu1').innerHTML = lastupd_landschaft;
		document.getElementById('lu2').innerHTML = lastupd_pflanzen;
	}
	
}

function switch_player(galerie,onoff)
{
    if(onoff==1){
        document.getElementById(galerie+'link').rel=0;
        document.getElementById(galerie+'link2').rel=0;
        document.getElementById(galerie+'switch').src='content/images/musik_aus.jpg';
    } else {
        document.getElementById(galerie+'link').rel=1;
        document.getElementById(galerie+'link2').rel=1;
        document.getElementById(galerie+'switch').src='content/images/musik_an.jpg';
    }
}

function nav(zeig)
{
	histAjax.loadNextBookmark(zeig);
}

function HistAjax() {
	this.loadNextBookmark = function(z) {
		unFocus.History.addHistory(z);
        xajax_server(z,'ja');
	};
	
	this.historyListener = function(historyHash) {
		if (historyHash) {
            xajax_server(historyHash,'nein');
            if(schonmaloffen!=0){
                myLightbox.end();
            }
 		}
	};
	
	unFocus.History.addEventListener('historyChange', this.historyListener);

	this.historyListener(unFocus.History.getCurrent());
}

function mailme(was)
{
	if(was=='auf')
	{
        if (window.removeEventListener){window.removeEventListener('DOMMouseScroll', wheel, false);}
        window.onmousewheel = document.onmousewheel = parent.onmousewheel = nowheel;
        hideFlash();
		document.getElementById('semitransparent').style.display = 'block';
		document.getElementById('diviframe').style.display = 'block';
		document.getElementById('diviframe').innerHTML = '<iframe src="content/form.php" allowtransparency="true" frameborder="0"></iframe>';
	}
	
	if(was=='zu')
	{
        if (window.addEventListener){window.addEventListener('DOMMouseScroll', wheel, false);}
        window.onmousewheel = document.onmousewheel = parent.onmousewheel = wheel;
        showFlash();
		top.document.getElementById('semitransparent').style.display = 'none';
		top.document.getElementById('diviframe').style.display = 'none';
		top.document.getElementById('diviframe').innerHTML = '';
	}
	
}

function rein(inwas)
{
	if(inwas==1)
	{
		if(document.getElementsByName('wer')[0].value==dWer){
			document.getElementsByName('wer')[0].value='';}
	}
	
	if(inwas==2)
	{
		if(document.getElementsByName('mail')[0].value==dMail){
			document.getElementsByName('mail')[0].value='';}
	}
	
	if(inwas==3)
	{
		if(document.getElementsByName('was')[0].innerHTML==dWas){
			document.getElementsByName('was')[0].innerHTML='';}
	}
}

function raus(outwas)
{
	if(outwas==1)
	{
		if(document.getElementsByName('wer')[0].value==''){
			document.getElementsByName('wer')[0].value=dWer;}
	}
	
	if(outwas==2)
	{
		if(document.getElementsByName('mail')[0].value==''){
			document.getElementsByName('mail')[0].value=dMail;}
	}
	
	if(outwas==3)
	{
		if(document.getElementsByName('was')[0].innerHTML==''){
			document.getElementsByName('was')[0].innerHTML=dWas;}
	}

	if(outwas==4)
	{
		mailme('zu');
	}
}

var upH = 15; 
var upW = 25; 
var downH = 15; 
var downW = 25; 
var dragH = 7; 
var dragW = 7; 
var scrollH = 380; 
var speed = 9; 

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()


function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='hidden'
}

function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='visible'
}
	
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar

var timer = setTimeout("",500); // Repeat variable
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var inhaltT; // inhalt layer Y;
var inhaltH; // inhalt height
var contentMaskH; // inhalt clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span

// Mousedown
function down(e){
	//this line was hindering scrollbar to work in Opera
	//if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton

	getMouse(e);
	startY = (mouseY - dragT);
	
	// If click on up-arrow
	if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
		clickUp = true;
		return scrollUp();
	}	
	// Else if click on down-arrow
	else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
		clickDown = true;
		return scrollDown();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
		// If click above drag
		if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		}
		// Else click below drag
		else{
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){
	if(clickDrag && inhaltH > contentMaskH){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		inhaltT = ((dragT - rulerT)*(1/scrollLength));
		inhaltT = eval('-' + inhaltT);

		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie4)
			return false;
	}
}

function up(){
	clearTimeout(timer);
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}

// Reads inhalt layer top
function getT(){
	if(ie4)
		inhaltT = document.all.inhalt.style.pixelTop;
	else if(nn4)
		inhaltT = document.contentMask.document.inhalt.top;
	else if(dom)
		inhaltT = parseInt(document.getElementById("inhalt").style.top);
}

// Reads mouse X and Y coordinates
function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
}

// Moves the layer
function moveTo(){
	if(ie4){
		document.all.inhalt.style.top = inhaltT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(nn4){
		document.contentMask.document.inhalt.top = inhaltT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(dom){
		document.getElementById("inhalt").style.top = inhaltT + "px";
		document.getElementById("drag").style.top = dragT + "px";
		document.getElementById("ruler").style.top = dragT + "px";
	}
}

// Scrolls up
function scrollUp(){
	getT();
	
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
		if(inhaltT < 0){		
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			inhaltT = inhaltT + speed;
			if(inhaltT > 0)
				inhaltT = 0;
			
			moveTo();
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

// Scrolls down
function scrollDown(){
	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();
	}

	if(clickDown){
		if(inhaltT > -(inhaltH - contentMaskH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			inhaltT = inhaltT - speed;
			if(inhaltT < -(inhaltH - contentMaskH))
				inhaltT = -(inhaltH - contentMaskH);
			
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload
function eventLoader(){
	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.up.style.pixelLeft;
		upT = document.all.up.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.down.style.pixelLeft;
		downT = document.all.down.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.drag.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop;		
		// Ruler Y variable
		rulerT = document.all.ruler.style.pixelTop;		
		// Height of inhalt layer and clip layer
		inhaltH = parseInt(document.all.inhalt.scrollHeight);
		contentMaskH = parseInt(document.all.contentMask.style.height);
	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.up.left;
		upT = document.up.top;		
		// Down-arrow X and Y variables
		downL = document.down.left;
		downT = document.down.top;		
		// Scrollbar X and Y variables
		dragL = document.drag.left;
		dragT = document.drag.top;		
		// Ruler Y variable
		rulerT = document.ruler.top;
		// Height of inhalt layer and clip layer
		inhaltH = document.contentMask.document.inhalt.clip.bottom;
		contentMaskH = document.contentMask.clip.bottom;
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").offsetLeft);
		upT = parseInt(document.getElementById("up").offsetTop);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").offsetLeft);
		downT = parseInt(document.getElementById("down").offsetTop);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").offsetLeft);
		dragT = parseInt(document.getElementById("drag").offsetTop);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("ruler").offsetTop);
		// Height of inhalt layer and clip layer
		inhaltH = parseInt(document.getElementById("inhalt").offsetHeight);
		contentMaskH = parseInt(document.getElementById("contentMask").offsetHeight);
		document.getElementById("inhalt").style.top = 0 + "px";
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(inhaltH-contentMaskH));
    if(scrollLength<=0){
        document.getElementById("up").style.visibility='hidden';
        document.getElementById("down").style.visibility='hidden';
        document.getElementById("drag").style.visibility='hidden';
        document.getElementById("bg").style.visibility='hidden';
        document.getElementById("ruler").style.visibility='hidden';
    } else {
        document.getElementById("up").style.visibility='visible';
        document.getElementById("down").style.visibility='visible';
        document.getElementById("drag").style.visibility='visible';
        document.getElementById("bg").style.visibility='visible';
        document.getElementById("ruler").style.visibility='visible';    
    }
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
}

/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta)
{
	if (delta > 0)
	{
		//alert("up");
		clickUp = true;
		scrollUp();
		scrollUp();
		scrollUp();
		clickUp = false;
	}
  else
  {
		//alert("down");
		clickDown = true;
		scrollDown();
		scrollDown();
		scrollDown();		
		clickDown = false;
	}
}

/** Event handler for mouse wheel event.

 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

function nowheel(){
    return false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = parent.onmousewheel = wheel;
