function addEvent(obj, evType, fn, useCapture) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.attachEvent) {
        return obj.attachEvent("on" + evType, fn);
    }
}

function rotate_projectpages(curoffset,mode)
{
	if(mode == "first")
	{
		// nur navigation laden
		getprojects_ajax_initnavigation();
		
	}else{
		if(curoffset < 8)
		{
			curoffset += 4;
		}else{
			curoffset = 0;
		}
		
		getprojects(curoffset,"true");
	}
	projectrotation = window.setTimeout("rotate_projectpages(" + curoffset + ")",15000);	
}

function getprojects(offset,rotate)
{	
	if(rotate != "true")
	{
		window.clearTimeout(projectrotation);
	}
	
	window.setTimeout("starter_getprojects('" + offset + "','" + rotate + "')",10);	
}

function starter_getprojects(offset,rotate)
{
	if(rotate == "true")
	{
		animation_out('projekte');	
		window.setTimeout("getprojects_ajax('" + offset + "')",800);	
	}else{
		window.setTimeout("getprojects_ajax('" + offset + "')",0);	
	}
	
}

function getprojects_ajax(offset)
{
		var pars = 'offset=' + offset;
		
		var url = 'index.php?ajax=true';

		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: pars, 
				onComplete: projects_loaded
			}
			);
}

function getprojects_ajax_initnavigation()
{
		var pars = 'offset=0';
		
		var url = 'index.php?ajax=true';

		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: pars, 
				onComplete: projects_loaded
			}
			);
}

function blendout(object,curval)
{	
	curval -= 10;
	
	document.getElementById(object).style.filter = "Alpha(opacity=" + curval + ", finishopacity=0, style=0)";
	document.getElementById(object).style.MozOpacity = curval/100;

	if(curval != 0)
	{
		window.setTimeout("blendout('" + object + "'," + curval +")", 50);	
	}
}

function blendin(object,curval)
{	
	curval = curval + 10;
	
	document.getElementById(object).style.filter = "Alpha(opacity=" + curval + ", finishopacity=0, style=0)";
	document.getElementById(object).style.MozOpacity = curval/100;

	if(curval != 100)
	{
		window.setTimeout("blendin('" + object + "'," + curval +")", 50);	
	}
}

function animation_out(list)
{
	if(list == "projekte")
	{
		window.setTimeout("blendout('topprojekt1',100)", 0);	
		window.setTimeout("blendout('topprojekt2',100)", 100);	
		window.setTimeout("blendout('topprojekt3',100)", 200);	
		window.setTimeout("blendout('topprojekt4',100)", 300);	
		
		window.setTimeout("animation_in('projekte')", 1200);	
	}
}

function animation_in(list)
{
	if(list == "projekte")
	{		
		window.setTimeout("blendin('topprojekt1',10)", 0);	
		window.setTimeout("blendin('topprojekt2',10)", 100);	
		window.setTimeout("blendin('topprojekt3',10)", 200);	
		window.setTimeout("blendin('topprojekt4',10)", 300);	
	}
}

