<!-- Requires: swfobject.js -->

function js_load_objects() {
	var str_root = "";
	var str_location = document.location.href;
	if (str_location.indexOf("htdocs")>=0 )  {	// debug mode
		str_root = str_location.substring(0, str_location.indexOf("htdocs")+6);
	} // end if

	// planning your visit
//	embed_flash("planning-your-visit", str_root + "/images/plan-visit.swf", "164", "311");
	// discoveries
	embed_flash("discoveries", str_root + "/images/discoveries.swf", "268", "315");
	embed_flash("latest-news", str_root + "/images/news.swf", "242", "303");
	embed_flash("latest-videos", "http://www.youtube.com/v/59n9bgtcG-4&hl=en&fs=1&rel=0&color1=0x000000&color2=0x000000", "242", "200");
	
	// special offers button
	var obj_element = document.getElementById("btn_special-offers");
	if (obj_element) {
		obj_element.href = "#";
		add_event(obj_element, "click", event_special_offer_click);
	} // end if
	
	// sub-nav
	var obj_element = document.getElementById("sub-nav");
	if (obj_element) {
		obj_element.className = "scripted";

		var obj_buttons = document.createElement("div");
		obj_buttons.id="sub-nav-buttons";
		obj_element.appendChild(obj_buttons);
	
		var obj_prev = document.createElement("a");
		obj_prev.href = "#";
		obj_prev.id = "sub-nav-previous";
		obj_prev.innerHTML = "<span>previous</span>"
		add_event(obj_prev, "click", event_sub_nav_click);
		obj_buttons.appendChild(obj_prev);

		var obj_current = document.createElement("a");
		obj_current.href = "#";
		obj_current.id = "sub-nav-choose";
		obj_current.innerHTML = "<span>choose</span>"
		add_event(obj_current, "click", event_sub_nav_click);
		obj_buttons.appendChild(obj_current);

		var obj_next = document.createElement("a");
		obj_next.href = "#";
		obj_next.id = "sub-nav-next";
		obj_next.innerHTML = "<span>next</span>"
		add_event(obj_next, "click", event_sub_nav_click);
		obj_buttons.appendChild(obj_next);

		var arr_elements = obj_element.getElementsByTagName("a");
		for (var int_i=0; int_i<arr_elements.length;int_i++) {
			add_event(arr_elements[int_i], "mouseout", event_sub_nav_leave);
			add_event(arr_elements[int_i], "mouseover", event_sub_nav_over);
		} // end for
	} // end if
} // end function
function sub_nav() {
	this.next_state = "";
	this.current_state = "closed";
	this.timer;
} // end function
var obj_sub_nav = new sub_nav();
function event_special_offer_click(obj_event) {
	var obj_element = get_event_element(obj_event);
	jsPopUp('voucher','570','');
	return false;
} // end function
function event_sub_nav_click(obj_event) {
	var obj_element = get_event_element(obj_event);
	switch (obj_element.id) {
		case "sub-nav-previous":
		case "sub-nav-next":
			// find current page in list of links, get href of previous, go there
			var str_current_page = document.location.href;
			str_current_page = str_current_page.substring(str_current_page.lastIndexOf("/")+1, str_current_page.length);
			str_current_page = str_current_page.substring(0,str_current_page.lastIndexOf(".htm")+4)
			var arr_links = document.getElementById("sub-nav").getElementsByTagName("a");
			var str_link_page = "";
			var int_current_index = 0;
			var int_next_index = 0;
			for (var int_i=0; int_i<arr_links.length-3;int_i++) {
				str_link_page = arr_links[int_i].href;
				if (str_link_page.indexOf(str_current_page) > 0) {
					int_current_index = int_i;
				} // end if
			} // end for
			if (obj_element.id == "sub-nav-previous") {
				if (int_current_index > 0) {
					int_next_index = int_current_index - 1;
				} else {
					int_next_index = arr_links.length-4;
				} // end if
			} else {
				if (int_current_index < arr_links.length-4) {
					int_next_index = int_current_index + 1;
				} else {
					int_next_index = 0;
				} // end if
			} // end if
			document.location.href = arr_links[int_next_index];
			break;
		case "sub-nav-choose":
			if (obj_element.className == "open") {
				obj_element.parentNode.parentNode.className = "scripted";
			} else {
				obj_element.parentNode.parentNode.className += " open";
			} // end if
			break;
	} // end switch
} // end function
function event_sub_nav_leave(obj_event) {
	var obj_element = get_event_element(obj_event);
	sub_nav_start_to_close();
} // end function
function event_sub_nav_over(obj_event) {
	obj_sub_nav.next_state = "open";
} // end function
function sub_nav_start_to_close() {
	obj_sub_nav.next_state = "closed";
	obj_sub_nav.timer = window.setTimeout("sub_nav_close()", 500);
} // end function
function sub_nav_close() {
	if (obj_sub_nav.next_state == "closed") {
		document.getElementById("sub-nav").className = "scripted";	// resets style
	} // end if
} // end function

