$(document).ready(function() {

  $("#cgc_agenda2010 a[rel]").each(function() {

    $(this).click(function(){
    	var show_id = $(this).attr("rel");
	    //if the ID exists in the DOM..
      if(document.getElementById(show_id) != null) {
	      //if the ID isn't diplayed yet &AND& if no fading is in progress..
	      if((show_id != $("#cgc_agenda2010 #agenda_content .visible").attr("id")) && (!$("#cgc_agenda2010 .tabrow").hasClass("fading"))) {
	        //add class 'fading' to declare fading progress
	        $("#cgc_agenda2010 .tabrow").addClass("fading");
	        //reset active tab
	        $("#cgc_agenda2010 .tabrow a.active").removeClass("active");
	        //set new active tab
	        $("#cgc_agenda2010 .tabrow a[rel='" + show_id + "']").addClass("active");
	        //hide currently and show new content
	        $("#cgc_agenda2010 #agenda_content .visible").fadeOut(100, function() {
	        	$(this).removeClass("visible");
	          $("#" + show_id).fadeIn(400, function() {
	          	$(this).addClass("visible");
	          	//remove fading class to allow new tab changes
	          	$("#cgc_agenda2010 .tabrow").removeClass("fading");

	         });
	       });
      }

      //if the show_id doesn't exist, feed back by making the link red
      } else {
              $(this).css("color", "#dd0000");
      }
      return false;
    });
  });


  $("#cgc_agenda2010 a.speakerlink").tooltip({
    fade: 100,
    track: true,
    delay: 0,
    showURL: false,
    showBody: " - ",
    positionRight: true,
	  bodyHandler: function() {

      //get the layer html
      tmpInnerHTML = $(this).parent().find(".referee_layer").html();

      if(tmpInnerHTML==null) {
              tmpInnerHTML = "<p style='width:auto;'>Es sind keine Informationen zum Sprecher vorhanden.</p>";
      }

      tmpHTML = "<div class='referee_layer'>";
      tmpHTML += tmpInnerHTML;
      tmpHTML += "</div>";


      return tmpHTML;
	  }
  });

});