/*vertical aligner*/
$.fn.vertAlign = function() {
	if (this.length > 0) {
		$parent = (arguments.length > 0) ? $(arguments[0]) : this.parent();
		var topShift = ( $parent.innerHeight() - this.outerHeight() ) / 2;
		topShift = topShift > 0 ? topShift + "px" : 0;
		this.css("marginTop",topShift);	
	}
}


$.fn.matchHeights = function() {
	var maxHeight = 0;
	$(this).each(function(i){
		var currHeight = $(this).height();
		maxHeight = (currHeight > maxHeight) ? currHeight : maxHeight;
	})
	.css({height:maxHeight+"px"});
}


/*Tip Positioning - req: dimensions.js*/
function setTipPos(trig,tip, offX, offY) {
	var trigOffset=$(trig).offset(trigOffset);
	//var parOffset=$($(tip).offsetParent()).offset(parOffset);
	var winH=$(window).height();
	var winW=$(window).width();
	var tipLeft=trigOffset.left + trig.offsetWidth + offX;
	var tipTop=trigOffset.top + offY;
	
	tipLeft = (tipLeft + tip.offsetWidth - $(window).scrollLeft() > winW) ? 
		/*
		trigOffset.left - tip.offsetWidth - offX - parOffset.left
		: tipLeft - parOffset.left;
		*/
		trigOffset.left - tip.offsetWidth - offX
		: tipLeft;
		
	tipTop = (tipTop + tip.offsetHeight - $(window).scrollTop() > winH) ? 
		/*
		trigOffset.top - tip.offsetHeight - offY - parOffset.top
		: tipTop - parOffset.top;
		*/
		trigOffset.top - tip.offsetHeight - offY
		: tipTop;
		
	tip.style.left = tipLeft + "px";
	tip.style.top = tipTop + "px";
}

$(document).ready(function(){	
	
	//vertical align text branding;
	$("#brandingHTML").vertAlign();
	
	//set copyright date
	if ($('#writeyear').length > 0){
		var date = new Date();
		$('#writeyear').text(date.getFullYear() + " ");
	}
	
	//vertical align Standard Feature links
	$(".hdrIntro .introLinks").vertAlign();
	
	//registration selector
	$("#hdrLogin a.linkRegister").click(function(){
		var $regSelector = $(this).siblings("div.registerSelect");
		$regSelector.find("h4").text($(this).text());
		$regSelector.show(300);
		
		$(document).bind("click.hideSelector", function(e){
			$regSelector.hide(300);
			$(document).unbind("click.hideSelector");
		});
		return false;
	});
	
	//persistent nav controls 
/*
	$("#hdrLogin input.inputbox").each(function(i){
		var $input = $(this);
		var $label = $input.parents("div.formUnit").find("label.mainLabel");
		if ($input.val() != "") {
			$label.hide();
		}
		
		$input.focus(function(){
			$label.hide();
		});
		
		$input.blur(function(){
			if (this.value == ""){
				$label.show();
			}
		});
	});
*/
	
	//homepage - match callout/promo heights
	if ($("#pageBody.instructorBody").length > 0) {
		$("#pageBody div.contentBlock, #pageBody .promoBody").matchHeights();
	}
	
});

