var win = $(window), winW = win.width(), winH = win.height(), dDownH = 0,
areaConts = $('#main'), areaTotalH,
filtersH, filters = 0,
gHash,
area = 0, // 0 home
contState = 0, servState = 0, detailState = 0, caDetailState = 0; // minMax state

function doisN(num) {
    return (num < 10 ? '0' : '') + num;
}

function existe(x) {
    if ($(x).length > 0) return true;
}
/* redim Plugin */
(function ($) {
    $.fn.redim = function () {
        var t = $(this);
        var options = $.fn.redim.options;
        return t.each(function () {
            var ratio = options.altMin / options.largMin;
            var browserLarg = $(window).width();
            var browserAlt = $(window).height();
            //Resize image ratio
            if (browserAlt < 500 && browserLarg < 920) { 
                t.height(options.altMin);
                t.width(options.altMin / ratio);
                t.css('left', '-24px');
                t.css('top', '-24px');
            } else {
                if ((browserAlt / browserLarg) > ratio) {
                    if (browserAlt < 500) {
                        t.height(options.altMin);
                        t.width(options.altMin / ratio);
                    } else {
                        t.height(browserAlt);
                        t.width(browserAlt / ratio);
                    }
                } else {
                    if (browserLarg < 920) {
                        t.width(options.largMin);
                        t.height(options.largMin * ratio);
                    } else {
                        t.width(browserLarg);
                        t.height(browserLarg * ratio);
                    }
                }
                if (options.verticalCenter == 1) {
                    if (browserAlt < 500) {
                        t.css('top', '-24px');
                    } else {
                        t.css('top', (browserAlt - t.height()) / 2);
                    }
                    if (browserLarg < 920) {
                        t.css('left', '-24px');
                    } else {
                        t.css('left', (browserLarg - t.width()) / 2);
                    }
                }
            }
            return false;
        });
    };
})(jQuery);

/* onDomReady */
$(function () {
    // Resize
    function redimWin() {
        winW = win.width();
        winH = win.height();
        if (winW < 920) winW = 920;
        if (winH < 500) winH = 500;
        areaTotalH = Number(winH - 0);
        areaTotalW = Number(winW - 0);
        $('#main').css({ 'width': Number(winW - 0) + 'px', 'height': areaTotalH + 'px' });
        $('.header').css('width', Number(winW - 0) + 'px');

        //plugin 
        $.fn.redim.options = { largMin: 1500, altMin: 850, verticalCenter: 1 }
        if (area == 0) $('#background-image img').redim();
        
    }
    win.resize(function () {
        redimWin();
    }).trigger("resize");
   
    /* function to fix the -10000 pixel limit of jquery.animate */
    $.fx.prototype.cur = function () {
        if (this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null)) {
            return this.elem[this.prop];
        }
        var r = parseFloat(jQuery.css(this.elem, this.prop));
        return typeof r == 'undefined' ? 0 : r;
    }
      });
appInit();

