function _debug ($string) {
   var debug = (window.console && window.console.firebug) ? true : false;
   (debug) ? console.log($string) : alert($string);
}

$(document).ready(function() {
   var ieAdjust, safariAdjust, mozAdjust, ul_h, p_h, h;
   
   if($("#home")[0]) {
      $("#layout .column").addClass("box").addClass("closed");
      $("#layout .column .homeContent").each(function(){
         // (debug) ? console.log($(this).children("ul:first").length > 0) : "";
         ($(this).children("ul:first").length > 0) ? $(this).addClass("navigation") : "";
      });
      $("#layout .column").click(function(el){
         ($(this).hasClass("open")) ? $(this).addClass("old_open") : "";
         //close open columns before showing the clicked version
         $("#layout .column").each(function(el){
            ($(this).hasClass("open")) ? $(this).attr("style", "margin-top: 11px").toggleClass("open").toggleClass("closed"): "";
         });
         
         if ($(this).children(".homeContent").children("ul:first").length > 0) {
            ieAdjust = (jQuery.browser.msie) ? 12 : 0;
            safariAdjust = (jQuery.browser.safari) ? 18 : 0;
            mozAdjust = (jQuery.browser.mozilla) ? 17 : 0;

            ul_h = $(this).children(".homeContent").children("ul:first").height();
            p_h = $(this).children(".homeContent").children("p:first").height();

            if ($(this).hasClass("old_open")) {
               $(this).attr("style", "margin-top: 11px").removeClass("open").addClass("closed").removeClass("old_open");
            } else if ($(this).hasClass("closed")) {
               h = determine_h();
               $(this).attr("style", "margin-top: " + h+"px").addClass("open").removeClass("closed");
            }
            //_debug($(this).children(".homeContent").children("ul:first").height());
            //.animate({marginTop: h}, 1500, "normal");
            
            if (jQuery.browser.msie && $(this).hasClass("open")) {
               ul_h = $(this).children(".homeContent").children("ul:first").height();
               h = determine_h();
               $(this).attr("style", "margin-top: " + h+"px");
            }
         }
      });
   };
   
   function determine_h () {
      return 0 - ul_h + p_h - ieAdjust - safariAdjust - mozAdjust;
   }
});
