$.noConflict();
jQuery(document).ready(function($) {
	// browser independent way of checking if image loaded
	var imageOk = function(img) {
		if (typeof(img.naturalWidth) != "undefined") {
			return img.naturalWidth > 0;
		} else {
			return img.complete;
		}
	};
	
	// add timestamp query param to the passed url string
	var timestampUrl = function(url) {
		if (!url.match(/timestamp=\d+/)) {
			url += (url.match(/\?/) ? '&' : '?') + 'timestamp=0';
		}
		return url.replace(/timestamp=\d+/, 'timestamp=' + new Date().getTime());
	};

	$(window).load(function() {
	  $('img.composed_image').each(function() {
			if (!imageOk(this)) {
				var img = $(new Image());
				var src = $(this).attr('src');
				$(this).replaceWith(img);

				img.hide()
					.wrap($('<div />').attr('class', $(this).attr('class')).addClass('loading'))
					.error(function() {
						setTimeout(function() { img.attr('src', timestampUrl(src)); }, 2000);
					})
					.load(function() {
						img.unbind('error').fadeIn().parent().removeClass('loading');
					})
					.attr('src', timestampUrl(src));
			}
		});
	});
	
	if (document.location.hash) {
		$(document.location.hash).addClass('selected_anchor');
	}
});
