/* JavaScript */
/* für ricochet-Website */
/* mul, 03.02.2010 */

// Status-Array zur Kontrolle der Animationen
// 0 -> aus, 1-> an, -1 -> gesperrt
var arr_status = Array();

function setStatus(id, value) {
	arr_status[id] = value;
	return true;
}

function anmelden(id) {
	if(typeof arr_status[id] == "undefined") {
		//arr_status[id] = 0;
		setStatus(id, 0);
	}
	return true;
}


// Animierter Wechsel "Wir schaffen..." auf Home
var arr_schoepfung = Array();
arr_schoepfung[0] = 'werte';
arr_schoepfung[1] = 'image';
arr_schoepfung[2] = 'bekanntheit';
arr_schoepfung[3] = 'nachhaltigkeit';
arr_schoepfung[4] = 'umsatz';
var schaffencnt = 0;
var nextschaffen = 0;
function animateSchoepfung() {
	if (schaffencnt % 2) {
		document.getElementById("schoepfung2").src = "/fileadmin/ricochet-2010/pics/wir-schaffen-"+arr_schoepfung[nextschaffen]+".png";
		document.getElementById("schoepfung2").alt = arr_schoepfung[nextschaffen].capitalize()+".";
		new Effect.Parallel(
			[
				new Effect.Opacity('schoepfung1', {
					duration: 1.0,
					transition: Effect.Transitions.linear,
					from: 1.0,
					to: 0.0
				} ),
				new Effect.Opacity('schoepfung2', {
					duration: 1.0,
					transition: Effect.Transitions.linear,
					from: 0.0,
					to: 1.0
				} )
			],
			{
				duration: 1.0
			}
		);
		schaffencnt++;
	}
	else {
		document.getElementById("schoepfung1").src = "/fileadmin/ricochet-2010/pics/wir-schaffen-"+arr_schoepfung[nextschaffen]+".png";
		document.getElementById("schoepfung1").alt = arr_schoepfung[nextschaffen].capitalize()+".";
		new Effect.Parallel(
			[
				new Effect.Opacity('schoepfung1', {
					duration: 1.0,
					transition: Effect.Transitions.linear,
					from: 0.0,
					to: 1.0
				} ),
				new Effect.Opacity('schoepfung2', {
					duration: 1.0,
					transition: Effect.Transitions.linear,
					from: 1.0,
					to: 0.0
				} )
			],
			{
				duration: 1.0
			}
		);
		schaffencnt--;
	}
	nextschaffen++;
	if (nextschaffen > 4) {
		nextschaffen = 0;
	}
  setTimeout("animateSchoepfung()", 3500);
}

function setVisible(id) {
	document.getElementById(id).style.visibility = "visible";
	document.getElementById(id).setAttribute("zindex", "10");
}
function setInvisible(id) {
	document.getElementById(id).style.visibility = "hidden";
	document.getElementById(id).setAttribute("zindex", "-1");
	//document.getElementById(id).style.zindex = "-1";
}


// Hochspringen der Navigationspunkt auf den Kopfseiten
// wie hoch die ausgewählten Elemente "springen"
var sprunghoehe = 30;

function jumpUp(id) {
	anmelden(id);
	if (arr_status[id] == 0) {
	    var height = document.getElementById(id).getHeight();
		//var factor = parseInt(eval(((height + sprunghoehe)/height) * 100));
		var factor = parseInt(Math.round(eval(((height + sprunghoehe)/height) * 100)));
		new Effect.Parallel(
			[
				new Effect.MoveBy(document.getElementById(id), -30, 0, {
					transition: Effect.Transitions.sinoidal,
					beforeStart: function() {setStatus(id, -1);},
					afterFinish: function() {setStatus(id, 1);}
				} ),
				new Effect.Scale(id, factor, {
					scaleX:false,
					scaleContent:false
				} )
			],
			{
				duration: 0.3
			}
		);
	}
}

function jumpDown(id) {
	anmelden(id);
	if (arr_status[id] == 1) {
	    var height = document.getElementById(id).getHeight();
		//var factor = parseInt(eval(((height - sprunghoehe)/height) * 100));
		var factor = parseInt(Math.round(eval(((height - sprunghoehe)/height) * 100)));
		new Effect.Parallel(
			[
				new Effect.MoveBy(document.getElementById(id), 30, 0, {
					transition: Effect.Transitions.sinoidal,
					beforeStart: function() {setStatus(id, -1);},
					afterFinish: function() {setStatus(id, 0);}
				} ),
				new Effect.Scale(id, factor, {
					scaleX:false,
					scaleContent:false
				} )
			],
			{
				duration: 0.3
			}
		);
	}
}
function jumpDownWait(id) {
	anmelden(id);
	if (arr_status[id] == 1) {
	    jumpDown(id);
	}
	else if (arr_status[id] == -1) {
        setTimeout('jumpDown("'+id+'")', 1000);
	}
}


