/*

IMAGE RESIZE AND CORRECT

JAVASCRIPT by Bonacode + Leonardo Favre
http://www.bonacode.com
http://www.leofavre.com

*/

function imageResize(){
	if(mobile == true){
		imageResizeMobile();
	}else{
		imageResizeDesktop();
	}
}

function imageResizeDesktop() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		var imgBoxWidth = window.innerWidth;
		var windowHeight = window.innerHeight;

		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		var imgBoxWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;

		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		var imgBoxWidth = document.body.clientWidth;
		var windowHeight = document.body.clientHeight;
	}
	
	var imgHeight = $("#the-image").height();
	var imgWidth = $("#the-image").width();
	var imgAspect = imgWidth/imgHeight;

	$("#content").css("height", "auto");

	var imgMaxHeight = windowHeight - ( $("#content").height() + 150 );
	var imgMaxWidth = imgBoxWidth;
	var imgMaxAspect = imgMaxWidth/imgMaxHeight;
	
	if(imgBoxWidth < 770){
		$("#image").css("width", 770);
	}else{
		$("#image").css("width", imgBoxWidth);
	}
	
	if(imgHeight == null){
		$("#image").css("height", imgMaxHeight);
		$("#the-image").css("height", imgMaxHeight);
		sobra = windowHeight - $("#image").height() -150;
		$("#content").css("height", sobra);
	}else{
		$("#image").css("height", "auto");
		if(imgAspect > imgMaxAspect){
			$("#the-image").css("height", "auto");
			$("#the-image").css("width", imgMaxWidth);
		}else{		
			$("#the-image").css("height", imgMaxHeight);
			$("#the-image").css("width", "auto");
		};
		sobra = windowHeight - $("#the-image").height() -150;
		$("#content").css("height", sobra);
	}	

};

function listSize(){
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		var imgBoxWidth = window.innerWidth;
		var windowHeight = window.innerHeight;

		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		var imgBoxWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;

		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		var imgBoxWidth = document.body.clientWidth;
		var windowHeight = document.body.clientHeight;
	}
	$("#content").css("height", "auto");
	atual = $("#content").height()
	sobra = windowHeight -150;
	if(sobra > atual){
		$("#content").css("height", sobra);
	}	
}

function imageResizeMobile(){
	/* $("#image").css("width", 770); */
	/* $("#image").css("width", "auto"); */
	$("#the-image").css("width", 770);
	$("#the-image").css("width", "auto");
}


