// back image resize
var main_image_original_width = 1500;
var main_image_original_height = 1000;
var pic_width = main_image_original_width;
var pic_height = main_image_original_height;

function resize_image_with_cropping() {
	var win_width = jQuery(window).width();
	var win_height = jQuery(window).height();
	var win_aspect_ratio = win_width / win_height;

	current_width = jQuery('#main_image').width();
	if (current_width > 1) {
		pic_width = current_width;
	}	

	current_height = jQuery('#main_image').height();
	if (current_height > 1) {
		pic_height = current_height;
	}
	
	pic_aspect_ratio = pic_width / pic_height;
	
	if (win_aspect_ratio > pic_aspect_ratio) {
		// scale pic to fit window width
		var new_height = (win_width / pic_width) * pic_height;
		var new_width = win_width;
	} else {
		// scale pic to fit window height		
		var new_height = win_height;
		var new_width = (win_height / pic_height) * pic_width;
	}
	
	// center image
	new_top = 0 - ((new_height - win_height) / 2);
	new_left =  0 - ((new_width - win_width) / 2);
	
	// center image only horizontal
	new_top = 0 ;
	new_left =  0 - ((new_width - win_width) / 2);

	// alert('new_top: ' + new_top + 'new_left: ' + new_left);
	jQuery('#main_image').css({top: new_top, left: new_left});

	jQuery('#main_image').css({height: new_height, width: new_width});
	jQuery('#bkg-wrapper').css({height: win_height, width: win_width});
	jQuery('#bkg-wrapper').css({visibility:"visible", display:"inline"});
	
	// link positions
	jQuery('#linkWrap').css({height: new_height,width: new_width / 2 + 10});
	jQuery('.de').css({top: new_height / 2.5, height: new_height / 9});
	jQuery('.fr').css({top: new_height / 2.3, height: new_height / 9});
}

window.onload = resize_image_with_cropping;
jQuery(window).resize(function(){
	resize_image_with_cropping();
});

