function onready()
{
	$.history.init(callback);
	$("a").live('click',function(e){
		var t = jQuery(e.target);
		var t = jQuery(e.target).closest('a');
		if ( t.attr('href').search(/\.html$/) != -1 ){
			e.preventDefault();
			$.history.load($(this).attr("href"));
		}
	});
}

function callback(hash)
{
	if (!hash) hash = "home.html";
	//$(".tabs").find("a.shadow4").removeClass("shadow4").addClass("shadow5");
	//$(".tab[rel="+hash+"]").find("a.shadow5").removeClass("shadow5").addClass("shadow4");
	$(".content").animate({ opacity: 0}, "fast", function(){
		$.ajax({
			url: hash,
			//url: hash+".html",
			cache: false,
			success: function(data){
				$(".content").showHtml(data, "slow");
			},
			error: function(){
				$.get('notfound.html', function(data){
					$(".content").showHtml(data, "slow");
				});
			}
		});
	});
}

function gui_prepare( elem )
{
	$(elem).find(".shadow1, .shadow2, .shadow3, .shadow4, .shadow5, .shadow6").prepend('<div class="shadow_n"></div><div class="shadow_ne"></div><div class="shadow_e"></div><div class="shadow_se"></div><div class="shadow_s"></div><div class="shadow_sw"></div><div class="shadow_w"></div><div class="shadow_nw"></div>');
	$("a[@rel='history']").unbind('click');
	$("a[@rel='history']").click(function(){
		$.history.load(this.href.replace(/^.*#/, ''));
		return false;
	});
	return elem;
}

(function($)
{
	$.fn.showHtml = function(html, speed, callback) {
		this.each(function() {
			var el = $(this);
			var finish = {width: this.style.width, height: this.style.height};
			var cur = {width: el.width()+'px', height: el.height()+'px', opacity: 0};
		
			el.html(html);
			//gui_prepare(el);

			var next = {width: el.width()+'px', height: el.height()+'px', opacity: 1};

			el .css(cur)
				.animate(next, speed, function() {
					el.css(finish);
					if ( $.isFunction(callback) ) callback();
				});
		});
	};

})(jQuery);
