﻿var MainSwitch = 0;
var ImageSwitch = 0;
DDisOn = new Array();
DDList = new Array();

function turnOn() {
	MainSwitch = 1;
	menu_center('y');
}

function check_search_form() {
	form = document.search_form;
	var el = '';
	if (form.SearchTerm.value == '') el += 'Enter a term to search on and click "GO" again \n';
	if (el == '') {
		return true;
	} else {
		alert(el);
		return false;
	}
}

function pop_file(f, w, h) {
	var temp_url = f;
	var new_win = window.open(temp_url, 'pop' + h + w, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + w + ',height=' + h + ',alwaysRaised=yes');
	new_win.focus();
}

// The W3C DOM Object
function dom_object(obj) {
	this.css2 = obj;
	this.name = obj.id;
	this.objHide = domHide;
	this.objShow = domShow;
	if (document.all && document.all[this.name] && document.all[this.name].style && document.all[this.name].style.left) {
		temp = document.all[this.name].style.left;
	} else if (document.getElementById && document.getElementById(this.name) && document.getElementById(this.name).style && document.getElementById(this.name).style.left) {
		temp = document.getElementById(this.name).style.left;
	} else {
		temp = '0px';
	}
	this.leftOffset = parseInt(temp.substr(0, temp.length-2));
	this.setLP = setLeftPosition;
}

// The Navigator DOM Object
function ns_object(obj) {
	this.css2 = obj;
	this.name = obj.name;
	this.objHide = nsobjHide;
	this.objShow = nsobjShow;
	if (document.layers && document.layers[this.name] && document.layers[this.name].left) {
		temp = document.layers[this.name].left;		
	} else {
		temp = '0px';
	}
	this.leftOffset = parseInt(temp.substr(0, temp.length-2));
	this.setLP = setLeftPosition;
}

// The DOM Object Implementations
function setLeftPosition(new_left_position) {
	if (document.layers && document.layers[this.name] && document.layers[this.name].left) {
		temp = new_left_position + this.leftOffset;
		this.css2.left = temp.toString() + 'px';
	} else if (document.all && document.all[this.name] && document.all[this.name].style && document.all[this.name].style.left) {
		temp = new_left_position + this.leftOffset;
		this.css2.style.left = temp.toString() + 'px';
	} else if (document.getElementById && document.getElementById(this.name) && document.getElementById(this.name).style && document.getElementById(this.name).style.left) {
		temp = new_left_position + this.leftOffset
		this.css2.style.left = temp.toString() + 'px';
	}
}

// hide element
function domHide() {
   this.css2.style.visibility = "hidden";
}

// show element
function domShow() {
   this.css2.style.visibility = "visible";
}

// The Navigator 4.x Objects
// hide element
function nsobjHide() {
	this.css2.visibility = "hidden";
}

// show element
function nsobjShow() {
	this.css2.visibility = "inherit";
}

// Create the objects
// menu will not function until all objects are created and the turnOn function is called
function create_objects() {
    if (document.all && document.all.tags)
		create_ie_objects();
    else if (document.layers && document.layers.length)
		create_ns_objects();
	else if (document.getElementsByTagName)
		create_dom_objects();
}

// For IE, pull all DIV blocks into object array
function create_ie_objects() {
	theelements = document.all.tags('div');
	theobjs = new Array();
	for (i = 0; i < theelements.length; i++){
		if (theelements[i].id != '') {
			theobjs[theelements[i].id] = new dom_object(theelements[i]);
		}
	}
	create_nodes();	
}

// For Navigator 4.x, pull all DIV blocks into object array
function create_ns_objects(newarray) {
	theobjs = new Array();
	for (i = 0; i < document.layers.length; i++) {
		if (document.layers[i].name != '') {
			theobjs[document.layers[i].name] = new ns_object(document.layers[i]);
		}
	}
	create_nodes();	
}

// For W3C DOM (Navigator 6.x, Mozilla, IE), pull all named DIV blocks into an array
function create_dom_objects() {
	theelements = document.getElementsByTagName('div');
	theobjs = new Array();
	for (i = 0; i < theelements.length; i++) {
		var obj = theelements[i];
		if (obj.id != '') {
			theobjs[obj.id] = new dom_object(obj);
		}
	}
	create_nodes();	
}

// For dhtml navigation highlights
var color = '';

