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");
});



function openPodcast(theURL)
{
    winName = window.open(theURL,'Podcast','location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=938,height=756');
    if(winName == null || winName.closed){
    	window.open(theURL,winName,features);
    }
    else{winName.location.href = theURL;}
    if (!winName.closed)
    winName.focus();
}


// Checks the browser and adds classes to the body to reflect it.

jQuery(document).ready(function(){
    
    var userAgent = navigator.userAgent.toLowerCase();
    $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
    
    // Is this a version of IE?
    if($.browser.msie){
        $('body').addClass('browserIE');
        
        // Add the version number
        $('body').addClass('browserIE' + $.browser.version.substring(0,1));
    }
    
    
    // Is this a version of Chrome?
    if($.browser.chrome){
    
        $('body').addClass('browserChrome');
        
        //Add the version number
        userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
        userAgent = userAgent.substring(0,1);
        $('body').addClass('browserChrome' + userAgent);
        
        // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
        $.browser.safari = false;
    }
    
    // Is this a version of Safari?
    if($.browser.safari){
        $('body').addClass('browserSafari');
        
        // Add the version number
        userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
        userAgent = userAgent.substring(0,1);
        $('body').addClass('browserSafari' + userAgent);
    }
    
    // Is this a version of Mozilla?
    if($.browser.mozilla){
        
        //Is it Firefox?
        if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1){
            $('body').addClass('browserFirefox');
            
            // Add the version number
            userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
            userAgent = userAgent.substring(0,1);
            $('body').addClass('browserFirefox' + userAgent);
        }
        // If not then it must be another Mozilla
        else{
            $('body').addClass('browserMozilla');
        }
    }
    
    // Is this a version of Opera?
    if($.browser.opera){
        $('body').addClass('browserOpera');
    }
    
      $("div.zoomdiv > a > img").each(function(index) {
    
    var zdWidth = $(this).width();

    if (zdWidth == "140") {
      $(this).parent("a").parent("div.zoomdiv").css("width", "11.7em");
    }
  });

});




/*SocialMediaFooter*/
var some_time = 1;
var some_currentvalue = some_time;
var some_intervalId = 0;
var some_keep = false;

function someCountDown(){
	if(some_currentvalue > 0){
		some_currentvalue -= 1;
	} else if(some_currentvalue == 0) {
		clearInterval ( some_intervalId );
		some_currentvalue = some_time;
		$('#bmpu').hide();
	}
}

function Site(id, name, url, linkTitleDE, linkTitleEN, displayName) {
  this.id = id;
  this.name = name;
  this.url = url;
  this.linkTitleDE = linkTitleDE;
  this.linkTitleEN = linkTitleEN;
  this.linkInList = "";
  this.displayName = displayName;
}

function buildLink(site, url, title, lang) {
	var nurl = site.url.replace(/{u}/, encodeURIComponent(url)).replace(/{t}/, encodeURIComponent(title));
	var linkText = "";
	if (lang == "de") {
		linkText = site.linkTitleDE;
	} else {
		linkText = site.linkTitleEN;
	}
	var displayName;
	if (site.displayName == true) {
		displayName = site.name;
	} else {
		displayName = "";
	}
	link = '<li><a class="'+site.id+'" href="'+nurl+'" title="'+linkText+'" target="_blank">'+displayName+'</a></li>';
	return link;
}

