// Global Behaviors
// Requires jQuery

function limitStory(limit) {
	$("#txtStory").keyup(function() {
		var currentVal = $(this).val();
		var currentLength = parseInt(currentVal.length);
		if(currentLength > limit) {
			$(this).val(currentVal.substr(0, limit));
			currentLength = limit;
		}
		$("#remainingChars").text(limit - currentLength);
	})
}

// on DOM ready
$(function() {

	// ad replacement
	$(".promoBlock").html('<iframe src="/main/ad-page/" frameborder="0" scrolling="no" width="300" height="250"></iframe>');
	
	// stripe tables
	$("#mainContent table").each(function() {
		$("tr:odd", this).addClass("alt");
		
		$("tr:last td", this).each(function() {
			if($(this).html() == "" || $(this).html() == "&nbsp;") {
				$(this).addClass("empty");
			}
		});
	});
	
	// current article link
	if(location.pathname == "/") return false;
	$("#sidebar dl dd:has(a[href$='" + location.pathname + "'])").addClass("current");
	
	// job tips
	if(location.hash) {
		$(location.hash).next().andSelf().addClass("default");
		var pos = $("#tipList").prev("h3").offset();
		window.scrollTo(0, pos.top);
	}
	$("#tipList .tip").not(".default").hide();
	$("#tipList").find("h4").wrapInner('<a href="#" class="expandable"></a>');
	$("#tipList h4 a").click(function() {
		$(this).toggleClass("expanded").parent().next(".tip").toggle();
		return false;
	});
	$("#tipList h4.default a").addClass("expanded");
});