var main_image_original_width = 1920;
var main_image_original_height = 1200;
var pic_width = main_image_original_width;
var pic_height = main_image_original_height;
 
function resize_image() {
	var win_width = $(window).width();
	var win_height = $(window).height();
	var win_aspect_ratio = win_width / win_height;
	
	current_width = $('#image_holder img').width();
	if (current_width > 1) {
		pic_width = current_width;
	}	

	current_height = $('#image_holder img').height();
	if (current_height > 1) {
		pic_height = current_height;
	}
	
	var pic_aspect_ratio = pic_width / pic_height;
	var new_height = $(window).height();
	var new_width = $(window).width();
	if (win_aspect_ratio > pic_aspect_ratio) {
		// scale pic to fit window width
		var new_height = (win_width / pic_width) * pic_height;
	} else {
		// scale pic to fit window 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);

	//alert("win_height: "+win_height+"; win_width: "+win_width+"; pic aspect ratio: "+pic_aspect_ratio+"; win aspect ratio: "+win_aspect_ratio+"; new height: "+new_height+"; new width: "+new_width+"; new top: "+new_top+"; new left: "+new_left);
	$('#image_holder').css({
		'height': new_height,
		'width': new_width}).data({top: new_top, left: new_left});
	$('#image_holder img').css({
		'top': new_top, 
		'left': new_left,
		'height': new_height,
		'width': new_width
	});
}

/////////Ostensibly the image swapping functions.
function swapImgTo(nextImgId){
	var next_img = '#image_holder img#'+nextImgId;
	if($(next_img).length != 0){
		$('#image_holder img').hide();
		$(next_img).show();
		$('a.pic_num').removeClass('active_pic');
		$('li.active a#'+nextImgId).addClass('active_pic');
	}
};
function swapImgNext(currID){
	var nextID = currID*1;
	swapImgTo(nextID+1);
};
function swapImgPrev(currID){
	var nextID = currID*1;
	swapImgTo(nextID-1);
};

