function WM_preloadImages() {
  if (document.images) {
    if (typeof(document.WM) == 'undefined'){
      document.WM = new Object();
    }
    document.WM.loadedImages = new Array();
    var argLength = WM_preloadImages.arguments.length;
    for(arg=0;arg<argLength;arg++) {
      document.WM.loadedImages[arg] = new Image();
      document.WM.loadedImages[arg].src = WM_preloadImages.arguments[arg];
    }
  }
}
function generateTag(imgName) {
	var name_parts = imgName.split('.');
	mouseover_filename = name_parts[0] +'__'+ mouseoverchoice +'.'+ name_parts[1];
	return "<img src=\"thumbnails/" + mouseover_filename + "\" alt=\"\" border=\"0\" />";
}
var RICHARDGATE = {
	cache: {}
};
function paintingMouseover(imgName, selector) {
	// window.location.hash = selector;
	if (typeof(RICHARDGATE.cache[selector]) === 'undefined') {
		RICHARDGATE.cache[selector] = generateTag(imgName);
	}
	$('#painting').html(RICHARDGATE.cache[selector]);
}
$(document).ready(function() {

	$('#topNavigation ul li[class^="child-"] a').each(function(){
		$(this).toggle(function(){
			var id = '#' + $(this).parents('li:first').attr('class').split('-')[1];
			$(id).fadeIn('slow');
			return false;
		}, function(){
			var id = '#' + $(this).parents('li:first').attr('class').split('-')[1];
			$(id).fadeOut('fast');
			return false;
		});
	});
	
	var imgPreloads = [];
	$('.hiddenPhoto img').each(function(i){
		imgPreloads[i] = new Image();
		imgPreloads[i].src = $(this).attr('src');
	});

	if ($('#bodyangling').length > 0) {
		$('a[id^=angling-link]').bind('mouseover', function(){
			var counter = $(this).attr('id').split('_')[1];
			$('#displayPhoto').html($('#photo' + counter).html());
		});
	}
	
	$('.painting-nav').bind('click', function(){
		$('#whatever').html($('#paintingNav' + $(this).index()).html());
		$('.painting-nav').css({ textDecoration: 'none' });
		$(this).css({ textDecoration: 'underline'});
	});
	
	if ($('#bodypaintings').length > 0) {
		var page_id = window.location.hash.split('-')[0];
		switch(page_id) {
			case '#p1': case '#p2': case '#p3':
				break;
			default:
				page_id = '#p1';
		}
		$(page_id).trigger('click');
		if (window.location.hash.length > 2) {
			$(window.location.hash).trigger('mouseover');
		}
	}
	$('a.regular').click(function(){
		$('#loading').show();
	});
	$('#loading').fadeOut();


});