function init() {
	 
	/* Setup hover on buttons */
	$("table.btn-outer").each(function (i) {
		$(this).hover(
			function(){
				$(this).addClass("x-btn-over");
			},
			function(){
				$(this).removeClass("x-btn-over");
			}
		);
	});
	
	/* Init the menu */
	$('.menu_div ul').hide();
	/* $('.menu_div ul:first').show(); */
	var pu = parseUri(window.location.href);
	var pu_dir = pu['directory'];
	var pu_dir_split = pu_dir.split('/');
	var pu_processed_id = '';
	for(i=0; i<pu_dir_split.length; i++) {
		if(pu_dir_split[i] != '') {
			if((i+1) == pu_dir_split.length) {
				pu_processed_id = pu_processed_id + pu_dir_split[i];
			}
			else {
				pu_processed_id = pu_processed_id + pu_dir_split[i] + '-';
			}
		}
	}
		
	if (pu_processed_id.length > 0) {
		if($('.menu_div li a#' + pu_processed_id).parent().attr('class')=='parent_menu') {
			$('.menu_div li a#' + pu_processed_id).next().slideDown('normal');
		}
		else if($('.menu_div li a#' + pu_processed_id).parent().parent().parent().parent().parent().attr('class')=='parent_menu') {
			$('.menu_div li a#' + pu_processed_id).parent().parent().parent().parent().show();
			$('.menu_div li a#' + pu_processed_id).parent().parent().show();
			$('.menu_div ul').addClass('not_selected');
			$('.menu_div li a#' + pu_processed_id).parent().parent().removeClass('not_selected');
			$('.menu_div li a#' + pu_processed_id).addClass('selected');
		}
		else if($('.menu_div li a#' + pu_processed_id).parent().parent().parent().parent().parent().parent().parent().attr('class')=='parent_menu') {
			$('.menu_div li a#' + pu_processed_id).parent().parent().parent().parent().parent().parent().show();
			$('.menu_div li a#' + pu_processed_id).parent().parent().parent().parent().show();
			$('.menu_div li a#' + pu_processed_id).parent().parent().show();
			$('.menu_div li a#' + pu_processed_id).parent().parent().parent().parent().removeClass('not_selected');
			$('.menu_div li a#' + pu_processed_id).addClass('selected');
		}
		else {
			$('.menu_div li a#' + pu_processed_id).parent().parent().show();
			$('.menu_div ul').addClass('not_selected');
			$('.menu_div li a#' + pu_processed_id).parent().parent().removeClass('not_selected');
			$('.menu_div li a#' + pu_processed_id).addClass('selected');
		}
	}
	
	$('.menu_div li a').click(
		function() {
			$('.menu_div ul').removeClass('selected');
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				$('.menu_div ul.not_selected').slideUp('normal');
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				if(checkElement.hasClass('area_menu') || checkElement.hasClass('section_menu')) {
					checkElement.addClass('selected');
					if(checkElement.parent().is('ul')) {
						checkElement.parent().addClass('selected');
						checkElement.parent().removeClass('not_selected');
					}
					if(checkElement.parent().parent().is('ul')) {
						checkElement.parent().parent().addClass('selected');
						checkElement.parent().parent().removeClass('not_selected');
					}
					checkElement.addClass('selected');
					$('.menu_div ul.not_selected').slideUp('normal');
					$('.menu_div ul.selected').slideDown('normal');
				}
				else {
					$('.menu_div ul').addClass('not_selected');
					checkElement.removeClass('not_selected');
					checkElement.addClass('selected');
					$('.menu_div ul.region_menu').slideUp('normal');
					$('.menu_div ul.not_selected').slideUp('normal');
					$('.menu_div ul.selected').slideDown('normal');
				}
				return false;
			}
		}
	);
	
	/* Cookie to store screen res for max size of graphs */
	function writeScreenResolutionCookie() 
	{
	 var today = new Date();
	 var the_date = new Date("December 31, 2023");
	 var the_cookie_date = the_date.toGMTString();
	 var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
	 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
	 document.cookie=the_cookie
	}
	writeScreenResolutionCookie();
	
	/* MIDAS Map Player Animations */		
	$("#dtgs").bind("click", function(e){
      animation.gotodtgframe();
    });
	$("#map_previous").bind("click", function(e){
      animation.gotoprevious();
    });
	$("#map_next").bind("click", function(e){
      animation.gotonext();
    });
	
	/* Request Form Validate Event */
	$("form#request").validate();
	
	$(".tabs").tabs();
	
	$('#fisheye').Fisheye(
		{
			maxWidth: 50,
			items: 'a',
			itemsText: 'span',
			container: '.fisheyeContainer',
			itemWidth: 50,
			proximity: 35,
			halign : 'center'
		}
	)
	
	/* Top is Ajaxed to allow alerts to change by minute */
	$.timer(60000, function (timer) {
   		$("div#top").load("/ajax_top");
		$("div#top").ajaxComplete(function(request, settings){
			if (headline_interval != 'undefined') {
				clearInterval(headline_interval);
			}
			$("div.headline").css('top','210px');
			current_headline = 0;
			old_headline = 0;
			headlineRotator();
		 });
   	});
	
	headlineRotator();
	
	if (window.initializeLightning) {
		initializeLightning();
		window.onunload = GUnload;
	}
	if ($("#myGoogleMap").length > 0) 
	{
		$(window).unload(function(){
			GUnload();
		});
	}
	if ($("#myGoogleMap").length > 0) 
	{
		initMCRadar();
		setLooping(true);
	}
	
	$("input.chk_graph_legend").bind("click", function(e) {
		document.forms.frmgraphlegend.submit();
	});
			
	/* End of startup init */
}

