//=============================================================================
/* 

	basic.js
	v1.0
	2008/01/21

	Headscape
	Written by Ed Merritt (ed.merritt@headscape.co.uk)

	The behaviours are served to all sites.

*/
//=============================================================================
// Adds a class to the body tag so any elements on the page can be styled differently if the browser supports JS

$(document).ready(function() {
	$("body").addClass("jsEnabled");
});

//=============================================================================
// Adds a class to the first and last <li> of every list

$(document).ready(function() {
	$("ul li:first-child").addClass("firstLi");
	$("ul li:last-child").addClass("lastLi");
	$("ol li:first-child").addClass("firstLi");
	$("ol li:last-child").addClass("lastLi");
});

//=============================================================================
// Causes external links to open in a new window

$(document).ready(function(){
	$('a[href^=http],a[href^=/relatedlink.html?class=link&link=http],a[href$=pdf],a[href$=PDF],a[href$=download]').each(function() {
		var titleStr = $(this).attr("title");
		if (titleStr!="" && titleStr!=undefined) {
			titleStr += " (new window)";
		} else {
			titleStr = "(new window)";	
		}
		$(this).attr("title", titleStr);
		$(this).click(function() {
			window.open(this.href);
			return false;
		});
	});
});

//=============================================================================
// enables smooth scrolling to anchors within the current page

$(document).ready(function(){
  $('a[href^=#]:not(a[href$=#])').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body').animate({scrollTop: targetOffset}, 1000);
	   return false;
	  }
	}
  });
});

//=============================================================================

