$(document).ready(function() {
	$('a.contact').click(function() {
		  $('#contact').slideToggle('slow', function() {});
	});
	
	
	// fix hight of any boxes
	var boxheight = 0;
	$("div.box .text").each( function(i) {
		var textdivheight = $(this).height();
	    boxheight = Math.max(boxheight, textdivheight);
	});
	if (boxheight > 0) {
		$("div.box .text").each( function(i) {
			$(this).height(boxheight);
		});
	}
	
	
	// transform the box as linkable (based on link class="boxlink")
	$('div.box').each( function(i) {
	  var box = $(this);
	  var boxLinks = $("a:first", this);
	  // if the link exists... make the box linkable
	  if (boxLinks && boxLinks.length > 0) {
	    box.css("cursor", "pointer");
	    
      var boxLink = $(boxLinks[0]);
	    box.click(function() {
        var linkHref = boxLink.attr('href');
        // check if bcboverlay is configured?
        if (boxLink.hasClass('bcboverlay')) {
          bcbOverlayShow(linkHref);
        } else {
          // normal link
          var linkTarget = boxLink.attr('target');

          // Check for base tag and relative link
          var baseTag = document.getElementsByTagName('base');
          var baseHref = "";
          if (baseTag.length) {
            baseTag = baseTag[0];
            if (baseTag.getAttribute("href")) {
              baseHref = baseTag.getAttribute("href");
            }
          }
          
          if (linkHref.indexOf("/") != 0 && baseHref && baseHref != "" && linkHref.indexOf("http") == -1) {
            if (baseHref.lastIndexOf("/") != baseHref.length-1) {
              baseHref += "/";
            }
            linkHref = baseHref + linkHref;
          }
          
          // check if target blank - open in new window
          if(linkTarget == "_blank") {
            window.open(linkHref, "_blank");
          } else {
            window.location = linkHref;
          }
        }
        return false;
	    });
	  }
	});
});

