jQuery(document).ready(function(){
	print_links("#dnn_ContentPane a", "http://www.wvuheducation.com");
	
	//SET TITLE = ALT FOR CROSS PLATFORM STUFF
	$("img").each(function(){
		if  ( ($(this).attr("title") == undefined) || ($(this).attr("title") == "") )  {
			if  ( ($(this).attr("alt") != undefined) && ($(this).attr("alt") != "") )  {
				$(this).attr( {title: $(this).attr("alt") });	
			}
		}
	});	
	
	// ALT ROW CLASSES APPLY
	jQuery("tbody > tr:even").addClass("evenRow");
	jQuery("tbody > tr:odd").addClass("oddRow");
		
	// ADD FIRSTCHILD CLASS TO ALL LI FIRST CHILD ELEMENTS 
	jQuery("ul li:first-child").addClass("firstChild");

	// REPLACE ALIGN RIGHT/LEFT WITH CLASSES
	jQuery("img[align='left']").addClass("floatLeftGrayOutlinePadded").removeAttr('align').removeAttr('hspace').removeAttr('vspace');
	jQuery("img[align='right']").addClass("floatRightGrayOutlinePadded").removeAttr('align').removeAttr('hspace').removeAttr('vspace');
	
	jQuery("hr").wrap('<div class="hr"></div>');
	
	// add class to search results tabls - SearchResults_dgResults
	jQuery("#mainContent table").each(function(){
		if(jQuery(this).attr("id").indexOf("SearchResults_dgResults") > -1){
			jQuery(this).addClass("search-results");
		}
	});
	
	// truncate_long_links("#mainContent", 500);
	
	//FAQ SHOW AND HIDE
	$(".faqDetail").hide();
	
	$(".faqQuestion").click(function(){
		$(".faqDetail").hide(0);
		$(".faqQuestion").parent().removeClass("underline");
		$(this).parent().next().slideToggle(100);
		$(this).parent().addClass("underline");
		return false;
	});
	
	$("#faqShowAll").click(function(){
		$(".faqQuestion").parent().addClass("underline");
		$(".faqDetail").show(0);
		$(this).parent().next().show(0);
		$(this).hide();
		return false;
	});
	
	
});

function print_links(_selector, _root){
	jQuery(_selector).each(function(){
		var _link = jQuery(this).attr("href");
		if(_link != undefined){
			if((_link.indexOf('http:') != 0) && (_link.indexOf('mailto:') != 0)){
				while(_link.indexOf("../") != -1){
					_link = _link.replace("../","");
				}
				_link = _root + "/" + _link;
			} 
			_link = _link.replace("mailto:","");
			jQuery(this).after('<span class="print-link"> (' + _link + ')</span>'); 
		}
	});
}

function truncate_long_links(_context, _size){
	jQuery(_context).find("a").each(function(){
		if(jQuery(this).css("display").toLowerCase() == "inline"){
			if(jQuery(this).width() > _size){
				var _oText = jQuery(this).html();
				var _fSize = parseInt(jQuery(this).css("fontSize"),10);
				jQuery(this).html(_oText.substr(0, _size/_fSize) + "...")
			}
		}
	});
}
