$(document).ready(function() {
	//Preloading rollover images
	$(".rollover").each(function(i) {
		var hoverImgSrc = setUrlParam(this.src, 'blobcol', 'urlthumbnail');
		var preloadImg = new Image();

		preloadImg.src = hoverImgSrc;
	});

	$(".rollover").hover(
		function(){
			this.src = setUrlParam(this.src, 'blobcol', 'urlthumbnail');
		},
		function(){
			this.src = setUrlParam(this.src, 'blobcol', 'urlimagemedium');
		}
	);

	$(".rollover_more").hover(
		function() {
		  curr = $(this).attr('src');
			ext = curr.substr(curr.lastIndexOf('.'),4);
		  overlen = curr.length;
		  over = curr.substr(0, overlen-4);
		  over = over+'_o'+ext;
		  $(this).attr({ src: over});
		 },
		 function() {
		  $(this).attr({ src: curr});
		 }
	)

	$(".rollover_more").each(function(i) {

	  temp = this.src;
		ext = temp.substr(temp.lastIndexOf('.'),4);
	  prelen = temp.length;
	  pre = temp.substr(0, prelen-4);
	  pre = pre+'_o'+ext;
	  preload_image_object = new Image();
	  preload_image_object.src = pre;

	});

	/**
	* Replaces the value of a url param
	* @usage newURL = setUrlParam('http://www.three.com.au?param1=old&paramN=x', 'param1', 'new')

	* @arg url: The original url
	* @arg name: The name of the url param
	* @arg newVal: The new value for the specified url param

	* @return Returns the new url with the replaced url param value, otherwise returns null
	*/
	function setUrlParam(url, name, newVal){
		var exp = '[?|&]+' + name + '=[^&]*';
		var re = new RegExp(exp);
		var results = re.exec(url);
		var ret = null;

		if(results !=null){
			var results2 = /.*=/i.exec( results[0] );
			var newparam = results2[0] + newVal;

			//replace old param with new
			ret = url.replace(results[0], newparam );
		}

		return ret;
	}

});