function addEvent(obj, evType, fn){ 
  if (obj.addEventListener){ 
    obj.addEventListener(evType, fn, false); 
    return true; 
  } else if (obj.attachEvent){ 
    var r = obj.attachEvent("on"+evType, fn); 
    return r; 
  } else { 
    return false; 
  } 
}

function dohides(){
  var h3s,tohide,newlink,newtext;
// get all h3 elements, loop over them
  h3s=document.getElementsByTagName('h3');
var klappe = querySt("klappe");
  for (i=0;i<h3s.length;i++){
// check if the class contains showhide
    if(/showhide/.test(h3s[i].className)){
// get the next sibling until it really is an element, if so, hide it
      tohide=h3s[i].nextSibling;
      while(tohide.nodeType!=1){
        tohide=tohide.nextSibling;
      }
      //tohide.style.display='none';
var nr = i + 1;
if(klappe != nr) {
      tohide.className = 'ishidden';
}
/// assemble a link and take the content of the span inside the h3 as its text
      newlink=document.createElement('a');
      newtext=document.createTextNode(h3s[i].firstChild.firstChild.nodeValue);
      newlink.appendChild(newtext);
      newlink.href='#'
// create a new object attribute, this saves us looping in the showhide function
// add the event handlers
      newlink.colobj=tohide;

      newlink.onmouseover=function() {
        this.parentNode.className+=" isover";
      }
      newlink.onmouseout=function() {
        this.parentNode.className=this.parentNode.className.replace(new RegExp(" isover\\b"), "");
      }

      newlink.onclick=function(){
		$(this.colobj).animate({
      "height": "toggle", "opacity": "toggle"
    }, "slow");
showhide(this.parentNode);
        //new Effect.toggle(this.colobj, 'blind',{queue:'start', afterFinish:showhide(this.parentNode)});
        //Effect.Combo(this.colobj, {duration: 1, scaleX: false, scaleContent: false});
        return false;
      }
      //newlink.onkeypress=function(){showhide(this.colobj);return false}
// replace the h3 with the link
      h3s[i].replaceChild(newlink,h3s[i].firstChild)
    }
  }
}

function showhide(o){
// toggle class
  //if(o){o.className = o.className == 'showhidehidden'?'showhide':'showhidehidden';}
  if(o.className.match(new RegExp(" isopen\\b"))){
    o.className=o.className.replace(new RegExp(" isopen\\b"), "");
  } else {
    o.className+=" isopen";
  }

}


function querySt(ji) {
 hu = window.location.search.substring(1);
 gy = hu.split("&");
 for (i=0;i<gy.length;i++) {

 ft = gy[i].split("=");
 if (ft[0] == ji) {
 return ft[1];
 }
 }
}

function getQuery() {
 var action = querySt("action");
 if(action == "go") {
 document.getElementById("btn").style.display = "none";
 document.getElementById("winner").style.display = "block";
 letitSnow();
 }
}

// if the browser can deal with DOM, addEventlisteners  
if(document.getElementById && document.createTextNode){
  addEvent(window, 'load', dohides);
  //addEvent(window, 'load', bar);
}


jQuery(function(){

  $("a[name=video]").addClass("video");
  $("a[name=audio]").addClass("audio");
  $("a[name=pdf]").addClass("pdflink");
  $("a[name=facebook]").addClass("facebook");
  $("a[name=twitter]").addClass("twitter");
});
