$(document).ready(function() {

	function getUrlVars(href)
	{
	    var vars = [], hash;
	    var hashes = href.slice(href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++)
	    {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }
	    return vars;
	}

	$('a.thumb-href').click(function() {
		var href = $(this).attr('href');
		var item_id = getUrlVars(href)['item'];
		var fragment = '#item' + item_id + ' a.medium-image';
		var url = href + ' ' + fragment;
		var images = $(this)
							.parents('div.images');
		var imagebox = images
							.children('div.imagebox');

		imagebox.fadeOut(function() {
			$(images).children('.loading').show();
			imagebox.load(url, function() { 
				imagebox.fadeIn();
				$(images).children('.loading').hide();
				$(fragment + "[rel='full-image-" + item_id + "']").colorbox();
			});
		});

		return false;
	});

});
