var canvasH,canvasW,documentW,documentH = 0;

function resize_bg() {
		canvasW = $(window).width();
		canvasH = $(window).height();	
		if (canvasW<640) {
			//canvasW=640;
		}
		if (canvasH<480) {
			//canvasH=480;
		}
		
		
		var thumbW = canvasW-400;
		if (canvasW<640) thumbW = 340;
		$('#thumbnails').css('width',thumbW);
		
		
		$('#bg img').removeAttr("width"); 
		$('#bg img').removeAttr("height");
		var oriW = $('#bg img').width();
		var oriH = $('#bg img').height();
		if (oriW/oriH<canvasW/canvasH) {
			imgW = canvasW;
			imgH = oriH/oriW*imgW;
		} else {
			imgH = canvasH;
			imgW = oriW/oriH*imgH;
		}
		
		
		$('#bg img').width(imgW).height(imgH);
		
		imgT = (canvasH-imgH)/2;
		imgL = (canvasW-imgW)/2;
		$('#bg').css("top", (imgT)+'px');
		$('#bg').css("left", (imgL)+'px');
		
		$('#content').height(canvasH-$('#menubar').height()-2);
}
			
function init() {
	$(document).ready(function(){
								
		canvasH = $(window).height();		
		canvasW = $(window).width();
		documentW = $(document).width();	
		documentH = $(document).height();
		$('#bg').hide();
		var my_src =  $('#bg img').attr('src')+'?time='+(new Date().getTime());
		$('#bg img').attr('src',my_src);
		
		//$('#bg').fadeIn("slow");
		if ($('#bg img').width()!=0) {
				$('#bg').fadeIn("slow");
				resize_bg();
		} else {
			$('#bg img').load(function(){
				$('#bg').fadeIn("slow");
				resize_bg();
			});
		}
		
		$('#menubar ul li a img,#enter a img').not('.selected').bind("mouseenter",function(){
			var new_src = $(this).attr('src').replace('_off','_on');
			$(this).attr('src',new_src);
		});	
		
		$('#menubar ul li a img,#enter a img').not('.selected').bind("mouseout",function(){
			var new_src = $(this).attr('src').replace('_on','_off');
			$(this).attr('src',new_src);
		});
		
		
		
		$('#thumbnails .thumb img').bind("mouseenter",function(){
			$(this).parent().parent().css('background-image','url(img/bg_2.png)');
		});	
		
		$('#thumbnails .thumb img').bind("mouseout",function(){
			$(this).parent().parent().css('background-image','url(img/bg_1.png)');
		});	
		
		
		$('#thumbnails .thumb a').prettyPhoto({overlay_gallery:false});
		
	});					
	$(window).resize(function() {
	  	resize_bg();
	});
	
}

init();

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-4960032-24']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
