$(document).ready(function()
{
  

  $("#buchdetails,#ausgaben").hide();
  $("#buchdetails,#ausgaben").addClass("bubble");
  $("#buchdetails,#ausgaben").wrapInner("<div class=\"inner\"></div>");
  $("#buchdetails,#ausgaben").append("<div class=\"footer\"></div>");

  $(".folderlinks a").click(function()
  { 
    var folderTop = -7; // Schatten abziehen
    if($(".folderlinks a").offset())
    { folderTop += $(".folderlinks").offset().top + parseInt($(".folderlinks").css("height")); } 
    $("#buchdetails,#ausgaben").css({
      top: folderTop + "px"
    });


    $("#buchdetails,#ausgaben").not($(this).attr("href")).hide();
    $(".folderlinks a").not($(this)).removeClass("on");
    $(this).toggleClass("on");
    $($(this).attr("href")).toggle();
    $(this).blur();
    
    return false; 
  });
  
  $("#ollestadcontent,#bazellcontent").find("#buchdetails,#ausgaben").each(function()
  {
    var thisBubble = $(this);
    var thisLink = $("a[href=#" + thisBubble.attr("id") + "]");
    thisLink.before(thisBubble);
    
    thisLink.css({position: "relative"});
    thisBubble.css({margin: "-14px 0 0 -20px"});

    thisLink.click(function()
    {
      thisLink.blur();
      if(thisBubble.is(":hidden"))
      { 
        hideBubble($("#buchdetails,#ausgaben").not(thisBubble));
        showBubble(thisBubble); 
      }
      else
      { hideBubble(thisBubble); }
      return false;
    });
    
  });
  
  function showBubble(thisBubble)
  {
    var thisLink = $("a[href=#" + thisBubble.attr("id") + "]");
    var thisZIndex = 1; 
    thisLink.addClass("open");
    if(!isNaN(parseInt(thisBubble.css("zIndex"))))
    { thisZIndex += parseInt(thisBubble.css("zIndex")); }
    thisBubble.css({zIndex: thisZIndex});
    thisLink.css({zIndex: thisZIndex + 1});
    thisBubble.show();
  }

  function hideBubble(thisBubble)
  {
    var thisLink = $("a[href=#" + thisBubble.attr("id") + "]");
    thisLink.removeClass("open");
    thisBubble.css({zIndex: ""});
    thisLink.css({zIndex: ""});
    thisBubble.hide();
  }

  
  var bubbleClick = false;
  $(".bubble").click(function()
  {
    bubbleClick = true;
  });
  
  $("body").click(function()
  {
    if(!bubbleClick)
    {
      hideBubble($(".bubble:visible"));
      $(".folderlinks a").not($(this)).removeClass("on");
    }
    bubbleClick = false;
  });
  
  if($("#moreinfos .inner a").length == 0)
  {
    $("#moreinfos").remove();
  }
  
});