﻿var inp;
var index;
var next;
var prev;
var indexnumber = 0;

function resize (img,w,h) {
    var maxWidth = w; // Max width for the image
    var maxHeight = h;    // Max height for the image
    var ratio = 0;  // Used for aspect ratio
    var width = $(img).width();    // Current image width
    var height = $(img).height();  // Current image height
    // Check if the current width is larger than the max
    if (width > maxWidth) {
        ratio = maxWidth / width;   // get ratio for scaling image
        if (ratio < 1) {
            $(img).css("width", maxWidth); // Set new width
            $(img).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        } else {
            $(img).css("width", maxWidth);
        }
    }

    // Check if current height is larger than max
    if (height > maxHeight) {
        ratio = maxHeight / height; // get ratio for scaling image
        if (ratio < 1) {
            $(img).css("height", maxHeight);   // Set new height
            $(img).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
        else {
            $(img).css("width", maxWidth);
        }
    }
    $(img).css("margin-top", setMargingHeight(maxHeight, $(img)));
    $(img).css("margin-bottom", setMargingHeight(maxHeight, $(img)));
    $(img).css("margin-left", setMargingWidth(maxWidth, $(img)));
    $(img).css("margin-right", setMargingWidth(maxWidth, $(img)));
    $(img).fadeIn(500);




}
function resizeBig(img, w) {
    var ratio = 0;  // Used for aspect ratio
    var width = $(img).width();    // Current image width
    var height = $(img).height();  // Current image height
    var maxWidth = 250; // Max width for the image
    var maxHeight = 250;    // Max height for the image
    // Check if the current width is larger than the max
    if (width > maxWidth) {
        ratio = maxWidth / width;   // get ratio for scaling image
        if (ratio < 1) {
            $(img).css("width", maxWidth); // Set new width
            $(img).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        } else {
            $(img).css("width", maxWidth);
        }
    }

    // Check if current height is larger than max
    if (height > maxHeight) {
        ratio = maxHeight / height; // get ratio for scaling image
        if (ratio < 1) {
            $(img).css("height", maxHeight);   // Set new height
            $(img).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
        else {
            $(img).css("width", maxWidth);
        }
    }
    $(img).css("margin-top", setMargingHeight(maxHeight, $(img)));
    $(img).css("margin-bottom", setMargingHeight(maxHeight, $(img)));
    $(img).css("margin-left", setMargingWidth(maxWidth, $(img)));
    $(img).css("margin-right", setMargingWidth(maxWidth, $(img)));
    $(img).fadeIn(500);




}
    function setMargingHeight(div, height) {
        var img = $(height).height();
        var h = (div - img) / 2;
        if (h < 0)
            return 0;
        else
            return h;

    }
    function setMargingWidth(div, width) {
        var img = $(width).width();
        var w = (div - img) / 2;
        if (w < 0)
            return 0;
        else
            return w;

    }
   