function over(id,alayer,color) {
    if (document.layers) {
		window.color = window.document.layers[alayer].document.layers[id].bgColor;
        window.document.layers[alayer].document.layers[id].bgColor = color;
    }
    else if (document.all) {
        window.color = window.document.all[id].style.background;
        window.document.all[id].style.background = color;
    }
	 else if (document.getElementById) {
        window.color = window.document.getElementById(id).style.background;
        window.document.getElementById(id).style.background = color;
    }
}

function out(id,alayer,color) {
    if (document.layers) {
        window.color = window.document.layers[alayer].document.layers[id].bgColor;
        window.document.layers[alayer].document.layers[id].bgColor = color;
    }
    else if (document.all) {
        window.color = window.document.all[id].style.background;
        window.document.all[id].style.background = color;
    }
	 else if (document.getElementById) {
        window.color = window.document.getElementById(id).style.background;
        window.document.getElementById(id).style.background = color;
   }
}

// menu code
function menu_center(opt) {
	var current_width = determine_page_width();
	if (current_width >	987)
		new_left_position = Math.round((current_width-986)/2, 0);
	else
		new_left_position = 0;
	if (theobjs['TM']) theobjs['TM'].setLP(new_left_position);

	var DIVs = document.getElementsByTagName('div');
	for (var d = 0; d < DIVs.length; d++) {
		if (DIVs[d].id.substr(0, 2) == 'DD' && theobjs[DIVs[d].id]) {
			theobjs[DIVs[d].id].setLP(new_left_position);
		}
	}
	if (opt == 'y' && MainSwitch == 1 && theobjs['TM']) theobjs['TM'].objShow();
}

function determine_page_width() { 
	var myWidth = 0; 
	if (document.width) {
		myWidth = document.width;
	} else if( typeof( window.innerWidth ) == 'number' ) { 
		myWidth = window.innerWidth; // doesn't work if there's a vertical scrollbar
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
		myWidth = document.documentElement.clientWidth; 
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
		myWidth = document.body.clientWidth; 
	} 
	return myWidth
} 

function create_nodes() {
	var TDs = document.getElementsByTagName('td');
	for (var t = 0; t < TDs.length; t++) {
		if (TDs[t].className == 'TopNavItem') {
			var node = TDs[t];
			addEvent(node, 'mouseover', getMoverFor(node), false);
			addEvent(node, 'mouseout', getMoutFor(node), false);
			node.TMin = false;
			node.DDin = false;
		}
	}
	var DIVs = document.getElementsByTagName('div');
	for (var d = 0; d < DIVs.length; d++) {
		if (DIVs[d].id.substr(0, 2) == 'DD') {
			if (theobjs[DIVs[d].id]) DDisOn[DIVs[d].id.toString] = DIVs[d].id;
			var node = DIVs[d];
			addEvent(node, 'mouseover', getMoverFor(node), false);
			addEvent(node, 'mouseout', getMoutFor(node), false);
			node.TMin = false;
			node.DDin = false;
			DDList[DIVs[d].id] = node;
			
			// change the class for the last "li" in list to "DDBottom"
			node.getElementsByTagName('li')[node.getElementsByTagName('li').length-1].className += ' DDBottom';
		}
	}
	turnOn();
}

function getMoverFor(node) {
	return function(e) { mover(e, node); };
}

function getMoutFor(node) {
	return function(e) { mout(e, node); };
}

function mover(e, targetElement) {
	var el = window.event ? targetElement : e ? e.currentTarget : null;
	if (!el) return;
	clearTimeout(el.outTimeout);
	if (DDList['DD' + el.id.substr(2)]) {
		if (!DDList['DD' + el.id.substr(2)].TMIn && !DDList['DD' + el.id.substr(2)].DDIn) {
			clearInterval(DDList['DD' + el.id.substr(2)].intervalID);
			DDList['DD' + el.id.substr(2)].style.display = 'block';
			DDList['DD' + el.id.substr(2)].savedOW = DDList['DD' + el.id.substr(2)].offsetWidth;
			DDList['DD' + el.id.substr(2)].savedOH = DDList['DD' + el.id.substr(2)].offsetHeight;
			DDList['DD' + el.id.substr(2)].clippingRectangle = [0, DDList['DD' + el.id.substr(2)].offsetWidth, 0, 0];
			DDList['DD' + el.id.substr(2)].style.display = 'none';
			DDList['DD' + el.id.substr(2)].intervalID = setInterval(function() {showMenu(DDList['DD' + el.id.substr(2)]);}, 10);
			//if (theobjs['DD' + el.id.substr(2)]) show_menu(el.id.substr(2));
		}
		if (el.id.substr(0, 2) == 'DD')
			DDList['DD' + el.id.substr(2)].DDIn = true;
		else if (el.id.substr(0, 2) == 'TM')
			DDList['DD' + el.id.substr(2)].TMIn = true;
	}
	el.className += '';   // Force IE to recompute styles
}

