/***
 * Resize background
 * Keep dimensions, fill whole screen
 */

var siteWidth 		= 980;
var marginTop 	 	= 0;
var marginBottom 	= 0;

function resizesite(){
	var win_w = jQuery(window).width();
	var win_h = jQuery(window).height();
	if (win_w > siteWidth)
		jQuery('#wrapper').css({'width':win_w});
}

function resizebg(){
	var win_w = jQuery(window).width();
	var win_h = jQuery(window).height();
	var fc_w  = siteWidth;
	var fc_h  = jQuery('#wrapper').height();
	var w = (win_w > fc_w)?win_w:fc_w;
	jQuery('#bg-image .bgimage, #flashmovie .bgimage').css({'width' : w});

	var h = jQuery('#bg-image .bgimage, #flashmovie .bgimage').height();
	var compare_h = ((win_h > fc_h) ? win_h : fc_h) - marginTop - marginBottom;

	var fixh = false;
	var margleft = 0;

	if(h < compare_h){
		h = compare_h;
		jQuery('#bg-image .bgimage, #flashmovie .bgimage').css({'height':h,'width':'auto'});
		margleft = parseInt((win_w - jQuery('#bg-image .bgimage, #flashmovie .bgimage').width())/2);
		fixh = true;
	} else {
		jQuery('#bg-image .bgimage, #flashmovie .bgimage').height('auto');
	}

	jQuery('#bg-image .bgimage, #flashmovie .bgimage').css('margin-left',margleft);
}

jQuery(window).resize(resizebg);
jQuery(window).resize(resizesite);
jQuery(window).load(function(){
	resizebg();
	resizesite();
});

