﻿// JavaScript Document

Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},	
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	},
	setBG: function(element,bg) {
		element = $(element);
		element.style.backgroundColor = bg;
	},	
	checkExist: function(element) {
		element = $(element);
		if (element === null) {
//			alert("--" +element);
			return false;
		}
		else {
//			alert("++" +element);
			return true;
		} 
		//element.style.backgroundColor = bg;
	}	
});



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------



/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
var tCallback;

function ajaxpage(url, containerid, tCB){
    tCallback = tCB;
    //alert ("x" + url);
	var page_request = false
	if (window.XMLHttpRequest) { // if Mozilla, Safari etc
		page_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject){ // if IE
	try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e){
		try{
		page_request = new ActiveXObject("Microsoft.XMLHTTP")
	}
	catch (e){}
	}
	}
	else
	return false
	
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}

	if (bustcachevar) { //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
		page_request.open('GET', url+bustcacheparameter, true)
		page_request.send(null)
	}
}

function loadpage(page_request, containerid){
    //alert("loadPage");
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(containerid).innerHTML=page_request.responseText;
		// todo: callback function nach dem laden...
		//alert("callback to: " + tCallback);
		//eval(tCallback());
		window[tCallback]();
	}
}

function loadobjs(){
	if (!document.getElementById)
		return
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""

	if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
		if (file.indexOf(".js")!=-1){ //If object is a js file
			fileref=document.createElement('script')
			fileref.setAttribute("type","text/javascript");
			fileref.setAttribute("src", file);
		}
		else if (file.indexOf(".css")!=-1){ //If object is a css file
			fileref=document.createElement("link")
			fileref.setAttribute("rel", "stylesheet");
			fileref.setAttribute("type", "text/css");
			fileref.setAttribute("href", file);
		}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

// #################################################################################################################################
Effect.DelayedChain = Class.create();
Object.extend(Effect.DelayedChain.prototype, {
    initialize: function(effect, elements, options, timeout){
        this.elements = elements;
        this.effect = effect;
        this.timeout = timeout || 100;
        this.options = Object.extend({}, options || {});

        this.afterFinish = this.options.afterFinish || Prototype.emptyFunction;
        this.options.afterFinish = Prototype.emptyFunction;
        setTimeout(this.action.bind(this),1);
    },
    action: function() {
        if(this.elements.length){ 
            new Effect[this.effect](this.elements.shift(), this.options);
            setTimeout(this.action.bind(this), this.timeout);
        } else {
            if(this.afterFinish) this.afterFinish();
        }
    }
});

Effect.Chain = Class.create();
Object.extend(Effect.Chain.prototype, {
    initialize: function(effect, elements, options){
        this.elements = elements || [];
        this.effect = effect;
        this.options = options || {};
        this.afterFinish = this.options.afterFinish || Prototype.emptyFunction;
        this.options.afterFinish = this.nextEffect.bind(this);
        setTimeout(this.nextEffect.bind(this), 1);
    },
    nextEffect: function(){
        if(this.elements.length)
            new Effect[this.effect](this.elements.shift(), this.options);
        else
            this.afterFinish();
    }
});
// #################################################################################################################################


function initScreen() {

		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
		//fileref.setAttribute("href", file);
		objOverlay.onclick = function() { endLayer(1,'x'); return false; }
		objBody.appendChild(objOverlay);

		var objContentLayer = document.createElement("div");
		objContentLayer.setAttribute('id','content_layer');
		//objContentLayer.style.display = 'none';
		objBody.appendChild(objContentLayer);

}

function startOverlay(tDelay) {
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.7 });
}
function removeOverlay(tDelay) {
	//var arrayPageSize = getPageSize();
	//Element.setHeight('overlay', arrayPageSize[1]);

//	new Effect.Appear('overlay', { duration: 0.2, 
//								   from: 0.8, 
//								   to: 0.0,
//								   delay: tDelay });
Element.hide('overlay');
}

function launchContentLayer(tDelay,tURL,tBG) {
	//var arrayPageSize = getPageSize();
	//Element.setHeight('content_layer', arrayPageSize[1]);
	//Element.setBG('content_layer',tBG);

    ajaxpage(tURL,'content_layer','showContainer');
}
function removeContentLayer(tDelay) {
//	new Effect.Appear('content_layer', { duration: 0.2, 
//	                                     from: 1.0, 
//	                                     to: 0.0, 
//	                                     delay: tDelay
//	                                     });
	Element.hide('content_layer');
}

function launchLayer(tURL,tBG) {
//alert('launchLayer');
	// blende overlay ein --> callback startet einblendung des content_layers
	startOverlay(0);
	
	// blende content ein
	Element.setBG('content_layer',tBG);
	launchContentLayer(0.0,tURL,tBG);
	
	// lade seite
	//ajaxpage(tURL, 'content_layer');

}