/* Satellite pages data */
function fillSelectSatellite(num){
	var tick = new Date(start_at.getTime() + (num - 1) * 15 * 60 * 1000);
	return tick.toString().substr(0, 24);
}

function rotateImagesSatellite(num){
	var tick = new Date(start_at.getTime() + (num - 1) * 15 * 60 * 1000);
	var year = tick.getFullYear();
	var month = tick.getMonth() + 1;
	if (month < 10) 
		month = '0' + month;
	var day = tick.getDate();
	if (day < 10) 
		day = '0' + day;
	var hour = tick.getHours();
	if (hour < 10) 
		hour = '0' + hour;
	var minute = tick.getMinutes();
	if (minute < 10) 
		minute = '0' + minute;
	
	return imagedir + year + month + day + hour + minute + '.jpg';
}
function rotateLargeImagesSatellite(num){
	var tick = new Date(start_at.getTime() + (num - 1) * 15 * 60 * 1000);
	var year = tick.getFullYear();
	var month = tick.getMonth() + 1;
	if (month < 10) 
		month = '0' + month;
	var day = tick.getDate();
	if (day < 10) 
		day = '0' + day;
	var hour = tick.getHours();
	if (hour < 10) 
		hour = '0' + hour;
	var minute = tick.getMinutes();
	if (minute < 10) 
		minute = '0' + minute;
	
	return largeimagedir + year + month + day + hour + minute + '.jpg';
}

function MagnifierPosition()
{			
	this.style.left = Math.round(this.xPosition - 1 - this.size/2) + "px"; // -1 to account for the border
	this.style.top = Math.round(this.yPosition - 1 - this.size/2) + "px";
	
	this.shadow.style.left = Math.round(this.xPosition - this.size/2 - kShadowPadding) + "px";
	this.shadow.style.top = Math.round(this.yPosition - this.size/2 - kShadowPadding) + "px";
	
	var magnifierCenterX = Math.round(this.xPosition * this.xMultiplier - this.size/2);
	magnifierCenterX -= 440;
	var	magnifierCenterY = Math.round(this.yPosition * this.yMultiplier - this.size/2);
	magnifierCenterY -= 430;	
	
	this.style.backgroundPosition = -magnifierCenterX + "px " +
									-magnifierCenterY + "px";
	
}

function ControllerSizeButtonClick(event)
{
	if (!event) event = window.event;
	
	var button = event.currentTarget || event.srcElement;
	
	button.parentNode.magnifier.resize(button.magnifierSize);
}

