﻿var naturalWidth = 1200;
var naturalHeigth = 799;
function resizeImage() {
    var de = document.documentElement;
    var x = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    var y = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;

    var background = $(".portal .backgroundImage");
    if (!background.length) return;

    // show the background
    background.show();

    // find img
    var img = background.find("img");
    if (!img.length) return;

    // get the first image
    img = img.get(0);
    var width = img.naturalWidth || naturalWidth;
    var height = img.naturalHeight || naturalHeigth;

    var xFactor = x / width;
    var yFactor = (y - 120) / height;

    if (xFactor > yFactor) {
        width = width * xFactor;
        height = height * xFactor;
    } else {
        width = width * yFactor;
        height = height * yFactor;
    }

    img.width = width;
    img.height = height;
}

$(document).ready(function () {
    resizeImage();
});
window.onresize = resizeImage;
