﻿/// <reference path="~/Assets/Scripts/Generic/jquery-1.2.6.min.js" />
/***
	INIT JAVASCRIPT

    The purpose of this script is to perform any tasks that are required on all pages in the site.
    
    At the time of writing, the only task is to set the css class of the html element to 'js'. This allows us
    to target browsers with js enabled/disabled in the css, e.g. hiding/showing elements accordingly. This is
    not valid html (<html> cannot have attribute 'class') but it works well, and due to the need to execute this
    js before the <body> element has been initialised, we cannot put the class on the body.

    @Authors
    Alasdair McLeay
    Graham Licence

***/
//document.getElementsByTagName('html')[0].className = 'js';
//recommended adding <script type="text/javascript">document.documentElement.className = 'js';</script> under head tag for speed

$(document).ready(function() {
	$("body").click(function(event) {
		if ($(event.target).is('a') || $(event.target).parent('a').size() > 0) {
			var anchor;
			if ($(event.target).is('a')) {
				anchor = $(event.target);
			}
			else {
				anchor = $(event.target).parent('a');
			}
			if (anchor[0].hostname !== location.hostname &&  !($(anchor).hasClass('internal'))) {
				window.open(anchor[0].href);
				return false;
			}
		}
    });
    // add "opens in new window" to external links 
	$("a[href*='http']:not([href*='"+location.hostname+"'])").each(
	    function() {
	        var title = $(this).attr("title");
	        var titleNewWindow = title + " - opens in new window";
	        $(this).attr("title", titleNewWindow);
		});

});