     $(document).ready(function() {

       $("#navigation ul li > a").each(function(){
		$(this).click(function() {
			x = $(this).attr("id");
			processLink(x);
		return false;
		});
		//$("#navigation_under").animate({"left": "+=192px"}, "slow");
		
		});

	$('#homelink').click(function() {
		showHomePage();
		return false;
		});
		
	$('#aboutlink').click(function() {
		showHTMLContent(2);
		return false;
		});
	
	$('.contactlink').live("click",function(){
		showHTMLContent(3);
		return false;
		});

	});

	 var numberofmenuitems = 5;
	 var menuitemwidth = 192;
	 	 var album = new Array();
	 album[1] = 9;
	 album[2] = 5;
	 album[3] = 6;
	 album[4] = 7;
	 album[5] = 8;
	 
	 var albumtitle = new Array();
	 albumtitle[1]="Painted Portraits";
	 albumtitle[2]="Pencil Portraits";
	 albumtitle[3]="Personal Stationery";
	 albumtitle[4]="Personal Presents";
	 albumtitle[5]="Baby Presents";

	 function processLink(x) {
	var newposition = x;
		if (HTMLContent==1) {
			//alert('HTMLContent is 1!');
			$("#flashcontent").css('height','530px');
			$("#html_content").css("display","none").html('');
			$("#html_heading").css("display","none").html('');
			$('#caption_spiel').css('display','none');
			$('#gallery_spiel').fadeIn('fast');
			}
		$('#caption_spiel').hide();
		
		var factor = newposition - currentposition;
		//alert(GalleryStatus);
		//New HTMLContentTests Added here for the animation of the navigation_under opacity.  It's getting messy.  May have to redesign this function.
		if (factor == 0) {
			if (HTMLContent==1) {
			//alert('Altering opacity!');
				$("#navigation_under").animate({"opacity": 1}, "slow");
				HTMLContent=0;
				$("#caption_spiel").fadeIn('fast');
				$("#gallery_spiel").fadeIn('fast');
				}
			//A conditional statement to load an album in the case when the same button is clicked (HTMLContent conditional statements simply make the flash file appear again)
			if (GalleryStatus==1) {
				
				sspLoadAlbum("album-" + album[newposition],0);
				}
		}
		else {
			if (HTMLContent==1) {
				$("#navigation_under").animate({"opacity": 1}, "slow").animate({"left": "+=" + (factor*menuitemwidth) + "px"}, "slow");
				currentposition = newposition;
				sspLoadAlbum("album-" + album[newposition],0);
				$('#gallery_spiel').css('display','none').html(gallery_description[newposition]);
				HTMLContent=0;
				}
			else {
		
			//alert("We need to travel by " + (factor*menuitemwidth) + " pixels");
			$("#navigation_under").animate({"left": "+=" + (factor*menuitemwidth) + "px"}, "slow");
			currentposition = newposition;
			//alert(album[newposition]);
			sspLoadAlbum("album-" + album[newposition],0);
			$('#gallery_spiel').css('display','none').html(gallery_description[newposition]);
			//$('#gallery_spiel');
				}
			}
			GalleryStatus = 0;
			CurrentAlbumId=x;
	}
	 
   function sspLoadAlbum(x,y) {
     if(thisMovie("flashcontent")!=undefined) {
     thisMovie("flashcontent").sspLoadAlbum(x,y);}
   }
   
    function sspToggleGallery() {
      if(thisMovie("flashcontent")!=undefined) {
      thisMovie("flashcontent").sspToggleGallery();}
   }  

   function thisMovie(movieName) {
   return swfobject.getObjectById(movieName);
	}
	
function albumIden(albumData) {
	//Temporary Fix for Non updating gallery issue.
	//alert (albumData);
	if (albumData == 'album-9') {
		processLink(1);
		GalleryStatus = 0;
		}
	else if (albumData == 'album-5') {
		processLink(2);
		GalleryStatus = 0;
		}
	else if (albumData == 'album-6') {
		processLink(3);
		GalleryStatus = 0;
			}
	else if (albumData == 'album-7') {
		processLink(4);
		GalleryStatus = 0;
		}
	else if (albumData == 'album-8') {
		processLink(5);
		GalleryStatus = 0;
		}
	//alert('albumIden');
}
	
