﻿$(document).ready(function () {

    var enderecoAtual = location.pathname;

    if (enderecoAtual.substring(enderecoAtual.length - 1) == "/") {
        enderecoAtual = enderecoAtual.substring(0, enderecoAtual.length - 1);
    }

    var submenuSelecionado = false;
    $("#nav-lateral ul li").each(function () {

        if (enderecoAtual == $(this).children().attr("href")
        || (enderecoAtual.indexOf("Noticias") > 0 && $(this).children().attr("href").indexOf("Noticias") > 0)) {

            $(this).addClass('lateral-ativo');
            submenuSelecionado = true;

        }
    });

    if (!submenuSelecionado && $("#nav-lateral ul li") != null) {
        $("#nav-lateral ul li:first").addClass('lateral-ativo');
    }

    $('a[rel="lightbox"]').lightBox();
});

$.fn.resizeImage = function (w, h) {

    var maxWidth = w; // Max width for the image 
    var maxHeight = h;       // Max height for the image 

    $(this).css("width", "auto").css("height", "auto"); // Remove existing CSS 
    $(this).removeAttr("width").removeAttr("height"); // Remove HTML attributes 

    var width = $(this).width();    // Current image width 
    var height = $(this).height();  // Current image height 

    if (width > height) {
        // Check if the current width is larger than the max 
        if (width > maxWidth) {
            var ratio = maxWidth / width;   // get ratio for scaling image 
            $(this).css("width", maxWidth); // Set new width 
            $(this).css("height", height * ratio);  // Scale height based on ratio 
            height = height * ratio;        // Reset height to match scaled image 
        }
    } else {
        // Check if current height is larger than max 
        if (height > maxHeight) {
            var ratio = maxHeight / height; // get ratio for scaling image 
            $(this).css("height", maxHeight);   // Set new height 
            $(this).css("width", width * ratio);    // Scale width based on ratio 
            width = width * ratio;  // Reset width to match scaled image 
        }
    }
}

$.fn.somenteNumeros = function () {
    $(this).keypress(function (e) {
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57))
            return false;
        else
            return true;
    });
}