function endLayer(tDelay,tMode) {
//	alert("endLayer("+tDelay+","+tMode+")");
	// todo: unload content
	tDelay = 0;
    
	// blende content aus



	switch (tMode) {
		case "page":
		default:
		if (Element.checkExist('container3')) {
		   	new Effect.Appear('container3', { duration: 0.3, 
	                                     from: 1.0, 
	                                     to: 0.0, 									 
	                                     queue: {position:'front', scope:'endlayer'}
	                                     });
		}
		if (Element.checkExist('container2')) {
			new Effect.Appear('container2', { duration: 0.3, 
	                                     from: 1.0, 
	                                     to: 0.0, 
	                                     queue: {position:'end', scope:'endlayer'}
	                                     });
		}
		if (Element.checkExist('container1')) {
	  		new Effect.Appear('container1', { duration: 0.3, 
	                                     from: 1.0, 
	                                     to: 0.0, 
	                                     queue: {position:'end', scope:'endlayer'}
	                                     });                                                                
		}
// 			break;   		

		if (Element.checkExist('contentframe_splash')) {
	  		new Effect.Appear('contentframe_splash', { duration: 0.3, 
	                                     from: 1.0, 
	                                     to: 0.0, 
	                                     queue: {position:'end', scope:'endlayer'}
	                                     });                                                                
		}				    	
 			break;   		
	}


	new Effect.Appear('overlay', { duration: 0.2, 
	                                     from: 0.8, 
	                                     to: 0.0, 
	                                     delay: 0.0,
										 afterFinish: hideElements,
	                                     queue: {position:'end', scope:'endlayer'}
	                                     });
    
    
}

function loadContentPage(tURL,tBG,tCallback,tMode) {

	//Element.setBG('content_layer',tBG);
	switch(tMode) {
	   case "inline":
		  ajaxpage(tURL,'content_layer',tCallback);
	   
	   	   break;
	   case "start":
	   default:
		  ajaxpage(tURL,'content_layer',tCallback);
	   
	   	  break;
	   
	}
}

function showContainer() {

    //alert('showContainer');

		if (Element.checkExist('container1')) {
   			new Effect.Opacity('container1', { duration: 0.0, 
	        	                             from: 0.0, 
	            	                         to: 0.0
	            	                         });
		}
		if (Element.checkExist('container2')) {
   			new Effect.Opacity('container2', { duration: 0.0, 
	        	                             from: 0.0, 
	            	                         to: 0.0
	            	                         });
		}
		if (Element.checkExist('container3')) {
   			new Effect.Opacity('container3', { duration: 0.0, 
	        	                             from: 0.0, 
	            	                         to: 0.0
	            	                         });
		}

    
    
	if (Element.checkExist('content_layer')) {
		new Effect.Appear('content_layer', { duration: 0.1, 
	    	                                 from: 0.0, 
	        	                             to: 1.0
	            	                          });
		}

		if (Element.checkExist('container1')) {
   			new Effect.Appear('container1', { duration: 0.5, 
	        	                             from: 0.0, 
	            	                         to: 1.0, 									 
	                	                     queue: {position:'front', scope:'showcontainer'}
	                    	                 });
		}
		if (Element.checkExist('container2')) {
			new Effect.Appear('container2', { duration: 0.5, 
	    	                                 from: 0.0, 
	        	                             to: 1.0, 
	            	                         queue: {position:'end', scope:'showcontainer'}
	                	                     });
		}
		if (Element.checkExist('container3')) {
	  		new Effect.Appear('container3', { duration: 0.5, 
	        	                             from: 0.0, 
	            	                         to: 1.0, 
	                	                     queue: {position:'end', scope:'showcontainer'}
	                    	                 });                                                                
		}
}

function hideElements() {

	Element.hide('content_layer');
	Element.hide('overlay');
}

function loadIntro() {

		var tColumns = "ABCDEF";
		var tDelay = 0.0;
		for(x=0;x<tColumns.length;x++) {
			for(y=0;y<4;y++) {
			
				tID = tColumns.charAt(x)+y;

				if (tID == "F3") {
					new Effect.Appear(tID, { duration: 1.0, from:0.2,to:1.0,delay: tDelay,                        
		                                     afterFinish: launchIntroLayer
		                                     });
				}
				else {
					new Effect.Appear(tID, { duration: 1.0, from:0.2,to:1.0,delay: tDelay
		                                     });
				
				} 
	            tDelay= 0;
			}
		}



	//
}

function launchIntroLayer() {
	launchLayer('de/intro','');
}

function setDivContent(tDiv, tContent) {
	Element.setInnerHTML(tDiv,tContent);
}

function openStartLayer() {
	alert("openStartLayer");
	tID = "startframe";
	tDelay = 0;
	new Effect.Appear(tID, { duration: 1.0, from:0.2,to:1.0,delay: tDelay});
	
}

function closeStartLayer() {
	stopRotation();
	tID = "startframe";
	tDelay = 0;
	new Effect.Appear(tID, { duration: 1.0, from:1.0,to:0.0,delay: tDelay, afterFinish: hideStartLayer});
	
}


