$(function(){
 $('#top .main img').hide();
 var newslistH = $('#top .newslist').height();
 $('#top .footer').css('height',newslistH);

	function windowSize() {
		winHeight = Math.floor($(window).height());
		winWidth = Math.floor($(window).width());
		contHeight = Math.floor($(document).height());
		contWidth = Math.floor($(document).width());
		wrpLeft = Math.floor($('.wrapper').offset().left);
		img = $('#top .main img');
		imgtop  = Math.floor((winHeight- img.height()) / 2)-20;
		footer = $('#top .footer');
		wrapper =$('.wrapper');

		if(winHeight>740 && winHeight<850){
			inHeight();
			imgfadeIn();
		} else if(winHeight>=850) {
			overHeight();
			imgfadeIn();
		} else if(winHeight<=740){
			underHeight();
			imgfadeIn();
		};		
	} ;
	
	function imgfadeIn(){
		 $('#top .main img').fadeIn(2000);	
	}

	function underHeight(){
		img.css({
			'position':'static'
		});
		footer.css({
			'position':'relative',
			'bottom': 0,
			'left': 0
		});
		wrapper.css({
			'position':'relative',
			'height':'100%'
		});
	};
	
	function inHeight() {
		img.css({
			'position':'absolute',
			'top': imgtop,
			'left': wrpLeft
		 });
		 footer.css({
			'position':'absolute',
			'bottom': '30px',
			'left': wrpLeft,
			'z-index': 9999
		 });
		wrapper.css({
		 	'position':'static'
		 });
	};
	
	function overHeight() {
		var wrapperTop  = Math.floor((850 - img.height())/2);

		img.css({
			'position':'absolute',
			'top': wrapperTop,
			'left': 0
		 });
		footer.css({
			'position': 'absolute',
			'z-index': 9999,
			'bottom': 0,
			'left': 0
		});
		wrapper.css({
			'position':'relative',
			'height': '805px'
		});
	};
	

	

	var resizeTimer = null;
	$(window).bind('load', function() { 
		windowSize();
	});
	
	$(window).bind('resize', function() {
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(windowSize, 100);	
	});

});
