var str_src = "";
var str_alt = "";
var str_path_to_root = "";	// stores path to root folder, useful if we're in a sub-folder

function gallery_show(str_object) {
	if (document.location.href.indexOf("photo-gallery.htm")>=0)  {	// override default image swapping on photo gallery page - swap movies instead
		embed_flash("gallery", "images/bath-hotel-gallery.swf?data=" + str_object.replace("image_","gallery_") + ".xml", "335", "400");
	} else {
		var obj_source_img = document.getElementById(str_object);
		var obj_display_img = document.getElementById("image_0");
		if (obj_source_img) {
			if (str_src == "") {
				str_src = obj_display_img.src;
				str_alt = obj_display_img.alt;
			} // end if
			if (str_object == "image_0") {
				obj_display_img.src = str_src;
				obj_display_img.alt = str_alt;
			} else {
				obj_display_img.src = obj_source_img.src;
				obj_display_img.alt = obj_source_img.alt;
			} // end if
		} // end if
	} // end if
	
	// set navigation state
	if (!document.getElementsByTagName) return;
	var arr_anchors = document.getElementById("sub-nav").getElementsByTagName("a"); 
	for (var int_i=0; int_i < arr_anchors.length; int_i ++) { 
		var obj_anchor = arr_anchors[int_i]; 
		if (obj_anchor.getAttribute("href")) {
			if (obj_anchor.getAttribute("href").indexOf("#" + str_object.replace("_","-")) >=0){
				obj_anchor.style.textDecoration = "underline";
			} else {
				obj_anchor.style.textDecoration = "none";
			} // end if
		} //end if 
	} // end for

	return true;
} // end function

function gallery_navigation_update_to(int_current) {
	var obj_nav = document.getElementById("sub-nav");
	if (obj_nav) {
		var arr_links = obj_nav.getElementsByTagName("a");
		if (arr_links.length > 0) {
			for (var int_i = 0; int_i < arr_links.length; int_i++) {
				if (int_i == int_current) {
					arr_links[int_i].style.textDecoration = "underline";
				} else {
					arr_links[int_i].style.textDecoration = "none";
				} // end if
			} // end for
		} // end if
	} // end if
	return true;
} // end function

function embed_flash(str_id, str_src, str_width, str_height) {
	var arr_flashvars = {};
	var arr_params = {wmode:"transparent",quality:"high"};
	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 js_load_objects() {
	var str_location = document.location.href;
	str_location = str_location.replace("http://","");
	str_location = str_location.replace("https://","");
	str_location = str_location.replace(document.domain,"");
	if (str_location.indexOf("htdocs/")>=0) {
		str_location = str_location.substring(str_location.indexOf("htdocs/")+7, str_location.length);
	} // end if
	if (str_location == "" || str_location == "/" )  { 
		load_splash();
	} // end if
//alert(str_location);

	if (str_location.indexOf("/")>=0)  {
		str_path_to_root = "../";	// we are within a folder
	} // end if 

	if (str_location.indexOf("photo-gallery.htm")>=0)  { 
		embed_flash("gallery", str_path_to_root + "images/bath-hotel-gallery.swf", "335", "400");
	} // end if
	if (str_location.indexOf("restaurant")<0)  {	// don't embed logo flash on restaurant pages
		embed_flash("bath-hotel", str_path_to_root + "images/bath-hotel.swf", "288", "142");
	} // end if

	// header animation
	embed_flash("bath-hotel-animation", str_path_to_root + get_advert(), "518", "102");

} // end function

function load_splash() {
	var obj_footer = document.getElementById("footer");
	if (obj_footer) {
		obj_footer.style.display = "none";
	} // end if
	var obj_page = document.getElementById("page");
	if (obj_page) {
		obj_page.style.display = "none";
	} // end if	
	embed_flash("page", str_path_to_root + "images/entrance.swf", "960", "675");
	obj_page.style.display = "block";
} // end function

function js_external_links() { 
	if (!document.getElementsByTagName) return; 
	var arr_anchors = document.getElementsByTagName("a"); 
	for (var int_i=0; int_i < arr_anchors.length; int_i ++) { 
		var obj_anchor = arr_anchors[int_i]; 
		if (obj_anchor.getAttribute("href")) {
			if ((obj_anchor.getAttribute("href").indexOf("http")>=0 && obj_anchor.getAttribute("href").indexOf("thequeensberry.co.uk")<0) || obj_anchor.getAttribute("href").indexOf(".pdf")>=0 || obj_anchor.getAttribute("href").indexOf("reservations.htm")>=0){
				obj_anchor.target = "_blank"; 
			} // end if
		} //end if 
	} // end for
} // end function 

function js_rollovers() { 
	if (!document.getElementsByTagName) return; 
	var obj_images = document.getElementById("image-links");
	if (obj_images) {
		var arr_images = obj_images.getElementsByTagName("img"); 
		for (var int_i=0; int_i < arr_images.length; int_i ++) { 
			var obj_image = arr_images[int_i]; 
			if (obj_image.getAttribute("src")) {
				if (obj_image.getAttribute("src").indexOf("the-aa")>=0) {
					add_event(obj_image, "mouseover", js_rollover);
					add_event(obj_image, "mouseout", js_rollout);
				} // end if
			} //end if 
		} // end for
	} // end if
} // end function 
function js_rollover(obj_event) { 
	var obj_image = get_event_element(obj_event);
	obj_image.src = obj_image.src.replace(".png","_over.png");
} // end function
function js_rollout(obj_event) { 
	var obj_image = get_event_element(obj_event);
	obj_image.src = obj_image.src.replace("_over.png",".png");
} // end function

function swap_img(str_id, str_src) {
	alert(str_src);
} // end function

function event_load(obj_event) {
	js_load_objects();
	js_external_links();
	js_rollovers();
} // end function
swfobject.addDomLoadEvent(event_load);


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 cancel_event(obj_event) {
	if (!obj_event) return false;
	if (isIE) {
		obj_event.returnValue = false;
		obj_event.cancelBubble = true;
	} else {
		obj_event.preventDefault();
		obj_event.stopPropagation && obj_event.stopPropagation();
	} // end if
	return false;	
} // 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