function imageIden(idData, titleData, captionData) {
	//$('#album').html(albumData);
	if (!idData) {var imageid=0;}
	else {
		var idData = idData.split('-');
		var imageid = parseInt(idData[1]);
		}
	if (!titleData) {var imagetitle="";}
	else {var imagetitle = titleData;}
	if (!captionData) {var caption="";}
	else {var caption = captionData;}
	if (CurrentAlbumId == 2 || CurrentAlbumId == 5) {
		if (titleforce[imageid]){
			$('#gallery_spiel').html('<h1>' + titleforce[imageid] + '</h1><h2>' + imagetitle + '</h2>');
			$('#caption_spiel').html('<p>' + caption + '</p><p><i>' + salespitch[imageid] + '</i></p><p style="color:#8e8585">Link: <i>http://www.zazashelley.com/' + hyperlinkAString(titleforce[imageid]) + '.html</i></p>');
			$(document).attr('title', titleforce[imageid] + ' - Zaza Shelley');
			}
		else {
			$('#gallery_spiel').html('<h1>Pencil Portraits</h1><h2>' + imagetitle + '</h2>');
			$('#caption_spiel').html('<p>' + caption + '</p><p><i>To enquire about commissions such as these, please get in touch <a class="contactlink" href="http://www.zazashelley.com/contact.html">here</a>.</i></p>');
		}
		$('#caption_spiel').show();
		
		}
	else {
		$('#gallery_spiel').html('<h1>' + albumtitle[CurrentAlbumId] + '</h1><h2>' + imagetitle + '</h2>');
		$('#caption_spiel').html('<p>' + caption + '</p>');
		$('#caption_spiel').append(gallery_description[CurrentAlbumId]);
		$('#caption_spiel').show();
		$(document).attr('title', albumtitle[CurrentAlbumId] + ' - Zaza Shelley');
		}
	//alert('imageIden');
	$('#gallery_spiel').fadeIn('fast');
	$('#caption_spiel').fadeIn('fast');
	}

//A variable to determine if HTMLContent is present rather than the Flash Gallery (Set at one initially to make stuff behave)
HTMLContent = 1;
//A variable to determine if the gallery is visible
GalleryStatus = 1;
	
function showHTMLContent(x) {
	$("#navigation_under").animate({"opacity": 0.15}, "slow");
	HTMLContent = 1;
	if (x == 2) {$(document).attr('title', 'About - Zaza Shelley');}
	if (x == 3) {$(document).attr('title', 'Contact - Zaza Shelley');}
	$("#flashcontent").css('height','0');
	//Hide HTML elements so they can be smoothly updated before sliding them down.
	$("#html_content").hide();
	$("#html_heading").hide();
	//Hide Caption and Gallery Spiels and clear them so they represent what they should represent for Google Spiders.
	$("#caption_spiel").hide().html();
	$("#gallery_spiel").hide().html();	
	$("#html_content").html(html_content[x]);
	$("#html_heading").html(html_contentb[x]);
	$("#html_heading").slideDown("normal");
	$("#html_content").slideDown("normal");
}

function showHomePage() {
	$("#navigation_under").animate({"opacity": 0.15}, "slow");
	if (HTMLContent = 1) {
		$("#flashcontent").css('height','530px');
		$("#html_content").css("display","none").html('');
		$("#html_heading").css("display","none");
		}
	else {
		HTMLContent = 1; //I know the labelling is bad but we use HTMLContent to fade #navigation_under..etc.
	//This function is the same as showHTMLContent(x) except with the removal of #html_content stuff (this is within the div that the flash file resides) and the addition of sspToggleGallery()
		}
	if (GalleryStatus==0) {
		sspToggleGallery();
		//alert('Changing Gallery Status to 1!');
		GalleryStatus=1;
		//alert('Gallery Status Changed! Look' + GalleryStatus);
		}
	$("#caption_spiel").hide().html();
	$("#gallery_spiel").hide().html();
	$("#html_heading").html(html_contentb[1]);
	$("#html_heading").slideDown("normal");
	$(document).attr('title', 'Portrait, Stationery and Art Commissions by Zaza Shelley');
}

function hyperlinkAString(string) {
//Remove any white space from the beginning or the end of the string.
$.trim(string);

//Remove all characters except white space, letters or digits
string = string.replace(/[^\da-z ]/ig,'');

//Reduce multiple white spaces to a single white space (Avoiding unecessary '--'...etc in the hyperlink.
string = string.replace(/ +/g, ' ');

//Replace the white space with 'dashes'
string = string.replace(/[\s]/g, '-');

//Make all of the letters lowercase
string = string.toLowerCase();
return string;
}