function projects_loaded(originalRequest) {
	
	var response = originalRequest.responseText;	
	response = unescape(response).replace(/\+/g, " ");	
	
	// Projektnavigation aktualisieren

	var respones = response.split("|||");
	
	document.getElementById('nav_projects').innerHTML = respones[respones.length-1];
	
	
	// vorherige Projekte ausblenden
	
	
	
	
	
	if(respones[0])
	{
		var project01 = respones[0].split(";;");
		document.getElementById('topprojekt1').innerHTML = '<img src="medien/' + project01[3] + '" border="0" width="83" height="83" alt="' + project01[0] + '" /><h3>' + project01[0] + '</h3><p style="font-size:80%;margin:6px 0 0 0;line-height:120%;">' + project01[1] + '</p><div class="link"><a href="' + project01[2] + '">mehr</a></div>';
	}
	
	if(respones[1])
	{
		var project02 = respones[1].split(";;");
		document.getElementById('topprojekt2').innerHTML = '<img src="medien/' + project02[3] + '" border="0" width="83" height="83" alt="' + project02[0] + '" /><h3>' + project02[0] + '</h3><p style="font-size:80%;margin:6px 0 0 0;line-height:120%;">' + project02[1] + '</p><div class="link"><a href="' + project02[2] + '">mehr</a></div>';
	}
	
	if(respones[2])
	{
		var project03 = respones[2].split(";;");
		document.getElementById('topprojekt3').innerHTML = '<img src="medien/' + project03[3] + '" border="0" width="83" height="83" alt="' + project03[0] + '" /><h3>' + project03[0] + '</h3><p style="font-size:80%;margin:6px 0 0 0;line-height:120%;">' + project03[1] + '</p><div class="link"><a href="' + project03[2] + '">mehr</a></div>';
	}
	
	if(respones[3])
	{
		var project04 = respones[3].split(";;");
		document.getElementById('topprojekt4').innerHTML = '<img src="medien/' + project04[3] + '" border="0" width="83" height="83" alt="' + project04[0] + '" /><h3>' + project04[0] + '</h3><p style="font-size:80%;margin:6px 0 0 0;line-height:120%;">' + project04[1] + '</p><div class="link"><a href="' + project04[2] + '">mehr</a></div>';	
	}	

	
	
	// Neue Projekte einlenden
	
	
	
	
	
	// Leere Kästen löschen
	
	if(respones.length == 2)
	{
		document.getElementById('topprojekt2').innerHTML = '';	
		document.getElementById('topprojekt3').innerHTML = '';	
		document.getElementById('topprojekt4').innerHTML = '';	
	}else if(respones.length == 3)
	{
		document.getElementById('topprojekt3').innerHTML = '';	
		document.getElementById('topprojekt4').innerHTML = '';	
	}else if(respones.length == 4)
	{
		document.getElementById('topprojekt4').innerHTML = '';	
	}
	
			
}



function showSitemap(href) {
    window.open(href, "wmsitemap", "width=340, height=600, scrollbars=yes");
    return false;
}

function nUopenWindow(theURL, wi, hi) {
    var winparam = eval("'scrollbars=auto,width=" + wi + ", height=" + hi + "'");
    var infofenster = 'infofenster';
    var dasfenster = window.open(theURL, infofenster, winparam);
    dasfenster.focus();
}

function sendeCardForm() {
    if ( checkeCardForm() ) {
        document.send_ecard.submit();
    }
}

function checkeCardForm() {
    if ( document.send_ecard.name.value == '' ) {
        alert('Bitte geben Sie Ihren Namen ein!');
        document.send_ecard.name.focus();
        return false;
    }
    if ( !isValidEmail(document.send_ecard.email.value) ) {
        alert('Bitte geben Sie Ihre korrekte E-Mail-Adresse ein!');
        document.send_ecard.email.focus();
        return false;
    }
    if ( document.send_ecard.name_empfaenger.value == '' ) {
        alert('Bitte geben Sie den Namen des Empfängers ein!');
        document.send_ecard.name_empfaenger.focus();
        return false;
    }
    if ( !isValidEmail(document.send_ecard.email_empfaenger.value) ) {
        alert('Bitte geben Sie die korrekte E-Mail-Adresse des Empfängers ein!');
        document.send_ecard.email_empfaenger.focus();
        return false;
    }
    if ( document.send_ecard.nachricht.value == '' ) {
        alert('Bitte geben Sie Ihr Nachricht ein!');
        document.send_ecard.nachricht.focus();
        return false;
    }
    return true;
}

function isValidEmail(email) {
     var a    = false;
     var res    = false;
     if (typeof( RegExp ) == 'function') {
          var b = new RegExp('abc');
          if (b.test('abc') == true) a = true;
      }
     if (a == true) {
          reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)' + '(\\@)([a-zA-Z0-9\\-\\.]+)' + '(\\.)([a-zA-Z]{2,4})$');
          res = reg.test(email);
     } else {
          res = email.search('@') >= 1 && email.lastIndexOf('.') > email.search('@') && email.lastIndexOf('.') >= email.length-5;
     }
     return res;
}