function hideStartLayer() {
	Element.hide('startframe');
	
}


function myFinish() {
	alert("finished");	
	ajaxpage( tURLToLoad,'start_dynamic_content', showStartContent);
																			  
}

function hideStartContent() {
	new Effect.Appear('start_dynamic_content', { duration: 1.0, from:1.0,to:0.0,delay: 0 });
}

function showStartContent() {
	new Effect.Appear('start_dynamic_content', { duration: 1.0, from:0.0,to:1.0,delay: 0 });
}

tActiveContainer = 0;
var tSelectedScreen = 0;
var tLastScreen = 0;
var tRotationTimer = 0;

function selectStartScreen(tIndex) {
	// rotate container id
//	tActiveContainer = (tActiveContainer+1)%2;
	containerid = "start_counter_"+tLastScreen;
	if (Element.checkExist(containerid)) {
		Element.setBG(containerid,""); //tSegment.style.background-color = "#ffffcc";	
	}
    containerid = "start_counter_"+tIndex;
	//tSegment = document.getElementById(containerid);
	Element.setBG(containerid,"#c30066"); //tSegment.style.background-color = "#ffffcc";	

    tActiveContainer++;
	tActiveContainer = tActiveContainer%2;
//	alert("x " + tActiveContainer);
	tSelectedScreen = tIndex;
	
//	tURL = tScreens[tSelectedScreen];
    
	loadStartContent(tSelectedScreen);
	
}

function doStep(tIndex) {
    stopRotation();
    tLastScreen = tSelectedScreen;
	selectStartScreen(tIndex);
}

function nextStep() {	
    stopRotation();
	nextStartScreen();
}

function previousStep() {
    stopRotation();
	previousStartScreen();
}


function initRotation() {
	selectStartScreen(1);
	startRotation();
}

function startRotation() {
	if (tRotationTimer == 0) {
       tRotationTimer = setInterval ( "nextStartScreen();", 4000 );
	}
}

function stopRotation() {
    clearInterval(tRotationTimer);	
	tRotationTimer = 0;
}



function previousStartScreen() {
   tLastScreen = tSelectedScreen;
   tSelectedScreen--;
   if (tSelectedScreen<1) {
      tSelectedScreen = tScreens.length - 1;
   }
	selectStartScreen(tSelectedScreen);
	
}

function nextStartScreen() {
   tLastScreen = tSelectedScreen;	
   tSelectedScreen++;
   if (tSelectedScreen >= tScreens.length) {
      tSelectedScreen = 1;
   }
	selectStartScreen(tSelectedScreen);
}


var tURLToLoad;

function loadStartContent(tIndex) {
    tImg = tScreenImages[tIndex];
	tImgSrc = tImg.src;
   //  tImgOnSrc = tImgOn.src; 
   // alert(tIndex + " / " + tActiveContainer);
	tText = tScreenText[tIndex];
	
		if (tActiveContainer == 0) {
		    document["startscreen_image0"].src = tImgSrc;
		    // ajaxpage(tURL,'start_dynamic_content_container0',swapContainer);
			new Effect.Appear('start_bg_pic0', { duration: 1.0, from:0,to:1,delay: 0,queue: {position:'end', scope:'start_container'},afterFinish: setScreenText });
			new Effect.Appear('start_bg_pic1', { duration: 1.0, from:1.0,to:0,delay: 0,queue: {position:'end', scope:'start_container'}  });
		    
		}
		if (tActiveContainer == 1) {
		   document["startscreen_image1"].src = tImgSrc;
			new Effect.Appear('start_bg_pic1', { duration: 1.0, from:0,to:1,delay: 0,queue: {position:'end', scope:'start_container'},afterFinish: setScreenText });
			new Effect.Appear('start_bg_pic0', { duration: 1.0, from:1.0,to:0,delay: 0,queue: {position:'end', scope:'start_container'}  });
		}
		  
   

}

function setScreenText() {
   tText =	tScreenText[tSelectedScreen];
   containerid = "start_textcontainer2";
   document.getElementById(containerid).innerHTML = '<div class="start_text">' + tText + '</div>';
}


function swapContainer() {
  //alert("swapContainer");
  //return;
  if(tActiveContainer == 1) {
//		alert("1");
		new Effect.Appear('start_dynamic_content_container0', { duration: 1.0, from:1.0,to:0,delay: 0,queue: {position:'end', scope:'start_container'} });
		new Effect.Appear('start_dynamic_content_container1', { duration: 1.0, from:0.0,to:1.0,delay: 1,queue: {position:'end', scope:'start_container'}  });
	  
  }
  if(tActiveContainer == 0) {
//		alert("0");
		new Effect.Appear('start_dynamic_content_container1', { duration: 1.0, from:1.0,to:0,delay: 0,queue: {position:'end', scope:'start_container'} });
		new Effect.Appear('start_dynamic_content_container0', { duration: 1.0, from:0.0,to:1.0,delay: 1,queue: {position:'end', scope:'start_container'} });
	  
  }
  
  
}

