﻿
var can_open = true;
var open = false;
var direcao = "right";

//sleep
function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
}
function rolamenu() {
    if (direcao == "right") {
        $(".master-menu-wrapper > ul").animate({ "margin-left": -90 }, 600, function() {//-910
            $(".master-menu-right").animate({ "opacity": 0.8 }, 300);
            $(".master-menu-left").animate({ "opacity": 1 }, 300);
        });
    }
    else {
        $(".master-menu-wrapper > ul").animate({ "margin-left": 0 }, 600, function() {
            $(".master-menu-left").animate({ "opacity": 0.8 }, 300);
            $(".master-menu-right").animate({ "opacity": 1 }, 300);
        });
    }
    if (direcao == "right") direcao = "left"; else direcao = "right";
}
$(document).ready(function() {
    //scroll menu
    $(".master-menu-left").animate({ "opacity": 0.8 }, 300);

    $(".master-menu-right").click(function() {
        rolamenu();
    });
    $(".master-menu-left").click(function() {
        rolamenu();
    });
    //open menu

    /* $(".master-menu").hover(function() {
    can_open = true;
    sleep(500);
    if (can_open)
    $(".master-menu-wrapper > ul").stop().animate({ "height": 143 }, 'slow', function() {
    $(".master-menu-topbottom").css("background-position", "left -10px");
    });
    }, function() {
    can_open = false;
    $(".master-menu-wrapper > ul").stop().animate({ "height": 18 }, 'slow', function() {
    $(".master-menu-topbottom").css("background-position", "left 0px");
    can_open = true;
    });
    });
    $(".master-menu-topbottom").click(function() {
    can_open = false;
    $(".master-menu-wrapper > ul").animate({ "height": 18 }, 'slow', function() {
    $(".master-menu-topbottom").css("background-position", "left 0px");
    can_open = true;
    });
    });
    */

    $(".master-menu-topbottom").click(function() {
        if (open) {
            $(".master-menu-wrapper > ul").animate({ "height": 18 }, 'slow', function() {
                $(".master-menu-topbottom").css("background-position", "left 0px");
                open = false;
            });
        } else {
            if (can_open) {
                $(".master-menu-wrapper > ul").animate({ "height": 143 }, 'slow', function() {
                    $(".master-menu-topbottom").css("background-position", "left -10px");
                    open = true;
                });
            }
        }
    });
});



//carrocel infinito
/*
var can_open = true;
var open = false;
function rola_menu(direcao) {
if (direcao == "right") {
largura = $(".master-menu-wrapper > ul > li:first-child").outerWidth(true) * -1;
$(".master-menu-wrapper > ul > li:first-child").animate({ "margin-left": largura }, 'normal', function() {
$(this).insertAfter($(".master-menu-wrapper > ul > li:last-child"), function() {
//zera margin
//$(".master-menu-wrapper > ul > li:last-child").css("margin-left", "0px");
});
$(".master-menu-wrapper > ul > li:last-child").css("margin-left", "0px");
});
} else {
largura = $(".master-menu-wrapper > ul > li:last-child").outerWidth(true) * -1;
$(".master-menu-wrapper > ul > li:last-child").css("margin-left", largura + "px");
$(".master-menu-wrapper > ul > li:last-child").insertBefore($(".master-menu-wrapper > ul > li:first-child"), function() {
//$(this).animate({ "margin-left": 0 }, 'slow');
});
$(".master-menu-wrapper > ul > li:first-child").animate({ "margin-left": 0 }, 'normal');
}
}

$(document).ready(function() {
//scroll menu
$(".master-menu-right").click(function() {
rola_menu("right");
});
$(".master-menu-left").click(function() {
rola_menu("left");
});
//open menu
$(".master-menu-topbottom").click(function() {
if (open) {
$(".master-menu-wrapper > ul").animate({ "height": 18 }, 'slow', function() {
$(".master-menu-topbottom").css("background-position", "left 0px");
open = false;
});
} else {
if (can_open) {
$(".master-menu-wrapper > ul").animate({ "height": 143 }, 'slow', function() {
$(".master-menu-topbottom").css("background-position", "left -10px");
open = true;
});
}
}
});
});
*/
