jQuery.preloadImages = function(){
  for(var i = 0; i<arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function prepareGallery(){
	var gallery = document.getElementById("imageGallery");
	var links = gallery.getElementsByTagName("a");
	for( i=0; i<links.length; i++){
		links[i].onclick = function() {
			showpic(this,this.id); // 2.14.08 updated with extra param for button nav functionality
			return false;
		}
	}
}

function showpic(whichPic,id) {
	var source = whichPic.getAttribute("href");
	var text = whichPic.getAttribute("title"); 
	var placeholder = document.getElementById("placeholder");
	var old = placeholder.getAttribute("src");
	var otext = placeholder.getAttribute("title");
	placeholder.setAttribute("src",source);
	placeholder.setAttribute("title",text);
	
	$("#description").empty();
	$("#description").append(text); 
	
	photo_nav(id,old,text,otext); 
}

function photo_nav(id,pic,text,otext) {
	var navigation = document.getElementById("imageGallery");
	var newID = $("span.nonlink").attr("id");
	$('span.nonlink').replaceWith('<a id="'+newID+'" title="'+otext+'" href="'+pic+'">'+newID+'</a>');
	$("a").remove("#"+id);
	$('#'+id).replaceWith('<li id="'+id+'"><span class="nonlink" title="'+text+'" id="'+id+'">'+id+'</span></li>');
	prepareGallery();
}


function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;
}

function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}

