	$(document).ready(function(){
		
		if ( $('#galleryImage').length ) {

	    	var hash = window.location.hash.substr(1);
			if (hash.length) {
		    	var toLoad = 'image.php?imageid=' + hash.substr(3,hash.length) + '#galleryImage';
		    	$('#galleryImage').load(toLoad)	
	    	}
	    		
			$('a.galleryThumbs img').click(function(event){
				event.preventDefault();
				var image_url = $(this).attr('src');
				image_qs = [];
				image_qs = (image_url.split('?id='))[1].split('&');
				image_id = image_qs[0];
				//need to get page from query string
				url_part = [];
				url_whole = window.location.href;
				url_part1 = url_whole.split('page=');
				if (url_part1[1]) {
					url_part2 = url_part1[0].split('&')[0];
					url_part3 = url_part2.split('#');
					pageid = url_part3[0];
					
				} else {
					pageid = 1;
				}
			    var toLoad = 'image.php?imageid=' + image_id + "&page=" + pageid;
			    $('#galleryImage').fadeOut('slow',loadContent);
			    window.location.hash = "img" + image_id;
			    function loadContent() {
			    	$('#galleryImage').load(toLoad,'',showNewContent())
			    }
			    
			    function showNewContent() {
			    	$('#galleryImage').fadeIn('slow');
		
		
			    }
			    return false;
		    
		    });
	    }
		
	});