$(document).ready(function(){

	var p = $('#gallery').position();
	var m = $('#page');
	
	$(window).resize(function(){
		var top = parseInt($(window).height()/2) - parseInt(m.outerHeight()/2);
		if(top > 0){
			m.css('marginTop', top);
		}else{
			m.css('marginTop', 0);
		}
		p = $('#gallery').position();
		$('#gallery .image .big').css('left', p.left).css('top', p.top);
	});
	
	
	$('#gallery .image .thumb').mouseover(function(){
		$('#gallery .image .thumb').removeClass('active');
		$(this).addClass('active');
		
		$('#gallery .image .big').stop(true, true);
		
		if($('#gallery .image .big.active').length == 0 || $(this).parent().find('.big').hasClass('active')){
			$(this).parent().find('.big').css('left', p.left).css('top', p.top).addClass('active');		
		}else{
			$('#gallery .big.active').removeClass('active').addClass('fading').fadeOut(400, function(){$(this).removeClass('fading')});
			$(this).parent().find('.big').css('left', p.left).css('top', p.top).fadeIn(400, function(){$('#gallery .image img.big').removeClass('active'); $(this).addClass('active')});
		}
	});
	
	$('#gallery .image:first .thumb').mouseover();
	
	$(window).resize();

	
});