function MagnifierResize(size)
{
	this.size = kMagnifierSizes[size];
	
	for (var i=0; i < this.controller.sizeButtons.length; i++)
	{
		if (i == size)
			this.controller.sizeButtons[i].className = "magnifierControllerButtonSelected";
		else
			this.controller.sizeButtons[i].className = "magnifierControllerButton";
	}
	
	if (this.size == 0)
	{
		this.shadow.style.display = "none";
		this.style.display = "none";
	}
	else
	{
		var shadow = this.shadow;
		var shadowSize = this.size + 2 * kShadowPadding;
		var shadowImageSrc = "/images/shadow" + size + ".png";
		
		// MSIE 5.x/6.x must be treated specially in order to make them use the PNG alpha channel
		if (this.size == 150) {
			shadowImageSrc = "/images/shadow2.png";
		}
		else if (this.size == 300) {
			shadowImageSrc = "/images/shadow3.png";
		}
		else {
			shadowImageSrc = "/images/shadow" + size + ".png";
		}
		if (shadow.runtimeStyle)
			shadow.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
									     shadowImageSrc +
										 "', sizingMethod='scale')";
		else
			shadow.style.backgroundImage = "url(" + shadowImageSrc + ")";
		shadow.style.width = shadowSize + "px";
		shadow.style.height = shadowSize + "px";
		shadow.style.display = "block";
		
		if (this.runtimeStyle) // msie counts the border as being part of the width
			this.size += 2; // must compensate
		
		this.style.width = this.size + "px";
		this.style.height = this.size + "px";
		this.style.display = "block";
		this.position();
	}
}

function MagnifierMouseDown(event)
{
	if (!event) event = window.event;
	
	document.body.magnifier = this;
	this.inDrag = true;
	if (event.pageX)
	{
		this.startX = event.pageX;
		this.startY = event.pageY;
	}
	else if (event.clientX)
	{
		this.startX = event.clientX;
		this.startY = event.clientY;
	}
	else
	{
		return;
	}
	var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
	var isMSIE = /*@cc_on!@*/false;
	if (isIE6) {
		this.startY += 190;
	}
	else if (isMSIE) {
		this.startY += 90;
	}
	this.savedCursor = this.style.cursor;
	this.style.cursor = "move";
}

function MagnifierMouseUp()
{
	if (this.inDrag)
	{
		this.inDrag = false;
		this.style.cursor = this.savedCursor;
		document.body.magnifier = null;
	}
}

function MagnifierDrag(event)
{
	if (!event) event = window.event;
	magnifier = document.getElementById("sat-image-playerMagnifier");
	if (magnifier && magnifier.inDrag)
	{
		var eventX;
		var eventY;

		if (event.pageX)
		{
			eventX = event.pageX;
			eventY = event.pageY;
		}
		else if (event.clientX)
		{
			eventX = event.clientX;
			eventY = event.clientY;
		}
		else
		{
			return;
		}
		
		magnifier.xPosition += eventX - magnifier.startX;
		magnifier.yPosition += eventY - magnifier.startY;
		magnifier.startX = eventX;
		magnifier.startY = eventY;
		magnifier.position();
	}
}

