$(function(){
  
  Cufon.replace('#quicklinks li a', { fontFamily: 'Swiss BT Light', fontSize: "18px"});
  Cufon.replace('h1', { fontFamily: 'Swiss BT Light', fontSize: "29px"});
  Cufon.now();
  
  $("body.hole .courseLayout area").hover(function(){
    var right = $("#googlemap");
    var hole = $(this);
    var course = hole.parent().attr("id");
    hole = hole.attr("href").replace("hole", "").replace(".aspx", "");
    right.append("<img src='/images/course/"+course+"/"+course[0].toUpperCase()+hole+".jpg'/>");
  }, function(){
    var right = $("#googlemap");
    right.html("");
  });

  $("#navigation li:last-child").addClass("last")
  
  $("img.rollover").hover(function(){
    $(this).attr("src", $(this).attr("src").replace(".", "_RO."));
  }, function(){
    $(this).attr("src", $(this).attr("src").replace("_RO", ""));
  });
  
  if ($(".right").length > 0 && $(".right").html().replace(/\s/g, "") == "") {
  //  $(".right").width(0).css({"min-width":0});
  }
  
  $("#navigation > li").hover(function(){
    var self = $(this);
    self.addClass("hover");
    
    var max_width = 0;
    self.children("ul").children("li").each(function() {
        var li = $(this);
        if (li.width() > max_width) {
            max_width = li.width();
        }
    }).each(function(){
        $(this).width(max_width);
    });
    
  }, function() {
    $(this).removeClass("hover");
  });
  
  if ($('.gallery img').length > 0){
    $('.gallery img').each(function() {
    
        var img = $(this);
        if (img.parents("a").length == 0)
            img.wrap("<a href='"+img.attr("src")+"' rel='gallery'></a>");
    });
    $('.gallery a[rel="gallery"]').colorbox();
    /*
    $('#gallery a').lightBox(
    {imageBtnPrev:"/images/lightbox/prevlabel.gif",
    imageBtnNext:"/images/lightbox/nextlabel.gif",
    imageBtnClose:"/images/photoalbum_close.png"
    }); */
 }
    

    $(window).load(function(){
          var right = $(".right");
        if (right.length > 0 && right.width() > 0 && $.trim(right.html()) != "") {
          var content = $("#content");
          content.children("p:last").addClass("last")
          right.children("p:last").addClass("last")
       
            right.height(content.height());
        }
        
       
        
         var right = $(".right");
        if (right.length > 0 && right.width() > 0 && $.trim(right.html()) != "") {
          var content = $("#content");
          content.children("p:last").addClass("last")
          right.children("p:last").addClass("last")
       
            var width = right.width();
            right.find("img, iframe").each(function(){
                if ($(this).width() > width) {
                    width = $(this).width();
                    //console.log(width);
                }
            })
            right.width(width);
            if (right.height() < content.height()) {
            right.height(content.height());
            }
        }
        
         var contentWithImages = $(".content-with-image");
        if (contentWithImages.length > 0) {
            var maxImageWidth = 0;
            contentWithImages.each(function() {
                var image = $(this).find(".image img");
             
                if (image.width() > maxImageWidth) { maxImageWidth = image.width(); }
            });
            
            contentWithImages.each(function() {
                var item = $(this);
                var image = item.find(".image");
                var content = item.find(".content");
                image.width(maxImageWidth);
                content.width(item.width() - maxImageWidth - parseInt(content.css("marginLeft")));
            });
        }
        
        
        if (right.length > 0 && right.width() > 0 && $.trim(right.html()) != "") {
        right.height("auto")
          var content = $("#content");
          content.children("p:last").addClass("last")
          right.children("p:last").addClass("last")
       
            var width = right.width();
            right.find("img, iframe").each(function(){
                if ($(this).width() > width) {
                    width = $(this).width();
                    //console.log(width);
                }
            })
            right.width(width);
            if (right.height() < content.height()) {
            right.height(content.height());
            }
        }
    })
});
