$(document).ready(function(){
 $('a[href*=#]:not([href=#])').click(function() {
   if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
   && location.hostname == this.hostname) {
     var $target = $(this.hash);
     $target = $target.length && $target 
     || $('[name=' + this.hash.slice(1) +']');
     if ($target.length) {
       var targetOffset = $target.offset().top;
       $('html,body')
       .animate({scrollTop: targetOffset}, 2000);
      return false;
     }
   }
 });
});

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 placeholder = document.getElementById("placeholder");
	var old = placeholder.getAttribute("src",source); // added to grab the original image to pass to the photo_nav(id of new element, url of old photo)
	placeholder.setAttribute("src",source);
	var text = whichPic.getAttribute("title");
	//var description = document.getElementById("description");
	//description.firstChild.nodeValue = text;
	photo_nav(id,old); // call the new nav function
}

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

$(document).ready(function(){
	$("div.amodule").hover(
	  function () {
		$(this).children(".abuttons").css('background','url(\"img/buy_listen_arrow.gif\") repeat-x #292634');
	  },
	  function () {
		$(this).children(".abuttons").css('background','#000');
	  }
	);
  });
