//	get the current page
	function get_current_page() {
		var fullpath = location.pathname;
		var patharray = fullpath.split('/');
		var folderposition = patharray.length - 1;
		var filename = patharray[folderposition];
		var filearray = filename.split('.');
		var nav = filearray[0];
		return nav;
	}

//	OPEN EXTERNAL LINKS IN A NEW WINDOW
	function externalLinks() { 
		if (!document.getElementsByTagName) return; 
		var anchors = document.getElementsByTagName("a"); 
		for (var i=0; i<anchors.length; i++) { 
			var anchor = anchors[i]; 
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
			anchor.target = "_blank"; 
		} 
	} 

//	ACTIVATE THE SEARCH CRITERIA FIELD
	function search_focus() {
		var criteria = document.getElementById('q').value;
		if ( criteria == 'search...' ) {
			document.getElementById('q').value = '';
		} else {
			return true;
		}	
	}

//	DEACTIVATE THE SEARCH CRITERIA FIELD
	function search_blur() {
		var criteria = document.getElementById('q').value;
		if ( criteria == '' ) {
			document.getElementById('q').value = 'search...';
		} else {
			document.getElementById('q').value = criteria;
		}
	}

//	ADD PAGE TO FAVOURITES
	function setBookmark(url,str){
		if(str=='')str=url;
		if (document.all)window.external.AddFavorite(url,str);
		else alert('Sorry, this function only works in Internet Explorer.\n\nPlease press CTRL and D to add a bookmark to \n"'+str+'".');
	}

//	HIDE SUB NAVIGATION ELEMENTS
	function hide_sub_nav() {
		if ( document.getElementById('sub_history') != undefined ) document.getElementById('sub_history').style.display = 'none';		
		if ( document.getElementById('sub_today') != undefined ) document.getElementById('sub_today').style.display = 'none';		
		if ( document.getElementById('sub_itinerary') != undefined ) document.getElementById('sub_itinerary').style.display = 'none';
	}

//	SHOW A GIVEN ELEMENT
	function show(el) {
		if ( document.getElementById(el) != undefined ) document.getElementById(el).style.display = '';
	}

//	HIDE A GIVEN ELEMENT
	function hide(el) {
		if ( document.getElementById(el) != undefined ) document.getElementById(el).style.display = 'none';
	}

//	HIGHLIGHT THE CURRENT NAVIGATION
	function highlight_current_nav(current) {
		if ( current == 'captains_log' ) {
			document.getElementById('captains_log').className = 'current';
		} else {
			if ( document.getElementById(current) != undefined ) document.getElementById(current).className = 'current';
		}
	}

//	SHOW ANY AUB NAVIGATION FOR THE CURRENT PAGE
	function display_current_nav() {
	
		var url = unescape(location.href);
		var xstart = url.lastIndexOf("/") + 1;
		var xend = url.lastIndexOf(".") + 4;
		
		var hereName = url.substring(xstart,xend);
		var herePath = url.substring(0,xstart);
	
		var croppedEnd = herePath.length - 1;
		var croppedPath = herePath.substring(0,croppedEnd );
		var pStart = croppedPath.lastIndexOf("/") + 1;
		var pEnd = croppedPath.length;
	
		var currDir = url.substring(pStart,pEnd);		
		
		var currPageStart = hereName.lastIndexOf(".");
		var currPage = hereName.substring(0,currPageStart);
		
		highlight_current_nav( currPage );
		
		switch ( hereName ) {
		
			case 'about_halcyon.php' :
			case 'history.php' :
			case 'restoration.php' :
			case 'halcyon_memories.php' :
				show('sub_history');
				break;
				

			case 'booking_enquiry.php' :
			case 'crew.php' :
			case 'captains_log.php' :
			case 'cuisine.php' :
			case 'recipe_book.php' :
			case 'specifications.php' :
			case 'accommodation.php' :
			case 'gallery.php' :
			case 'video_gallery.php' :
			case 'news.php' :
			case 'press.php' :
			case 'guestbook.php' :
			case 'faqs.php' :
			case 'desktops.php' :
			case 'ecards.php' :
				show('sub_today');
				break;
				

					case 'itinerary.php' :
			case 'accommodation.php' :
			case 'cruising_areas.php' :
			case 'where_is_halcyon.php' :
				show('sub_itinerary');
				break;
			
		}
	
	}

