var contentsBottomMargin = 237;
var contentsTop = 116;
var contentsMinHeight = 260;
var bottomSize = 220;

window.onload = function() {
    setMainImageSize();
}

window.onresize = function() {
    setMainImageSize();
}

IE7_PNG_SUFFIX = "-trans.png";
var type = "";
if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";
if (document.all) type="IE";
if (document.layers) type="NN";
if (!document.all && document.getElementById) type="MO";

var MAX_height = 12000;

function setMainImageSize() {
	var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
       myWidth = window.innerWidth;
       myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    
    var new_image_width = myWidth;
    var new_image_height = new_image_width*(1331/2000);
    
    if(new_image_height < myHeight) { 
        new_image_height = myHeight;
        new_image_width = new_image_height*(2000/1331);
    }
    
    // Image minimum dimensions...
    /*
    if(new_image_height < 630) {
    	new_image_height = 630;
    	new_image_width = new_image_height*(4108/3496);
    }
    */
    
    var mainimage = document.getElementById('mainimage');
    var mainimageContainer = document.getElementById('imagecontainer');
       
    mainimage.setAttribute("className", "dynamic");
    
    mainimage.style.height = new_image_height + "px";
    mainimage.style.width = new_image_width + "px";
    
    if(new_image_width < 1000) {
        mainimage.src = "/images/" + mainimage.getAttribute("alt") + "1000.jpg";
    } else if(new_image_width < 1500) {
        mainimage.src = "/images/" + mainimage.getAttribute("alt") + "1500.jpg";
    } else if(new_image_width < 2000) {
        mainimage.src = "/images/" + mainimage.getAttribute("alt") + "2000.jpg";
    } else {
        mainimage.src = "/images/" + mainimage.getAttribute("alt") + ".jpg";
    }
       
    var contentsize = myHeight  - (contentsTop + contentsBottomMargin);
    //if(type == "IE") {
    //	var topsize = (myHeight / 2) - 80;
    //}
    
    if(contentsize < contentsMinHeight) {
    	contentsize = contentsMinHeight;
	}
	document.getElementById("contents").style.height = contentsize + "px";

	// Make sure bottom bit doesn't go to high up
	var links = document.getElementById("links");
	var divider = document.getElementById("divider");
	var logo = document.getElementById("logo");
	
	if(myHeight - bottomSize < (contentsMinHeight + contentsTop)) {
		linksY = (contentsMinHeight + contentsTop);
	}
	else {
		linksY = myHeight - bottomSize;
	}
	links.style.top = linksY + "px";
	divider.style.top = (linksY + 110) + "px";
	logo.style.top = (linksY + 90) + "px";
	
    mainimageContainer.style.height = linksY + bottomSize;
    mainimageContainer.style.width = myWidth;		
}