function turnOff(dname) { 
    document.getElementById(dname).style.display = 'none'; 
} 
function turnOn(dname) { 
    document.getElementById(dname).style.display = 'block'; 
} 

function turnOnAlpha(dname) {
    document.getElementById(dname).style.display = 'block'; 
    var element = document.getElementById('alpha');
    element.style.display = 'block'; 
    
    var hoehe = 0;
    if(document.body && document.body.clientHeight > 0) {
        hoehe = document.body.clientHeight;
    } else if (document.documentElement && document.documentElement.clientHeight > 0 ){
        hoehe = document.documentElement.clientHeight;
    } else {
        hoehe = window.innerHeight;    
    }
    hoehe += document.getElementById('mainarea').offsetHeight - 48;
    element.style.height = hoehe+"px";        

       var breite = 0;
    if(document.body && document.body.clientWidth > 0) {
        breite = document.body.clientWidth;
        
    } else if (document.documentElement && document.documentElement.clientWidth > 0 ){
        breite = document.documentElement.clientWidth;
    } else {
        breite = window.innerWidth;    
    }
    element.style.width = breite+"px";        
}





LiveSearch = Class.create();
LiveSearch.prototype = {
    initialize: function() {
        var attachitem = 'suchbegriff';
        var searchtext = 'SUCHE';
        
        this.attachitem = attachitem;
        this.target = 'content';
        this.removeHTML = null;
        this.removeHeadline = null;
        this.url = $(this.attachitem).form.action;
        this.pars = 'type=ls&suchbegriff=';
        this.minlength = 3;
        this.searchtext = searchtext;
        this.t = null;

        $(this.attachitem).setAttribute('autocomplete','off');
        $(this.attachitem).setAttribute('value', this.searchtext);
        Event.observe($(this.attachitem), 'focus', function() { if ($(attachitem).value == searchtext) $(attachitem).setAttribute('value', '') });
        Event.observe($(this.attachitem), 'blur', function() { if ($(attachitem).value == '') $(attachitem).setAttribute('value', searchtext) });

        Event.observe($(this.attachitem), 'keyup', this.readyLivesearch.bindAsEventListener(this));
    },

    readyLivesearch: function(event) {
        var code = event.keyCode;
        var currentLivesearch = this;
        if ($(this.attachitem).value.length >= this.minlength) {
            if (code == Event.KEY_ESC || ((code == Event.KEY_DELETE || code == Event.KEY_BACKSPACE) && $F(this.attachitem) == '')) {
                this.resetLivesearch();
            } else if (code != Event.KEY_LEFT && code != Event.KEY_RIGHT && code != Event.KEY_DOWN && code != Event.KEY_UP && code != Event.KEY_RETURN) {
                if (this.t) { clearTimeout(this.t) };
                this.t = setTimeout(this.doLivesearch.bind(this), 400);
            }
        }
    },

    doLivesearch: function() {
        if (this.removeHTML == null) {
            this.removeHTML = $(this.target).innerHTML;
        }
        if ($('hmain') && this.removeHeadline == null) {
            this.removeHeadline = $('hmain').innerHTML;
        }
        new Ajax.Updater(
            this.target,
            this.url,
            {
                method: 'get',
                parameters: this.pars + $F(this.attachitem),
                onComplete: function() {
                    /*
                    if ($('flashcontent')) {
                        $('flashcontent').SetVariable("varheadline", "Suchergebnis: " + $F(this.attachitem));
                    }
                    */
                    $('sloading').style.display = 'none';
                },
                onLoading: function() {
                    $('sloading').style.display = 'block';
                }
            }
        );
    },

    resetLivesearch: function() {
        $(this.attachitem).value = '';
        $(this.target).innerHTML = this.removeHTML;
        /*
        if ($('flashcontent')) {
            $('flashcontent').SetVariable("varheadline", this.removeHeadline);
        }
        */
    }
}

addEvent(window, "load", function () {
    new LiveSearch();
});