// JavaScript Document
var x = 0;
var halfOpened = 0;
var opened = 0;
var footerTop;
var heightPercentage;
var heightTemp;
$(document).ready(function() {
    $('.Bgfooter').css("visibility", "hidden");
//    $('.features > .head').hover(function() { $(this).animate({ opacity: 1 }, 500) }, function() { $(this).animate({ opacity: 0.4 }, 500) });

});

function ForAll() {
    $('.our_products').click(showAll);
    heightPercentage = $('body').height();
    heightPercentage = heightPercentage - 245;
    $('body').css("min-height", "100%");
    $('body').css("height", "");
    $('.center_division').css("min-height", $('body').height() - 100 + "px");
    $('body').css("min-height", "");
    $('body').css("height", "100%");
    $('.Bgfooter').click(showAll);
    $('body').click(function(event) {
        if (!$(event.target).closest('.Bgfooter').length) {
            resetFooter();
        };
        
    });
    calculate();
}

function calculate() {
    heightPercentage = $('.Bgfooter').height() - heightPercentage;
    heightPercentage = -heightPercentage;
    footerTop = $('.Bgfooter').height();
    footerTop = -footerTop + 40;
    if ($('.footer_up').length == 0) {
        $('.Bgfooter').css("bottom", footerTop + "px");
    }
    else {
        $('.Bgfooter').css("bottom", heightPercentage + "px");
        $('.Bgfooter').css("z-index", "1");
        $('.Bgfooter').css("position", "absolute");

        opened = 1;
        x = 0;
    }
    $('.Bgfooter').css("visibility", "visible");
}

function showAll() {
    heightPercentage = $('body').height();
    heightPercentage = heightPercentage - 245;
    heightPercentage = $('.Bgfooter').height() - heightPercentage;
    heightPercentage = -heightPercentage;
    footerTop = $('.Bgfooter').height();
    footerTop = -footerTop + 40;
    if (opened == 0 && opened != 1) {
        x = 1;
        opened = 1;
        $('.Bgfooter').css("z-index", "1");
        $('.Bgfooter').css("position", "absolute");
        $('.product_logo').fadeOut(1800);
        $('.contentwrapper').animate({
            opacity: 0.4
        }, 1800, 'easeInOutExpo', openening)
        $('.Bgfooter').animate({
            bottom: heightPercentage + "px"
        }, 1800, 'easeInOutExpo', openening)
    }
}
$(window).resize(resizeTest);

function resizeTest() {
    if (opened == 1 && x == 0) {
        heightPercentage = $('body').height();
        heightPercentage = heightPercentage - 245;
        heightPercentage = $('.Bgfooter').height() - heightPercentage;
        heightPercentage = -heightPercentage;
        footerTop = $('.Bgfooter').height();
        footerTop = -footerTop + 40;
        $('.Bgfooter').css("bottom", heightPercentage + "px");
    }
}
function resetFooter() {
    footerTop = $('.navigation').height();
    footerTop = -footerTop - 9;
    if (opened == 1 && x == 0) {
        x = 1;
        $('.Bgfooter').css("position", "fixed");
        $('.product_logo').fadeIn(1800);
        $('.contentwrapper').animate({
        opacity: 1
    }, 1800)
        $('.Bgfooter').animate({
            bottom: footerTop + "px"
        }, 1800, 'easeInOutExpo', closed)
    }
}

function closed() {
    opened = 0;
    x = 0;
    $('.Bgfooter').css("z-index", "0");

}

function openening() {
    opened = 1;
    x = 0;
}
