(function ($) {
	$.fn.vAlign = function() {
		return this.each(function(i){
		var h = $(this).height();
		var oh = $(this).outerHeight();
		var mt = (h + (oh - h)) / 2;
		$(this).css("margin-top", "-" + mt + "px");
		$(this).css("top", "50%");
		$(this).css("position", "absolute");
	});
};
})(jQuery);

function externalLinks() { 
	if (!document.getElementsByTagName) return; 
 		var anchors = document.getElementsByTagName("a"); 
 		for (var i=0; i<anchors.length; i++) { 
   			var anchor = anchors[i]; 
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
     		anchor.target = "_blank"; 
 	} 
} 

window.onload = externalLinks;


$(document).ready(function () {
							
	$(".BlueBox a, .PinkBox a, .GreenBox a, .GreyBox a, .OrangeBox a").vAlign();
	
	$('.BlueBox:nth-child(3n+3)').css('margin-right','0px').parent().addClass("clearfix");
	$('.PinkBox:nth-child(3n+3)').css('margin-right','0px').parent().addClass("clearfix");
	$('.GreenBox:nth-child(3n+3)').css('margin-right','0px').parent().addClass("clearfix");
	$('.GreyBox:nth-child(3n+3)').css('margin-right','0px').parent().addClass("clearfix");
	$('.OrangeBox:nth-child(3n+3)').css('margin-right','0px').parent().addClass("clearfix");
	
	var clearSearch = "Search the website";
	
	$("input#Search").focus(function () {
		if ($(this).val() === $(this).attr("value")) {
			$(this).val("");
		}
	}).blur(function () {
		if ($(this).val() === "") {
			$(this).val(clearSearch);
		}
	});		
	
	//refresh page when submitting form
	$('.more-info').submit(function() {
		//alert('catch');
		return false;
	});
	
	//COLORBOX POPUP
	$(".popupbox").colorbox({maxWidth:"600px"});
	
	//SHOW HIDDEN
	$(".expandBox").click(function(){
	  $('.hiddenBox').slideToggle();
	  return false;
	});
	
	//BLOG LINK HOVER CODE
	$("#blogbutton").hover(function() {
		$(this).attr("src","images/visitblog_hover.gif");
			}, function() {
		$(this).attr("src","images/visitblog.gif");
	});

	
});

