var imageWidth = 1680;
var imageHeight = 1050;

$(document).ready(function() {
	$('#Spinner').css('opacity', '0.33');
	$.preloadCssImages({statusBarEl: '#Status'});
	$(window).resize(function(){
	  resizeImage();
	});
	
	$('#Header a').live('mouseover', function() {
		$('#Content').fadeIn();
		$('#Image').mouseover(function() {
			$('#Content').fadeOut();
		})
		return false
	})
	
	$('#Image a').live('click', function(){
		var href = this.href;
		href = href.replace('http://'+location.hostname,''); 
		$.address.value(href);  
		return false;
	})
	
	$.address.change(function(event) {  
		href = event.value;	
		if(href!='/') {
			$('#Spinner').show();
			$.ajax({
			  url: '/ajax'+href,
			  cache: true,
			  success: function(result){
				$('#Container').html(result);
				resizeImage();
				$('#Spinner').hide();
				$(document).pngFix();
			  }
			});
		}	
		else {
			resizeImage();
		}
	});
	
	$('#Content .links a').live('click', function(){
		var href = $(this).attr('href');
		href = href.replace('http://'+location.hostname,''); 
		$('#Content .description').html('<p>Loading...</p>');
		$.ajax({
		  url: '/ajax'+href,
		  cache: true,
		  success: function(result){
		    $("#Content .description").html(result);
			$("#Content .description").fadeIn();
		  }
		});
		$('#Content .links li').removeClass('selected');
		$(this).parent().addClass('selected');
		return false;
	});
	
});
function resizeImage() {
	var navWidth = $(window).width();
	var navHeight = $(window).height();
	var navRatio = navWidth / navHeight;
	imageRatio = imageWidth / imageHeight;
	if (navRatio > imageRatio) {
		var newHeight = (navWidth / imageWidth) * imageHeight;
		var newWidth = navWidth;
	} else {
		var newHeight = navHeight;
		var newWidth = (navHeight / imageHeight) * imageWidth;
	}	
	newTop = 0 - ((newHeight - navHeight) / 2);
	newLeft =  0 - ((newWidth - navWidth) / 2);
	$('#Image').css({height: navHeight, width: navWidth});
	$('#Image img').css({height: newHeight, width: newWidth, top: newTop, left: newLeft});
	$('#Image').css({visibility:"visible", display:"block"});
}
