$(function(){
	var throbber=$('<div class="throbber"></div>');
	var object=$('div#vip-object'); object.before(throbber);
	var object_image=$('div#object-image > a', object);
	// Object Info
	var detail=$('div#detail-object', object);
	var object_title=$("#detail-object h6", detail);
	var object_location=$('h3.location', detail);
	var object_parameters=$('h6.parameters', detail);
	var object_history=$('div.history > div', detail);
	var object_history_wrapper=$('div.history', detail);
	var object_readmore=$('div.history > a', detail);
	var button=$('div#next-object > a');
	
	button.removeAttr('href');
	throbber.hide();
	
	$.getJSON('/object/json-front', function(data){
		button.bind('click', function(){
			var i=button.data('current_index');
			i++;
			if(i>=data.length) i=0;
			var o=data[i];
			throbber.show();
			object.animate({opacity:0.0}, 1000, function(){
				var image=$('<img src="'+o.image.fileurl+'">').bind('load', function(){
					object_image.html(image);
					// Set Data
					object_title.html(o.title);
                    $("#detail-object h6").html(o.title);
					object_location.html(o.location);
					object_parameters.html(o.parameters);
					object_history.html(o.history);
					object_history_wrapper[o.history!=''?'show':'hide']();
					object_readmore.attr('href', o.moreurl);
					object_image.attr('href', o.moreurl);
					// Final Fixes
					throbber.hide();
					object.animate({opacity:1.0}, 1000);
				    });
			    });
			button.data('current_index', i);
		    });
	    });
    });