function setBookmark(lang){
  bookmarkurl = location.href;
  if (document.all) {
     var text = document.title;
     text = text.replace(/:/ ,"");
     text = text.replace(/\*/ ,"");
     text = text.replace(/\?/ ,"");
     text = text.replace(/\\/ ,"");
     text = text.replace(/"/ ,"");
     text = text.replace(/</ ,"");
     text = text.replace(/>/ ,"");
     text = text.replace(/|/ ,"");
     window.external.AddFavorite(bookmarkurl,text);
  } else {
    alert('Your Browser does not support this feature!');
  }
}

jQuery(function(){
		var target = $("#bigfooter div.functns");
		var url = window.location.href;
		var title = document.title;
		var sites = [];
		
		var hash = url.split("/");
		var href = hash[2];
		var hash2 = href.split(".");
		var lang = hash2[hash2.length-1];
		//Sprache wird ?ber Toplevel Domain gesetzt
		//lang = "de";
		
		var html = "";
		
		sites[0] = new Site("delicious","Delicious","http://del.icio.us/post?url={u}&amp;title={t}","Bei Delicious weiterempfehlen","Recommend on Delicious",true);
		sites[1] = new Site("digg","Digg","http://digg.com/submit?phase=2&amp;url={u}&amp;title={t}","Bei Digg weiterempfehlen","Recommend on Digg",true);
		sites[2] = new Site("facebook","Facebook","http://www.facebook.com/sharer.php?u={u}&amp;t={t}","Bei Facebook weiterempfehlen","Recommend on Facebook",false);
		sites[3] = new Site("google","Google","http://www.google.com/bookmarks/mark?op=edit&amp;bkmk={u}&amp;title={t}","Bei Google weiterempfehlen","Recommend on Google",true);
		sites[4]= new Site("linkedin","LinkedIn","http://www.linkedin.com/shareArticle?mini=true&amp;url={u}&amp;title={t}&amp;ro=false&amp;summary=&amp;source=","Bei LinkedIn weiterempfehlen","Recommend on LinkedIn",true);
		sites[5] = new Site("mail","Mail","https://secure.bayer.com/bayer/emailpage.aspx?url={u}&amp;title={t}","Per E-Mail weiterempfehlen","Recommend via email",false);
		sites[6] = new Site("misterwong","Mr. Wong","http://www.mister-wong.com/index.php?action=addurl&amp;bm_url={u}&amp;bm_description={t}","Bei Mr. Wong weiterempfehlen","Recommend on Mr. Wong",true);
		sites[7] = new Site("myspace","MySpace","http://www.myspace.com/Modules/PostTo/Pages/?c={u}&amp;t={t}","Bei MySpace weiterempfehlen","Recommend on MySpace",true);
		sites[8] = new Site("twitter","Twitter","http://twitter.com/home?status={t}++{u}","Bei Twitter weiterempfehlen","Recommend on Twitter",false);
		sites[9] = new Site("yahoo","Yahoo","http://myweb2.search.yahoo.com/myresults/bookmarklet?u={u}&amp;t={t}","Bei Yahoo weiterempfehlen","Recommend on Yahoo",true);
		//sites[10] = new Site("bookmark", "Bookmark", "javascript:setBookmark()", "Seite bookmarken", "Bookmark this page", true);
		
		for (var i = 0; i < sites.length; i++) {
			sites[i].linkInList = buildLink(sites[i], url, title, lang);
		}
		
		var empfehlenText = "";
		var mehrText = "";
		var schliessenText = "";
		var bookmark = "";
		var mail = "";
		
		if (lang == 'de') {
			empfehlenText = "Seite empfehlen:";
			mehrText = "Mehr Seiten ...";
			schliessenText = "schlie?en";
			bookmark = '<li><a title="Seite bookmarken" href="javascript:setBookmark()" class="bookmarken">Bookmark</a></li>';
			mail = "<li><a title=\""+sites[5].linkTitleDE+"\" class=\"mail\" href=\"javascript:winOpen('https://secure.bayer.com/foundations/emailpage.aspx?lang=de&amp;title=' + encodeURIComponent('" + title + "') + '&amp;url=' + encodeURIComponent('" + url+"'),'recommend','location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=520,height=650');\"></a></li>";
			//mail = "<li><a class=\"mail\" href=\"javascript:alert(\'mail\')\"></a></li>";
		} else {
			empfehlenText = "Recommend this site:";
			mehrText = "More Sites ...";
			schliessenText = "close";
			bookmark = '<li><a title="Bookmark this page" href="javascript:setBookmark()" class="bookmarken">Bookmark</a></li>';
			mail = "<li><a title=\""+sites[5].linkTitleEN+"\" class=\"mail\" href=\"javascript:winOpen('https://secure.bayer.com/foundations/emailpage.aspx?lang=en&amp;title=' + encodeURIComponent('" + title + "') + '&amp;url=' + encodeURIComponent('" + url+"'),'recommend','location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=520,height=650');\"></a></li>";
		}
		
		var firstList = sites[2].linkInList + sites[8].linkInList + mail;
		var secondList = sites[1].linkInList + sites[4].linkInList + sites[0].linkInList + sites[7].linkInList + sites[3].linkInList + sites[6].linkInList + sites[9].linkInList;
		
		html = '<div id=""><div id="bmpu"><a class="toggleBmpu close" title="{schliessenText}" href="#" id="closeBmpu"></a><ul class="somebm">{secondList}'+bookmark+'</ul></div><div id="bmbar"><div id="text">{empfehlenText}</div><ul class="somebm">{firstList}<li><a class="toggleBmpu plus" href="#" title="{mehrText}"></a></li></ul></div></div>';
		html = html.replace(/{secondList}/, secondList).replace(/{schliessenText}/, schliessenText).replace(/{empfehlenText}/, empfehlenText).replace(/{firstList}/, firstList).replace(/{mehrText}/, mehrText);
		target.html(html);
		
		$('.plus').mouseover(function() {
			$('#bmpu').show();
			clearInterval ( some_intervalId );
			some_currentvalue = some_time;
			return false;
		});

		$('.plus').mouseout(function() {
			if (!some_keep) {
				some_intervalId = setInterval( "someCountDown()", 1000 );
			}
			return false;
		});

		$('.plus').click(function() {
			$('#bmpu').show();
			return false;
		});

		$('#closeBmpu').click(function() {
			$('#bmpu').hide();
			some_keep = false;
			clearInterval ( some_intervalId );
			some_currentvalue = some_time;
			return false;
		});

		$('#bmpu').mouseover(function() {
			clearInterval ( some_intervalId );
			some_currentvalue = some_time;
		});

		$('#bmpu').mouseout(function() {
			if (!some_keep) {
				some_intervalId = setInterval( "someCountDown()", 1000 );
			}
		});
		
		if(!$.browser.msie) {
			$("#bigfooter .bookmark").hide();
		}

});