function embed_flash(str_id, str_src, str_width, str_height) {
	var arr_flashvars = {};
	var arr_params = {wmode:"transparent",quality:"high",allowfullscreen:"true"};
	var arr_attributes = {};
	swfobject.embedSWF(str_src, str_id, str_width, str_height, "9.0.0", false, arr_flashvars, arr_params, arr_attributes);
	return true;
} // end function

function event_load(obj_event) {
	js_load_objects();
} // end function
swfobject.addDomLoadEvent(event_load);



defaultStatus = "Blue Reef Aquarium - the ultimate undersea safari";

function jsPopUp(name,id,id2,attr3) {
	windowName =  name;
	windowLeft = 100;
	windowTop=100;
	switch (windowName) {
		case 'voucher':	// voucher
			windowWidth = 251;
			windowHeight = id;	
			windowTop = 0;
			windowScrollbars = 0;
			windowURL = "index_voucher.htm";
			if (id2 != "") { windowURL += "?" + id2; }
			break;
	} // end switch
	windowProps = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + windowScrollbars + ",resizable=0,copyhistory=0,width=" + windowWidth + ",height=" + windowHeight + ",left=" + windowLeft + ",top=" + windowTop;
	window.open(windowURL,windowName,windowProps);				
} // end function


function add_event(obj_element, str_event_type, str_function) { 
	if (obj_element.addEventListener) {
		obj_element.addEventListener(str_event_type, str_function, false); 
		return true; 
	} else if (obj_element.attachEvent) { 
		var bln_result = obj_element.attachEvent("on" + str_event_type, str_function); 
		return bln_result; 
	} else { 
		return false; 
	} // end if
	if (str_event_type == "load") {		// automatically remove 'load' events when page is unloaded
		remove_event(obj_element, "unload", str_function);
	} // end if
} // end function
function remove_event(obj_element, str_event_type, str_function) {
	if (obj_element.removeEventListener) {
		obj_element.removeEventListener(str_event_type, str_function, false);
		return true;
	} else if (obj_element.detachEvent) {
		var bln_result = obj_element.detachEvent("on" + str_event_type, str_function);
		return bln_result;
	} else {
		return false;
	} // end if
} // end function
function get_event_element(obj_event) {
	var obj_event = get_event(obj_event);
	if (obj_event.target) obj_element = obj_event.target;
	else if (obj_event.srcElement) obj_element = obj_event.srcElement;
	if (obj_element.nodeType == 3)	obj_element = obj_element.parentNode;
	if (obj_element.nodeName == 'SPAN')	obj_element = obj_element.parentNode;	// events shouldn't exist on span elements (fix for '<a><span>link</span></a>' links)
	return obj_element;
} // end function
function get_event(obj_event) {
	if (!obj_event) var obj_event = window.event;
	return obj_event;
} // end function