jQuery(document).ready(function($) {	
	function externalLinks(autoExternal,fileexts) {
		// checks standard 'external' classes and wrapped anchors.
		$('a[rel="external"],.external a').each(function (){
			$(this).attr("target","_blank");
		});
		// checks file extensions in submitted array.
		// checks for offsite links if auto is TRUE. 
		if (fileexts || autoExternal) {
			$('a').each(function (){
				var url = String($(this).attr("href"));
				if (fileexts) {
					var start = url.lastIndexOf(".");             				  		
					if (start != -1){                                				 
						start++;                                       				  	
						extension = url.substring(start, url.length).toLowerCase();
						if (extension in oc(fileexts)){
							$(this).attr("target","_blank");
						}
					}
				}
				if (autoExternal) {
					var hn = String(window.location.hostname);
					var linkArray = url.split('/');
					var linkHN = String(linkArray[2]); // assuming http://
					var linkProtocol = linkArray[0];
					var linkHNStart = linkHN.lastIndexOf(":"); // find port info.
					if (linkHNStart!=-1) var linkHN = linkHN.substr(0,linkHNStart);
					if (hn!=linkHN && (linkProtocol=="http:" || linkProtocol=="https:") && url!="#") {
						$(this).attr("target","_blank"); 
					}
				}
			});
		}
		// checks 'internal' classes and wrapped anchors.
		$('a[rel="internal"],.internal a').each(function (){
			$(this).attr("target","");
		});
	}

	$('.ro').each(
	    function() {
	        if ($(this).children(".over").length < 1) {
	            $(this).prepend('<span class="over"></span>').children(":first").css({"opacity":0});
	        }
	        $(this).bind({
	            'mouseenter': function() {
	                $(this).children(".over").stop(true).animate({opacity:"1"},200);
	            },
	            'mouseleave': function() {
	                $(this).children(".over").stop(true).animate({opacity:"0"},200);
	            }
	        })
	    }
	);
		
	if(location.hash) {
		var div_element = '.' + location.hash.substr(1);

		// calculate distance from top of page to div
		// 100 = page header
		// 32 (2em) = extra spacing
		var targetOffset = $(div_element).offset().top - 100 - 32;
		
		$('html,body').animate({scrollTop: targetOffset}, 500);    
	}
	
	externalLinks(true);
	

});
