$(window).resize(function() {
	ewc_resize();
	if($(window).height() > 650) {
		$('body').css({
			'overflow-y': 'hidden'
		});
	} else {
		$('body').css({
			'overflow-y': 'scroll'
		});
	}
});

function ewc_resize() {
	if ($('#full-size').is(':visible')) {
		_ewv_resize_fullimage();
	}

	var win_wid = $(window).width();
	var win_hei = $(window).height();
	
	
	if(win_wid-200 < 700) {
		if(win_wid-200 < 576 || win_hei-200 < 320) {
			cont_wid = 546;
			cont_hei = 318;
		} else {
			cont_wid = win_wid-200;
			cont_hei = cont_wid/cont_prop;
		}
	}
	if(win_hei-200 < 409) {
		if(win_wid-200 < 547 || win_hei-200 < 320) {
			cont_wid = 546;
			cont_hei = 318;
		} else {
			cont_hei = win_hei-200;
			cont_wid = cont_hei*cont_prop;
		}
	}
	else {
		cont_wid = 700;
		cont_hei = 408;
		$('body').css({
			'overflow-x' : 'hidden'
		});
	}
	var cont_prop = cont_wid/cont_hei;
	var main_wid = cont_wid + 50;
	
	if(win_wid > 980) {
		var full_pos_l = Math.round((main_wid - win_wid)/2);
		$('body').css({
			'overflow-x' : 'hidden'
		});
	}
	if(win_wid < 980) {
		$('body').css({
			'overflow-x' : 'scroll'
		});
	}

	$('#container').height($(window).height()-40);
};

function _ewv_resize_fullimage() {
	$('#full-size').css('position', 'static');

	var window_height = $(window).height();
	var window_width = $(window).width();
	var window_ratio = window_width / window_height;
	var window_center = Math.floor(window_width / 2);

	var image = $('#full-size > img:first');
	var image_height = parseInt($(image).attr('data-height'));
	var image_width = parseInt($(image).attr('data-width'));
	var image_ratio = image_width / image_height;

	if (window_ratio > image_ratio) {
		var new_width = window_width;
		var new_height = window_width / image_ratio;
	} else {
		var new_height = window_height;
		var new_width = new_height * image_ratio;
	}
	
	var parent_offset = $(image).parent().parent().position().left;
	var new_center = Math.floor(new_width / 2);

	$(image).css({
		'position': 'absolute',
		'width': new_width.toString() + 'px',
		'height': new_height.toString() + 'px',
		'left': (window_center - new_center - parent_offset).toString() + 'px'
	});
};

$(window).load(function() {
	$('#full-size > img:first').attr('data-width', $('#full-size > img:first').get(0).width);
	$('#full-size > img:first').attr('data-height', $('#full-size > img:first').get(0).height);
	ewc_resize();
});
