// when the document is ready:
	$(document).ready(function(){
							   	
		// add the roll over pointer class to the thumbnails
		$("div.product img").hover(function() {
			$(this).addClass("pointer");
		},function(){
			// remove it on roll off
			$(this).removeClass("pointer");
		});	
		
		// give the li containing the thumbnails a function
		$("div.product img").click(function() {	
			var $$ = $(this);
			// get the html of the li to see what img it is									
			var clickedImg = $$.attr('src')
			// the name of the dirs containing the image
			var smallLocation = "sm-imgDir";
			var largeLocation = "lg-imgDir";
			// search and replace function defined below
			var imagePopup = replaceAll(clickedImg,smallLocation,largeLocation);
			
			var imgAlt = $$.attr('alt');
			// time now to change the medium image
			// fade it out and then do the following stuff
			// also fade out the image link
		
			tb_show(imgAlt,imagePopup,false);
			
		});
		
		var topLinkString = '<p class="topLink"><a href="#myLittleEmpire">top</a></p>'
		$("div.product").append(topLinkString);
		
		$(document).ScrollToAnchors(700);
	});

// this function search and replaces a string and returns the new string
// http://www.daveshuck.com/blog/index.cfm/2006/12/13/Javascript-examples--removeElement-and-replaceAll
function replaceAll( str, searchTerm, replaceWith, ignoreCase )   {
   var regex = "/"+searchTerm+"/g";
   if( ignoreCase ) regex += "i";
   return str.replace( eval(regex), replaceWith );
}


// rel = external to open in new window
$(function(){
	// fix for target=”_blank”
	$("a[@rel~=’external’]").click(function(){
		window.open($(this).attr("href"));
		return false;
	});
});