function loadMagnifier(baseID, zoomedWidth, zoomedHeight)
{
	// get the zoomed image (load as early as possible)
	var zoomedImage = document.createElement("img");
	zoomedImage.src = $("img.satellite_zoom").attr("alt");
	
	// get the div's
	var base = document.getElementById(baseID);
	var magnifier = document.createElement("div");

	// get the regular image
	var normalImage = null;
	normalImage = document.getElementById("IPimg_satBase");
	if (normalImage == null)
	{
		normalImage = document.getElementById("IPimg_satIR");
		if (normalImage == null) {
			return;
		}
	}
	
	magnifier.xMultiplier = zoomedWidth/normalImage.width;
	magnifier.yMultiplier = zoomedHeight/normalImage.height;
	
	magnifier.size = kMagnifierSizes[kDefaultMagnifierSize];
	magnifier.xPosition = normalImage.width - magnifier.size/2 - 20;
	magnifier.yPosition = normalImage.height - magnifier.size/2 + 30;
	magnifier.id = baseID + "Magnifier";
	magnifier.className = "magnifier";
	
	// styles (only dynamic ones, rest are part of the class)
	magnifier.style.backgroundImage = "url(" + $("img.satellite_zoom").attr("alt") + ")";
	
	// functions
	magnifier.onmousedown = MagnifierMouseDown;
	magnifier.onmouseup = MagnifierMouseUp;
	$("#binding").mousemove(function(e){
		MagnifierDrag(e);
	});
	magnifier.position = MagnifierPosition;
	magnifier.resize = MagnifierResize;
	
	// controller
	var controller = document.createElement("span");
	
	controller.id = baseID + "MagnifierController";
	controller.className = "magnifierController";
	
	var controllerPrefix = document.createElement("span");
	controllerPrefix.innerHTML = kControllerPrefix;

	controllerPrefix.className = "magnifierControllerPrefix";
	controller.appendChild(controllerPrefix);
	
	controller.sizeButtons = new Array(kMagnifierSizes.length);

	

	for (var i=0; i < kMagnifierSizes.length; i++)
	{
		var button = document.createElement("span");
		button.innerHTML = kMagnifierSizeNames[i];
		button.className = "magnifierControllerButton";
		button.onclick = ControllerSizeButtonClick;
		button.magnifierSize = i;
		
		controller.sizeButtons[i] = button;
		controller.appendChild(button);
	}
	
	// shadow
	var shadow = document.createElement("div");
	
	shadow.id = baseID + "MagnifierShadow";
	shadow.className = "magnifierShadow";
	
	// point objects at each other
	magnifier.controller = controller;
	controller.magnifier = magnifier;
	magnifier.shadow = shadow;
	
	// add to document and lay out

	var controllerContainer = document.createElement("div");

	controllerContainer.className = "magnifierControllerContainer";

	controllerContainer.appendChild(controller);

	$("#IPimg_satBase").after(controllerContainer);
	base.appendChild(shadow);
	base.appendChild(magnifier);
	magnifier.resize(kDefaultMagnifierSize); // also positions
}		

/* Setup the alerts vertical scroller */
var headline_count;
var current_headline = 0;
var old_headline = 0;
var headline_interval;
function headlineRotator() {		
	headline_count = $("div.headline").size();
	$("div.headline:eq("+current_headline+")").css('top','5px');
	
	if (headline_count > 1) {
		headline_interval = setInterval(headline_rotate, 10000); //time in milliseconds
	}

	function headline_rotate() {
		current_headline = (old_headline + 1) % headline_count; 
		$("div.headline:eq(" + old_headline + ")").animate({top: -205},2500, function() {
 			$(this).css('top','210px');
		});
		$("div.headline:eq(" + current_headline + ")").show().animate({top: 5},2500);  
		old_headline = current_headline;
	}
}

function do_archive(dt) {
	if (dt == undefined) {
		document.forms['archive_form'].action = document.forms['archive_form'].action + '?archive_date=' + document.forms['archive_form'].archive_date_last.value;
	}
	else {
		document.forms['archive_form'].action = document.forms['archive_form'].action + '?archive_date=' + dt;
	}
	document.forms['archive_form'].submit();
}

function selectBoxPrevious(selectId, formId) {
	var currSel = $('select#' + selectId).attr('selectedIndex');
	if(currSel>0) {
		currSel--;
		$('select#' + selectId + ' option:eq(' + currSel + ')').attr('selected', 'selected');
		$('form#' + formId).submit();
	}
}
function selectBoxNext(selectId, formId) {
	var currSel = $('select#' + selectId).attr('selectedIndex');
	var maxItems = $('select#' + selectId + ' option').length; 
	if(currSel < (maxItems - 1)) {
		currSel++;
		$('select#' + selectId + ' option:eq(' + currSel + ')').attr('selected', 'selected');
		$('form#' + formId).submit();
	}
}