function mout(e, targetElement) {
	var el = window.event ? targetElement : e ? e.currentTarget : null;
	if (!el) return;
	if (DDList['DD' + el.id.substr(2)]) el.outTimeout = setTimeout(function() { mout2(el); }, 300);
}

function mout2(el) {
	if (el.id.substr(0, 2) == 'DD')
		DDList['DD' + el.id.substr(2)].DDIn = false;
	else if (el.id.substr(0, 2) == 'TM')
		DDList['DD' + el.id.substr(2)].TMIn = false;
	if (!DDList['DD' + el.id.substr(2)].TMIn && !DDList['DD' + el.id.substr(2)].DDIn) {
		clearInterval(DDList['DD' + el.id.substr(2)].intervalID);
		DDList['DD' + el.id.substr(2)].intervalID = setInterval(function() {hideMenu(DDList['DD' + el.id.substr(2)]);}, 10);
	}
	//if (!DDList['DD' + el.id.substr(2)].TMIn && !DDList['DD' + el.id.substr(2)].DDIn && theobjs['DD' + el.id.substr(2)]) theobjs['DD' + el.id.substr(2)].objHide();
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		EventCache.add(elm, evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

function showMenu(el) {
	el.clippingRectangle[2] += 10;
	if (el.clippingRectangle[2] >= el.savedOH) {
		el.clippingRectangle[2] = el.savedOH;
		clearInterval(el.intervalID);
		// reset the clip: browser-specific
		if (document.all && !window.opera) {
			el.style.clip = 'rect(auto, auto, auto, auto)';
		} else {
			el.style.clip = '';
		}
		return;
	}
	el.style.clip = 'rect(' + el.clippingRectangle.join('px ') + 'px)';
	el.style.display = 'block';
  }

function hideMenu(el) {
	el.clippingRectangle[2] -= 10;
	if (el.clippingRectangle[2] <= 0) {
		el.clippingRectangle[2] = 0;
		clearInterval(el.intervalID);
		// reset the clip: browser-specific
		if (document.all && !window.opera) {
			el.style.clip = 'rect(auto, auto, auto, auto)';
		} else {
			el.style.clip = '';
		}
		el.style.display = 'none';
		return;
	}
	el.style.clip = 'rect(' + el.clippingRectangle.join('px ') + 'px)';
}

function show_menu(id) {
	if (MainSwitch == 1) {
		theobjs['DD'+id].objShow();
	}
}

function rollover(n) {
	if (ImageSwitch == 1 && n != '') eval('document.' + n + '.src = ' + n + '_on.src;');
}

function rolloff(n) {
	if (ImageSwitch == 1 && n != '') eval('document.' + n + '.src = ' + n + '_off.src;');
}

function preload_images() {
	water_taxi_button_on = new Image;
	water_taxi_button_off = new Image;
	water_taxi_button_on.src = '/images/bottom_right/water_taxi_button_ro.gif';
	water_taxi_button_off.src = '/images/bottom_right/water_taxi_button.gif';
	ImageSwitch = 1;
}

addEvent(window, 'load', preload_images, false);
addEvent(window, 'unload', EventCache.flush, false);
addEvent(window, 'resize', menu_center, false);


// code for scrolling announcement settings
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var rotation_time = 5000; //time in milliseconds

$(document).ready(function(){
	headline_count = $("div.headline").size();
	current_headline = 0;
	var h1=$("#headline"+current_headline).height();
	var h2=$("#scrollup").height();
	h=Math.round((h2-h1)/2.3);
	$("#headline"+current_headline).show().animate({top: h},2000);
	if (headline_count>1) headline_interval = setInterval(headline_rotate,rotation_time);
	old_headline = current_headline;
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count
	var h2=$("#scrollup").height();
	var h1=$("#headline"+current_headline).height();
	var h3=$("#headline"+old_headline).height();
	$("#headline"+old_headline).animate({top: -h3},2000, function() {
    	$(this).css('top', h2+'px');
    });
	h=Math.round((h2-h1)/2.3);
	$("#headline"+current_headline).show().animate({top: h},2000);
	old_headline = current_headline;
}

