/* 
__     __                                           _
\ \   / /                                          | |
 \ \_/ /__  _   _ _ __ _ __   __ _  __ _  ___   ___| |__
  \   / _ \| | | | '__| '_ \ / _` |/ _` |/ _ \ / __| '_ \
   | | (_) | |_| | |  | |_) | (_| | (_| |  __/| (__| | | |
   |_|\___/ \__,_|_|  | .__/ \__,_|\__, |\___(_)___|_| |_|
                      | |           __/ |
                      |_|          |___/

Yourpage.ch System
mit Prototype Framework
und script.aculo.us

(c) 2008/2009 by Stefan Oechslein
*/
var dauer = 0.5;
var dynwidth;
var btnhoverimage = new Image();
var currentpage = 'home';
var position = 0;
var mw;
var mt;

function page(pageID) {
	/*new Effect.Pulsate('contentdiv',{duration:dauer, pulses:1});*/
	document.location.hash = "#" + pageID;
	currentpage = pageID;
	new Effect.Morph('contentdiv', {style: 'opacity: 0.2;', duration: dauer, queue:'front', afterFinish: function () {
		reqc(pageID);
		$('currentpagetitle').src = 'img/titel/yourpage-' + currentpage + '.jpg';
		$('home').style.backgroundImage = 'url(../img/icon_normal.jpg)';
		$('ueberuns').style.backgroundImage = 'url(../img/icon_normal.jpg)';
		$('projekte').style.backgroundImage = 'url(../img/icon_normal.jpg)';
		$('kontakt').style.backgroundImage = 'url(../img/icon_normal.jpg)';
		$('agb').style.backgroundImage = 'url(../img/icon_normal.jpg)';
		$(currentpage).style.backgroundImage = 'url(../img/icon_gelb.jpg)';
		new Effect.Morph('contentdiv', {style: 'opacity: 1.0;', duration: dauer, queue:'last' });
		/*if(pageID=='ueberuns'){
			var scrwidth = 1500;
			setTimeout('scrolleffect('+scrwidth+', 25);', 300);
		}*/
		window.scrollTo(0,0);
		/*if (position != 500) {
                position++;
                scroll(0,position);
                clearTimeout(timer);
                var timer = setTimeout("scroller()",44); timer;
        }*/
		//setcontentheight();
	}});	
	/*
	$('home').style.backgroundImage = 'url(img/icon_normal.jpg)'; 
	$('ueberuns').style.backgroundImage = 'url(img/icon_normal.jpg)'; 
	$('projekte').style.backgroundImage = 'url(img/icon_normal.jpg)'; 
	$('kontakt').style.backgroundImage = 'url(img/icon_normal.jpg)'; 
	$(pageID).style.backgroundImage = 'url(img/icon_gruen.jpg)'; */
	
	
	/*new Effect.Fade('contentdiv',{duration:dauer, from:1.0, to:0.5});
	new Effect.BlindUp('contentdiv',{duration:dauer});
	reqc(pageID);
	new Effect.BlindDown('contentdiv',{duration:dauer});
	new Effect.Appear('contentdiv',{duration:dauer, from:0.5, to:1.0});*/
}
function pageopen(){
	$('layoutdiv').setStyle({width:'0px', height:'0px', overflow:'auto'});
	new Effect.Morph('layoutdiv', {style:'width:89%; height:100%; overflow:visible', duration:2, queue:'front'});
}
function startredirect(){
	setTimeout('glowindex()', 20000);
}
function initindex(){
	new Effect.Appear('augegruen', { duration: 0, queue:'front'});
	new Effect.Opacity('augegruen', { from: 0, to: 0, duration: 0, queue:'last'});
	$('ired').style.display = 'inline';
	$('itbl').style.display = 'inline';
	$('augenormal').style.cursor = 'pointer';
	$('scrolldiv').style.marginLeft = '0px';
	alignpage(750);
	scrolleyes();
	startredirect();
}
function glowindex(){
	new Effect.Opacity('augegruen', { from: 0, to: 1.0, duration: 1, queue:'front'});
	new Effect.Opacity('augegruen', { from: 1.0, to: 0, duration: 1, queue:'last', afterFinish:function(){document.location.href = "index3.php#home"}});
}
function glowhome(){
	new Effect.Opacity('augegreen', { from: 0, to: 1.0, duration: 1, queue:'front'});
	new Effect.Opacity('augegreen', { from: 1.0, to: 0, duration: 1, queue:'last'});
	page('home');
}
function initpage(){
	new Effect.Appear('augegreen', { duration: 0, queue:'front'});
	new Effect.Opacity('augegreen', { from: 0, to: 0, duration: 0, queue:'last'});
	/*page('home');*/
	hashURL();  //HashURL aufrufen
	initbuttons();  //Buttons initialisieren
	alignpage(900);
	Event.observe(window, 'resize', function() {  //Prüfen ob die Fenstergrösse geändert wurde
  		alignpage(900);   //...Und neue grösse einstellen
	});
	new PeriodicalExecuter(hashDiff, 0.5); //Prüfen, ob sich die URL geändert hat
}

