var pageTracker = _gat._getTracker("UA-472303-9");
pageTracker._initData();
pageTracker._trackPageview();

var bg=document.getElementsByTagName("html")[0];

function _(_id){
	if(document.getElementById && document.getElementById(_id)) return document.getElementById(_id);
	else return null;
}



// element className & style functions
var CSS=function(obj){
	return {
		empty:function(){
			return obj.className.replace(/\s/g,"")==""?true:false;
		},
		all:function(name){
			return !this.empty()?obj.className.split(/\s+/):[];
		},
		exist:function(name){
			for(var i=0, c=this.all(name), l=c.length; i<l; i++)
				if(c[i]==name) 
					return true;
			return false;
		},
		set:function(name){
			obj.className=name;
		},
		add:function(name){
			this.remove(name);
			obj.className+=' '+name;
			return true;
		},
		remove:function(name){
			obj.className=obj.className.replace(new RegExp("((^)|(\\s))"+name+"((\\s)|($))"),"$3");
			return false;
		},
		invert:function(name){
			return this.exist(name) ? this.remove(name) : this.add(name);
		},
		clear:function(){
			obj.className='';
		}
	}
};

var myAccordion;
var cur;

function reHeight(obj){
	if(obj.id=="first") return false;
	if(!obj.pos) obj.pos=25;
	if(obj.pos==25) obj.d=1;
	if(obj.pos==51) obj.d=-1;
	obj.pos=obj.pos+obj.d;
	obj.style.lineHeight=obj.pos+"px";
	if(obj.pos==25 || obj.pos==51) return false;
	setTimeout(function(){reHeight(obj)}, 12);
}

function init_togglers(){
	var controls = $$('#projects a');
	var stretchers = $$('#projects blockquote');
	
	controls.each(function(item){
		item.onfocus=function(){this.blur()};
	});
	
	myAccordion = new Fx.Accordion(controls, stretchers, { 	
		opacity: false,
		//start: 'first-open', 
		transition: Fx.Transitions.quadOut,
			
		onActive: function(obj, i){
			CSS(controls[i]).add("act");
			CSS(stretchers[i]).add("act");
			//bg.style.backgroundImage=stretchers[i].style.backgroundImage;
			reHeight(controls[i]);
			if(cur) reHeight(cur);
			cur=controls[i];
		},
		onBackground: function(obj, i){
			CSS(controls[i]).remove("act");
			CSS(stretchers[i]).remove("act");
		},
		onComplete:function(obj, i){
			//CSS(stretchers[i]).add("act");
		}
	});

};


function h2_hover(obj){
	if(obj.className=="act")return;
	obj.className=(obj.className=="hover"?"":"hover");
}

function init_mail(id){
	var mail=_(id).title+"@"+_(id).name;
	_(id).href="mailto:"+mail;
	_(id).innerHTML=mail;
	_(id).title="";
}

function setLang(name) {
	document.form_lang.lang.value=name; 
	document.form_lang.submit(); 
	return false;
}


var email_pattern=/^([a-zA-Z_]*)@(([A-Za-z\-]*)\.){1,2}([A-Za-z]{2,3})$/;

function check_form(form){
	req=form.getElementsByTagName("label");
	for(i=0;i<req.length;i++){
		if(!((k=req[i].lang) && (obj=form.elements[k]))) continue;
		if(obj.value==""){
			alert("Bitte überprüfen Sie Ihre Eingabe");
			obj.focus();
			return false;
		}
		if(obj.name=="email" && !email_pattern.test(obj.value)){
			alert("Email is not valid!");
			obj.focus();
			return false;
		}
	}
	return true;
}

function protectcontact(){
	document.write('<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;:&#116;&#101;&#97;&#109;'+ '&#64;' + '&#118;&#101;&#114;&#100;&#117;&#114;&#101;&#46;&#100;&#101;\">');document.write('&#116;&#101;&#97;&#109;'+ '&#64;' +'&#118;&#101;&#114;&#100;&#117;&#114;&#101;&#46;&#100;&#101;</a>');
}

function init(){
	var inp = document.getElementsByTagName('input');
	for(var i = 0; i < inp.length; i++) {
		if ( ((inp[i].type == 'text') || (inp[i].type == 'password')) && !inp[i].onfocus) {
			inp[i].setAttribute('rel',inp[i].defaultValue)
			inp[i].onfocus = function() {
				if(this.value == this.getAttribute('rel')) {
					this.value = '';
				} else {
					return false;
				}
			}
			inp[i].onblur = function() {
				if(this.value == '') {
					this.value = this.getAttribute('rel');
				} else {
					return false;
				}
			}
			inp[i].ondblclick = function() {
				this.value = this.getAttribute('rel')
			}
		}
	}

	var inp = document.getElementsByTagName('textarea');
	for(var i = 0; i < inp.length; i++) {
		if ( (inp[i].type == 'textarea') && !inp[i].onfocus) {
			inp[i].setAttribute('rel',inp[i].defaultValue)
			inp[i].onfocus = function() {
				if(this.value == this.getAttribute('rel')) {
					this.value = '';
				} else {
					return false;
				}
			}
			inp[i].onblur = function() {
				if(this.value == '') {
					this.value = this.getAttribute('rel');
				} else {
					return false;
				}
			}
			inp[i].ondblclick = function() {
				this.value = this.getAttribute('rel')
			}
		}
	}

}
if(document.childNodes) {
	window.onload = init
}

if(typeof sIFR == "function"){
    sIFR.replaceElement(".body_kompetenzen h1", named({sFlashSrc: "http://www.verdure.de/swf/font2.swf", sColor: "#ffffff", sBgColor: "#002822", sWmode: "transparent"}));
	sIFR.replaceElement(".body_kompetenzen h2", "textalign=left", named({sFlashSrc: "http://www.verdure.de/swf/font3.swf", sColor: "#a0afb7", sBgColor: "#002822", sWmode: "transparent"}));
    sIFR.replaceElement(".body_impressum h1", named({sFlashSrc: "http://www.verdure.de/swf/font_h2_gruen.swf", sColor: "#003f37", sBgColor: "#002822", sWmode: "transparent"}));
	sIFR.replaceElement(".body_impressum h2", named({sFlashSrc: "http://www.verdure.de/swf/font_h3_grau.swf", sColor: "#a0afb7", sBgColor: "#002822", sWmode: "transparent"}));
};
