﻿function activateMenu(menu) {
    if (!$('#Menu' + menu).hasClass('Menu' + menu + 'Active')) {
        addMenuHighlight();
        $('#Menu' + menu).addClass('Menu' + menu + 'Active');
        $('#Menu' + menu).off('mouseenter mouseleave');
        activateContent(menu);
    }
}

function activateContent(menu) {
    $('#showcontrol, #controls2, #play-button').hide(); $('#supersized').fadeOut(); api.options.slideshow = 0;
    $('#FAQ').hide();
    $('#Aware').hide();
    $('#Desire').hide();

    if (menu == 'Comming') {
        $('#showcontrol, #controls2').show(); $('#supersized').fadeIn(); api.options.slideshow = 1; api.playToggle(); api.playToggle(); // double playToggle to push
    }
    else {
        $('#' + menu).fadeIn();
    }
}

function addMenuHighlight() {
    $('#MenuAware').removeClass('MenuAwareActive MenuAwareHover');
    $('#MenuComming').removeClass('MenuCommingActive MenuCommingHover');
    $('#MenuFAQ').removeClass('MenuFAQActive MenuFAQHover');
    $('#MenuDesire').removeClass('MenuDesireActive MenuDesireHover');

    //		$('#MenuAware').hover(  function () {$('#MenuAware').addClass('MenuAwareHover');  $('.MenuAwareHover').stop().css('opacity', 0.7).animate({opacity: 1}, 1000);},  function () { $('#MenuAware').removeClass('MenuAwareHover');});

    $('#MenuAware').hover(function () { $('#MenuAware').addClass('MenuAwareHover'); }, function () { $('#MenuAware').removeClass('MenuAwareHover'); });
    $('#MenuComming').hover(function () { $('#MenuComming').addClass('MenuCommingHover'); }, function () { $('#MenuComming').removeClass('MenuCommingHover'); });
    $('#MenuFAQ').hover(function () { $('#MenuFAQ').addClass('MenuFAQHover'); }, function () { $('#MenuFAQ').removeClass('MenuFAQHover'); });
    $('#MenuDesire').hover(function () { $('#MenuDesire').addClass('MenuDesireHover'); }, function () { $('#MenuDesire').removeClass('MenuDesireHover'); });
}

function showToolTip(item) {
    hideToolTip('email', 0);
    hideToolTip('password', 0);
    $('#' + item + 'Info').stop().css('opacity', 1);
    $('#' + item + 'Info').animate({
        width: '180px',
        height: '45px',
        padding: '5px',
        marginLeft: "30px"
    }, 100, function () {
        $('#' + item + 'Info, #' + item).hover(function () { $('#' + item + 'Info').stop().css('opacity', 1); },
											function () { hideToolTip(item, 3000); }
										);
        //hideToolTip(item, 3000);
    }
		  );
}

function hideToolTip(item, duration) {
    $('#' + item + 'Info').stop().fadeOut({ duration: duration, queue: false,
        complete: function () {//$('#' + item + 'Info').css('width','0px').height(0).css('padding', 0).css('margin-left', 0).css('display','inline-block');
            $('#' + item + 'Info').css('opacity', 0).show();
        }
    });
}






function visibleWidth() {
    return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0;
}
function visibleHeight() {
    return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
}
function centerControls() {
    var visibleH = visibleHeight();
    var visibleW = visibleWidth();
    $("#play-button").css({
        "position": "absolute",
        "top": visibleH / 2 - 30,
        "left": visibleW / 2
    });

    $('#showcontrol').height(400);
    if (visibleH < $('#showcontrol').height()) $('#showcontrol').height(visibleH);
    $('#showcontrol').width(700);
    if (visibleW < $('#showcontrol').width()) $('#showcontrol').width(visibleW);
    $("#showcontrol").css({
        "position": "absolute",
        "top": visibleH / 2 - $('#showcontrol').height() / 2,
        "left": visibleW / 2 - $('#showcontrol').width() / 2
    });
}
function resizeInfo() {
    $('#FAQ').height(visibleHeight() - 160);
    $('#Aware').height(visibleHeight() - 160);
    $('#Desire').height(visibleHeight() - 160);

}

function UpdateServer(fw) {
    var txt = JSON.stringify(fw.PrepareData(), null, 2);
    ControllerModel("SaveAll", txt, function (response) { ModelView.firmware().ID(response) });
}


function goHome() {
    location.href = getCurrentLocation("Home") + "Title";
}

function goContribute() {
    location.href = getCurrentLocation("Home") + "Contribute";
}

function goChecksum() {
    location.href = getCurrentLocation("Home") + "Check";
    /*
    CheckAuthentiticated(
        function () { location.href = getCurrentLocation("Home") + "Check"; },
        function () { gotoLogin(goChecksum); }
    );*/
}
function goBuy() {
    location.href = getCurrentLocation("Home") + "Buy";
}
function goContact() {
    location.href = getCurrentLocation("Home") + "Contact";
}
function goFeatures() {
    location.href = getCurrentLocation("Home") + "Features";
}
function goProduct() {
    location.href = getCurrentLocation("Home") + "Product";
}
