var rootUrl = "http://www.ebugz.de/wp-content/themes/";
var siteLoad = Class.create();
siteLoad.prototype = {
	
	initialize: function() {
		//Element.show('contentOverlay');
		//Effect.BlindDown('contentOverlay', {duration:1});
		
	},
	
	loadWork: function() {
		$('contentOverlay').style.height="438px";
		$('contentOverlay').className = "normal";
		var params="timeStamp=" + new Date().getTime();
		new Ajax.Request ( 
    	rootUrl + "/htmlSrc/work.html",
      	{ method: 'get', parameters: params, onComplete: this.displayContent });
	},
	
	loadWorkB: function() {
		$('contentOverlay').style.height="438px";
		$('contentOverlay').className = "normal";
		var params="timeStamp=" + new Date().getTime();
		new Ajax.Request ( 
    	rootUrl + "/htmlSrc/work_b.html",
      	{ method: 'get', parameters: params, onComplete: this.displayContent });
	},	loadWorkC: function() {		$('contentOverlay').style.height="438px";		$('contentOverlay').className = "normal";		var params="timeStamp=" + new Date().getTime();		new Ajax.Request (     	rootUrl + "/htmlSrc/work_c.html",      	{ method: 'get', parameters: params, onComplete: this.displayContent });	},	
	loadKontakt: function() {
		$('contentOverlay').style.height="438px";
		$('contentOverlay').className = "normal";
		var params="timeStamp=" + new Date().getTime();
		new Ajax.Request ( 
    	rootUrl + "/htmlSrc/kontakt.html",
      	{ method: 'get', parameters: params, onComplete: this.displayContent });
	},
	loadAbout: function() {
		$('contentOverlay').style.height="438px";
		$('contentOverlay').className = "normal";
		var params="timeStamp=" + new Date().getTime();
		new Ajax.Request ( 
    	rootUrl + "/htmlSrc/about.html",
      	{ method: 'get', parameters: params, onComplete: this.displayContent });
	},
	
	
	displayContent: function(xhr){
		Element.show('gbBottom');
		$('contentOverlay').innerHTML=xhr.responseText;
		
		if($('contentOverlay').style.display == "none"){
			Effect.BlindDown('contentOverlay', {duration:1});	
		}
	
		
	},
	loadSubWork: function(x){
		var className = "";
		if(x==1){
			className="ibis";
		}
		else if(x==2){
			className="hels";
		}
		else if(x==3){
			className="windsbacher";
		}
		else if(x==4){
			className="loringhoven";
		}
		else if(x==5){
			className="meandis";
		}
		else if(x==6){
			className="guckkasten";
		}		else if(x==7){			className="bibliotheca";		}		else if(x==8){			className="autogascentrum";		}		else if(x==9){			className="forschungsstelle";		}						
		
		else{
			className="ibis";
		}
//		alert($('contentOverlay').style.height);
		if($('contentOverlay').style.height=="438px"){
			new Effect.SlideDown('contentOverlay',{from:1.0, to:1.45, duration:0.8, afterFinish:growDiv});	
		}
		Element.hide('closeBtn');
		this.newClass = className;
		//new Effect.Shrink('contentOverlay', {duration:0.4, afterFinish:growDiv})
		var params="timeStamp=" + new Date().getTime();
		$('contentOverlay').className = className;
		new Ajax.Request ( 
	    rootUrl + "/htmlSrc/work" + x + ".html",
	    { method: 'get', parameters: params, onComplete:this.displayContent});
	      	
	},
	end: function(){
		Effect.BlindUp('contentOverlay', {duration:0.4});
		Element.hide('gbBottom');		
	}
	
};

function growDiv(){
	$('contentOverlay').style.height="638px";
	Element.show('closeBtn');
	
    
}
function shrinkDiv(){
	$('contentOverlay').style.height="438px";

	
    
}		
function initsiteLoad() { mySiteLoad = new siteLoad(); }

function loadWFunc(){
		mySiteLoad.loadWorkC();		
}	
function loadKFunc(){
		mySiteLoad.loadKontakt();		
}
function loadAFunc(){
		mySiteLoad.loadAbout();		
}

var errAddr = true;
var errText = true;


function validateEmail(inhalt)
{

   if(inhalt.match(/^[a-zA-Z0-9_\.-]{2,}@[a-z0-9-]{3,}\.[a-z]{2,4}|museum$/)) {
     return true;
   }else{
     return false;
   }

}



function clearField(field){
	var clearVar = $(field).value;
	if(clearVar== "Ihre Email" || clearVar=="Ihre Nachricht an uns" ){
		$(field).value="";
	}
}

function checkMail(){
	var clearVar = $('emailAddr').value;

	if(!validateEmail(clearVar) || clearVar=="" || clearVar== "Ihre Email"){
		errAddr = true;
		new Effect.Highlight('emailAddr',  {duration: 1.4, startcolor:"#99CC00", restorecolor:"#ffffff"});
		
	}else{
		errAddr = false;
		
	}
}

function checkText(){
	if($('mailBody').value=="" || $('mailBody').value=="Ihre Nachricht an uns"){
		errText = true;
		new Effect.Highlight('mailBody',  {duration: 1.4, startcolor:"#99CC00", restorecolor:"#ffffff"});
		
	}else{
		errText = false;
	}
}

function validateAndSend(){
	checkMail();
	checkText();
	var params="emailAddr=" + $('emailAddr').value + "&emailText=" + $('mailBody').value;
	
	if(errText==false && errAddr==false){
		
		new Ajax.Request ( 
    	rootUrl + "/mailKontakt.php",
      	{ method: 'get', parameters: params, onComplete: displayMailError });
	}
}

function displayMailError(xhr){
	alert(xhr.responseText);
	
}


