﻿/// <reference path="jquery-1.7.1.min.js" />


$(document).ready(function () {
    var img = $('#imgConstruction');
    var maxHeight = img.height();
    var maxWidth = img.width();

    if (img && img.length > 0) {
        $(window).bind('resize', resizeImage);
        resizeImage();
        img.bind('load', function () {
            maxHeight = img.height();
            maxWidth = img.width();
            resizeImage();
        });
    }

    function resizeImage() {
        var wHeight = $(window).height() - 50;
        var wWidth = $(window).width() - 50;
        var ratio = maxHeight / maxWidth;
        
        if (wHeight > maxHeight) wHeight = maxHeight;
        if (wWidth > maxWidth) wWidth = maxWidth;

        if (wHeight < maxHeight) {
            img.height(wHeight);
            img.width(wHeight / ratio);
            var width = img.width();
            if (width > wWidth) {
                img.width(wWidth);
                img.height(wWidth * ratio);
            }
        }
        else if (wWidth < maxWidth) {
            img.width(wWidth);
            img.height(wWidth * ratio);
            var height = img.height();
            if (height > wHeight) {
                img.height(wHeight);
                img.width(wHeight / ratio);
            }
        }
    }
});

