var locationToolTip;
var onLocationToolTip;

locationToolTip = true;
onLocationToolTip = true;

function loadMedia()
{
    $('.mediaApp').each( function() {
        var currentId = '#' + this.id;

    $.get('/global/apps/mediaPlayback/mediaPlayback.php', { dataVar: this.id.split('_')[1], dataShell: ''},

    function(data){
        $(currentId).html(data);
        });
    });
}
 

$(document).ready(function(){
	if ($("#sizer a").length) {
		$("#sizer a").textresizer
		({         
			target: ".resize",
			sizes:  [ "0.7em", "0.8em", "1em" ],
			selectedIndex: 1 
		});
	}

	if ($(".mediaApp").length) {
	    loadMedia();
	}
	
	checkUserAgent();

});

$(document.body).click(function() { 
	if ($('ul.hNav').length) {
			if(locationToolTip && !onLocationToolTip) {
				locationToolTip = false;
				onLocationTooltip = false;
				hideLocationTooltips();
			}
	}
});
	  
function hideLocationTooltips() {
	locLeb.hide();
	locCon.hide();
	locKen.hide();
	locMan.hide();
	locNas.hide();
	locChd.hide();
	locNcc.hide();
	locationToolTip = false;
}

function checkUserAgent() {
	if(($.browser.msie && parseFloat($.browser.version) <= 6.0) || ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)))
	{
	
	$("<div id=\"unsupported_browser\"><p>The browser you\'re using is very out of date.</p><p>To experience the Dartmouth-Hitchcock website fully, we strongly recommend that you upgrade to one of the following browsers:</p><ul><li><a href=\"http://windows.microsoft.com/en-US/internet-explorer/products/ie/home\" target=\"_blank\"><img src=\"/global/content/images/ie.gif\" alt=\"Internet Explorer 7 or later (PC)\" title=\"Internet Explorer 7 or later (PC)\" /></a></li><li><a href=\"http://www.mozilla.org/en-US/firefox/fx/\"  target=\"_blank\"><img src=\"/global/content/images/firefox.gif\" alt=\"Firefox 2 or later (Mac / PC)\" title=\"Firefox 2 or later (Mac / PC)\" /></a></li><li><a href=\"http://www.google.com/chrome\" target=\"_blank\"><img src=\"/global/content/images/chrome.gif\" alt=\"Google Chrome (Mac / PC)\" title=\"Google Chrome (Mac / PC)\" /></a></li></ul></div>").prependTo(document.body);

	}
}


if ($('ul.hNav').length) {
	$('div#header_topnav').hover (function() {onLocationToolTip = true;}, function() {onLocationToolTip = false;});

	$('.hNav').css('display', 'inline');
	$('.hNav_noscript').css('display', 'none');

	$('.n1 a').simpletip({
		persistent: true,
		focus: true,
		fixed: true,
		position: [0,14],
		onBeforeShow: function() {
			locationToolTip = false;
			hideLocationTooltips();
		},
		onShow: function() {
			locationToolTip = true;
		}	
	});

	$('.n2 a').simpletip({
		persistent: true,
		focus: true,
		fixed: true,
		position: [0,14],
		onBeforeShow: function() {
			locationToolTip = false;
			hideLocationTooltips();
		},
		onShow: function() {
			locationToolTip = true;
		}
	});

	$('.n3 a').simpletip({
		persistent: true,
		focus: true,
		fixed: true,
		position: [0,14],
		onBeforeShow: function() {
			locationToolTip = false;
			hideLocationTooltips();
		},
		onShow: function() {
			locationToolTip = true;
		}
	});

	$('.n4 a').simpletip({
		persistent: true,
		focus: true,
		fixed: true,
		position: [0,14],
		onBeforeShow: function() {
			locationToolTip = false;
			hideLocationTooltips();
		},
		onShow: function() {
			locationToolTip = true;
		}

	});

	$('.n5 a').simpletip({
		persistent: true,
		focus: true,
		fixed: true,
		position: [0,14],
		onBeforeShow: function() {
			locationToolTip = false;
			hideLocationTooltips();
		},
		onShow: function() {
			locationToolTip = true;
		}

	});

	$('.n6 a').simpletip({
		persistent: true,
		focus: true,
		fixed: true,
		position: [0,14],
		onBeforeShow: function() {
			locationToolTip = false;
			hideLocationTooltips();
		},
		onShow: function() {
			locationToolTip = true;
		}

	});

	$('.n7 a').simpletip({
		persistent: true,
		focus: true,
		fixed: true,
		position: [-278,14],
		onBeforeShow: function() {
			locationToolTip = false;
			hideLocationTooltips();
		},
		onShow: function() {
			locationToolTip = true;
		}
	});

	var locLeb = $('.n1 a').eq(0).simpletip();
	locLeb.load('/global/content/html/dhmc_lebanon.html');
	var locCon = $('.n2 a').eq(0).simpletip();
	locCon.load('/global/content/html/dh_concord.html');
	var locKen = $('.n3 a').eq(0).simpletip();
	locKen.load('/global/content/html/dh_keene.html');
	var locMan = $('.n4 a').eq(0).simpletip();
	locMan.load('/global/content/html/dh_manchester.html');
	var locNas = $('.n5 a').eq(0).simpletip();
	locNas.load('/global/content/html/dh_nashua.html');
	var locChd = $('.n6 a').eq(0).simpletip();
	locChd.load('/global/content/html/dh_chad_lebanon.html');
	var locNcc = $('.n7 a').eq(0).simpletip();
	locNcc.load('/global/content/html/dh_nccc_lebanon.html');

}