// MouseOver-Effekte für Unternavigation
function naviMouseover(id) {
	anmelden(id);
	if (arr_status[id] == 0) {
	    new Effect.Morph(id, {
			style:'background-position:218px bottom;',
			duration: 0.3,
			beforeStart: function() {setStatus(id, -1);},
			afterFinish: function() {setStatus(id, 1);}
			}
		);
	}
}
function naviMouseout(id) {
	anmelden(id);
	if (arr_status[id] == 1) {
	    new Effect.Morph( id, {
			style:'background-position:241px bottom;',
			duration: 0.3,
			beforeStart: function() {setStatus(id, -1);},
			afterFinish: function() {setStatus(id, 0);}
			}
		);
	}
}
function naviMouseoverAndOut(id) {
	anmelden(id);
	if (arr_status[id] == 0) {
	    new Effect.Morph(id, {
			style:'background-position:218px bottom;',
			duration: 0.3,
			beforeStart: function() {setStatus(id, -1);},
			afterFinish: function() { setStatus(id, 1); setTimeout('naviMouseout("'+id+'")', 1000);  }
			}
		);
	}
}
function naviMouseoutWait(id) {
	anmelden(id);
	if (arr_status[id] == 1) {
	    naviMouseout(id);
	}
	else {
        setTimeout('naviMouseoutWait("'+id+'")', 1000);
	}
}
// Scrollfunktion für überlange Inhalte
var scrollStep = 550;
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

function pageUp() {
    var id = 'scrollbar';
	if (document.getElementById(id).style.top == "") {
		return;
	}
	var topwert = parseInt(document.getElementById(id).style.top);
	
	//alert(topwert);
	if (topwert >= 0) {
		return;
	}
	if (arr_status[id] == 0) {
		new Effect.MoveBy(document.getElementById(id), scrollStep, 0, {
			transition: Effect.Transitions.sinoidal,
			duration:1.3,
			beforeStart: function() {setStatus(id, 1);},
			afterFinish: function() {checkButtons(); setStatus(id, 0);}
		} );
	}
	//checkButtons();
}
function pageDown() {
    var id = 'scrollbar';
	var topwert = parseInt(document.getElementById(id).style.top);
    var div_hoehe = getObjectHeight(document.getElementById(id));
    //alert(max_hoehe+" "+topwert);
	var max_topwert = (div_hoehe * -1) + scrollStep;
	//alert(max_topwert+" "+topwert);
    if (max_topwert > topwert) {
		return;
	}
	if (arr_status[id] == 0) {
		new Effect.MoveBy(document.getElementById(id), (-1 * scrollStep), 0, {
			transition: Effect.Transitions.sinoidal,
			duration:1.3,
			beforeStart: function() {setStatus(id, 1);},
			afterFinish: function() {checkButtons(); setStatus(id, 0);}
		} );
	}
	//checkButtons();
}
function checkButtons() {
    var id = 'scrollbar';
    var elem = getRawObject(document.getElementById(id));
    //alert(typeof(elem));
    //alert(elem);
    if (elem == null) {
        //alert("elem == null");
        return true;
	}
	anmelden(id);
    //alert(topwert);
    // div einen Topwert geben, falls noch nicht vorhanden
    var topwert = document.getElementById(id).style.top;
	//alert(topwert+" "+typeof(topwert));
	if (topwert == "") {
		topwert = 0;
	}
	else {
		topwert = parseInt(topwert);
	}
    var div_hoehe = getObjectHeight(document.getElementById(id));
	var max_topwert = scrollStep - div_hoehe;
	//var min_topwert = (-1 * scrollStep);
	var min_topwert = 0;
    //alert("div_hoehe: "+div_hoehe+"\ntopwert: "+topwert+"\nmax_topwert: "+max_topwert+"\nmin_topwert: "+min_topwert);
	//alert(max_topwert+" "+topwert);
	var downvis = "visible";
	var downdis = "block";
	var upvis = "visible";
	var updis = "block";
    if (topwert < max_topwert) {
		downvis = "hidden";
		downdis = "none";
	}
	if (topwert >= min_topwert) {
		upvis = "hidden";
		updis = "none";
	}
	document.getElementById('downBut').style.visibility = downvis;
	document.getElementById('downBut').style.display = downdis;
	document.getElementById('upBut').style.visibility = upvis;
	document.getElementById('upBut').style.display = updis;
	return true;
}