function fisherYates ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 2000;
// Duration of crossfade (seconds)
var crossFadeDuration = 1;
// Specify the image files
var TopPic = new Array();

// to add more images, just continue
// the pattern, adding to the array below

var this_page = get_current_page();

switch ( this_page ) {

	case 'guests_groups' :
		TopPic[0] = 'media/slideshow/guest_group/1.jpg';
		TopPic[1] = 'media/slideshow/guest_group/2.jpg';
		TopPic[2] = 'media/slideshow/guest_group/3.jpg';
		TopPic[3] = 'media/slideshow/guest_group/4.jpg';
		break;
		
	case 'guests_singles_couples' :
		TopPic[0] = 'media/slideshow/guest_singles/1.jpg';
		TopPic[1] = 'media/slideshow/guest_singles/2.jpg';
		TopPic[2] = 'media/slideshow/guest_singles/3.jpg';
		TopPic[3] = 'media/slideshow/guest_singles/4.jpg';
		break;
		
	case 'guests_corporate' :
		TopPic[0] = 'media/slideshow/guest_corporate/1.jpg';
		TopPic[1] = 'media/slideshow/guest_corporate/2.jpg';
		TopPic[2] = 'media/slideshow/guest_corporate/3.jpg';
		TopPic[3] = 'media/slideshow/guest_corporate/4.jpg';
		break;
		
	case 'guests_passage_makers' :
		TopPic[0] = 'media/slideshow/guest_passage/1.jpg';
		TopPic[1] = 'media/slideshow/guest_passage/2.jpg';
		TopPic[2] = 'media/slideshow/guest_passage/3.jpg';
		TopPic[3] = 'media/slideshow/guest_passage/4.jpg';
		break;
		
	default :
		TopPic[0] = 'media/slideshow/1.jpg';
		TopPic[1] = 'media/slideshow/2.jpg';
		TopPic[2] = 'media/slideshow/3.jpg';
		TopPic[3] = 'media/slideshow/4.jpg';
		TopPic[4] = 'media/slideshow/5.jpg';
		TopPic[5] = 'media/slideshow/6.jpg';
		TopPic[6] = 'media/slideshow/7.jpg';
		TopPic[7] = 'media/slideshow/8.jpg';
		TopPic[8] = 'media/slideshow/9.jpg';
		TopPic[9] = 'media/slideshow/10.jpg';
		TopPic[10] = 'media/slideshow/11.jpg';
		TopPic[11] = 'media/slideshow/12.jpg';
		break;
		
}


fisherYates(TopPic);

var e;
var f;
var g;
var j = 0;
var x = 0;
var y = 0;
var z = 0;
var k = 0;
var p = 11;
var preLoadTop = new Array();
for (a = 0; a < TopPic.length; a++) {
preLoadTop[a] = new Image();
preLoadTop[a].src = TopPic[a];
}

function runSlideShowTop() {
	if ( document.getElementById('slide') != undefined ) {
		if (document.all) {
			document.images.slide.style.filter="blendTrans(duration=3)";
			document.images.slide.style.filter="blendTrans(duration=crossFadeDuration)";
			document.images.slide.filters.blendTrans.Apply();
		}
		document.images.slide.src = preLoadTop[x].src;
		if (document.all) {
			document.images.slide.filters.blendTrans.Play();
		}
		x = x + 1;
		if (x >= TopPic.length) x = 0;
		e = setTimeout('runSlideShowTop()', 3000);
	}
}


	window.onload = function(e) {
		externalLinks();
		hide_sub_nav();
		display_current_nav();
		runSlideShowTop();
	}
