onload = function () {
    setMainImageSize();
}

onresize = function () {
    setMainImageSize();
}

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*(2588/3888);
    
    if(new_image_height < myHeight) { 
        new_image_height = myHeight;
        new_image_width = new_image_height*(3888/2588);
    }
    
    
    var mainimage = document.getElementById('background_image');
    var mainimageContainer = document.getElementById('background');
    
    if(mainimage != null) {
       
        mainimage.setAttribute("className", "dynamic");
        
        mainimage.style.height = new_image_height + "px";
        mainimage.style.width = new_image_width + "px";
    	mainimage.style.marginTop = 0  + "px";
    	mainimage.style.marginLeft = 0  + "px";
    	
    	if(new_image_height > myHeight) {
    		var topmargin = (myHeight/2) - (new_image_height/2);
    		if((topmargin+new_image_height-30) >= myHeight) {
				mainimage.style.marginTop = topmargin  + "px";
    		}
    	} else {
    		var leftmargin = (myWidth/2) - (new_image_width/2);
    		if((leftmargin+new_image_width-30) >= myWidth) {
				mainimage.style.marginLeft = leftmargin  + "px";
    		}
    	}
    	
    }
    

    

}