function initbuttons(){
	var btnnames = new Array();
	btnnames[0] = "home";
	btnnames[1] = "ueberuns";
	btnnames[2] = "projekte";
	btnnames[3] = "kontakt";
	btnnames[4] = "agb";
	btnhoverimage.src = "../img/icon_gelb.jpg"; //Hoverbild preloaden
	
	var i = 0;
	for(i=0; i<btnnames.length; i++){
		$(btnnames[i]).observe('mouseover', function(event){ //Mouseover Handler hinzufügen
			if(Event.element(event).id != currentpage){
				$(Event.element(event).id).style.backgroundImage = 'url(../img/icon_gelb.jpg)';
			}
		});	
		$(btnnames[i]).observe('mouseout', function(event){ //Mouseout Handler hinzufügen
			if(Event.element(event).id != currentpage){
				$(Event.element(event).id).style.backgroundImage = 'url(../img/icon_normal.jpg)';
			}
		});
		$(btnnames[i]).observe('click', function(event){ //Clickhandler hinzufügen
			page(Event.element(event).id);
		});
	}
}

function hashDiff(){
	var currenthash = '#' + currentpage;
	if (currenthash !== document.location.hash){
		hashURL();
	}
}

function hashURL(){
	if(document.location.hash === "" ){
    	document.location.hash = "#home";
		page('home');
    }else{
		var pagename = document.location.hash.replace(/^.*#/, '');
		page(pagename);
	}
}

function scrolleffect2(myWidth, myTime){
	new Effect.Morph('scrolldiv', {style: 'margin-left:-'+myWidth+'px;', duration: myTime, afterFinish:function(){
																alert(myWidth+" "+myTime);
																new Effect.Morph('scrolldiv', {style: 'margin-left:0px;', duration: myTime, afterFinish:scrolleffect(myWidth, myTime)});							
																}
																});
}
function scrolleffect(myWidth, myTime){
	mw = myWidth;
	mt = myTime;
	new Effect.Morph('scrolldiv', {style: 'margin-left:-'+myWidth+'px;', duration: myTime, queue:'front'});
}
function scrolleyes(){
	new Effect.Morph('scrolldiv', {style: 'left:-1400px;', duration: 25});
}
function setscrollerwidth(){
	$('namebox').setStyle({width: dynwidth});
	$('cloakdiv').setStyle({width: dynwidth});
	$('fadediv').setStyle({width: dynwidth});
}
function setcontentheight(){
	var bodyheight = window.innerHeight;
	var dynheight = $('contenttd').getStyle('height');
	$('contentdiv').setStyle({height: bodyheight});

}
function alignpage(contentpx){
	var scrw = (typeof window.innerWidth != 'undefined' ? window.innerWidth : document.body.offsetWidth);
	//var scrh = (typeof window.innerWidth != 'undefined' ? window.innerWidth : document.body.offsetWidth);
	var scrwnocontent = scrw - contentpx - 40;
	//var scrhnocontent = scrh - $('layoutdiv').getStyle('height');
	var pagewmargin = scrwnocontent / 2;
	//var pagehmargin = scrhnocontent / 2;
	$('layoutdiv').setStyle({marginLeft: pagewmargin+'px', marginRight: pagewmargin+'px'});
	$('layoutdiv').style.visibility = 'visible';
	
}

function showperson(nameToDisplay){
	/*$('namebox').innerHTML = nameToDisplay;*/
	$('jobbox').style.visibility = 'visible';
	reqperson(nameToDisplay);
}
function clearperson(){
	$('jobbox').style.visibility = 'hidden';
}