function imageRatio(width, height, w, h, lr, tb){
    ww = $(window).width();
    wh = $(window).height();
/* 
 *  old version
 *    var maxWidth    = ww - w - lr;
    var maxHeight   = wh - h - tb;
    
    var ratio    =   height / width;
    if (height > maxHeight) {
        height = maxHeight;
        width = Math.round(height / ratio);
    }
    
    if (width > maxWidth) {
        width = maxWidth;
        height = Math.round(width * ratio);
    }
*/
    var maxWidth    = ww - lr;
    var maxHeight   = wh - tb;
    var ratio  = height / width;
    if(height>maxHeight){
    	height=maxHeight;
    	width= Math.round(height / ratio);
    }
    if(width>maxWidth){
    	width=maxWidth;
    	height = Math.round(width * ratio);
    }
    
    return {
        width: width,
        height: height
    };
};
