	/*
moo.fx, simple effects library built with prototype.js (http://prototype.conio.net).
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE.
for more info (http://moofx.mad4milk.net).
Sunday, March 05, 2006
v 1.2.3
*/

//the main function, call to the effect object
	function init(){
	
	
		var stretchers = document.getElementsByClassName('stretcher'); //div that stretches
		var toggles = document.getElementsByClassName('display'); //h3s where I click on

		//accordion effect
		var myAccordion = new fx.Accordion(
			toggles, stretchers, {opacity: true, duration: 400}
		);

		//hash function
		/* */
		function checkHash(){
			var found = false;
			toggles.each(function(h7, i){
				if (window.location.href.indexOf(h2.title) > 0) {
					myAccordion.showThisHideOpen(stretchers[i]);
					found = true;
				}
			});
			return found;
		}
		
		if (!checkHash()) myAccordion.showThisHideOpen(stretchers[0]); 
	}
	
	function toggleImage(id) {
		if(document.getElementById) {
			var toggles = document.getElementsByClassName('display'); //h3s where I click on
			var stretcher = document.getElementsByClassName('stretcher'); 
			var clicked = document.getElementById(id);
			var down = "url(../img/down.gif)";
			var up = "url(../img/up.gif)"
			var count = 0;
		
			toggles.each(function(h2, i){		
				
				if (!toggles[i].style.backgroundImage) { //test in ie, if not set -> set it!
					toggles[i].style.backgroundImage = down;
					//stretcher[i].style.height = '1%';
				} 
				
				if (stretcher[i].style.height == '0px') {
					count++;
				} 
					
			});  /**/
	
			if (count > 1) { // Wennn beide Ebenen eingeklappt, angeklickte Ebene ausklappen
				if (clicked.style.backgroundImage == down) {
					clicked.style.backgroundImage = up;
				} else {
					clicked.style.backgroundImage = down;
				}
			} else {
				for(z=0; z < toggles.length; z++) {
				
					if ((stretcher[z].style.height == '1%')) {
						toggles[z].style.backgroundImage = down;
					}
					if ((stretcher[z].style.height == '0px')&&(clicked.style.backgroundImage == down)) {
						if(clicked==toggles[z]) {
							clicked.style.backgroundImage = up;
						}
					} 
					
				}
			}
 		}
	}
	
	var ScrollLinks = {
    currentHash: false,
    start: function(){
        this.scroll = new fx.Scroll({duration: 800, onComplete: function(){ScrollLinks.end();}});
        this.allinks = document.getElementsByTagName('a');
        for (i=0; i<this.allinks.length; i++){
            var lnk = this.allinks[i];
            if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
                lnk.onclick = function(){
                    ScrollLinks.scroll.clearTimer();
                    this.initialHref = this.href;
                    this.initialHash = this.hash;
                    this.href = "javascript:void(0)";
                    setTimeout(function(){this.href = this.initialHref;}.bind(this), 200);
                    ScrollLinks.click(this);
                }
            }
        }
    },

    click: function(link){
        this.currentHash = link.initialHash.substr(1);
        if (this.currentHash) {
            for (j=0; j<this.allinks.length; j++){
                if (this.allinks[j].id == this.currentHash){
                    if (!window.opera) this.scroll.scrollTo(this.allinks[j]);
                    else this.scroll.scrollTo(this.allinks[j].parentNode);
                    break;
                }
            }
        }
    },

    end: function(){
        window.location.href = "#"+this.currentHash;
        this.currentHash = false;
    }
}

window.onload = function(){
    ScrollLinks.start();
}
