$(document).ready(function() {
    $('#left > p').cycle({
        fx: 'fade',
        speed:    2500,
        timeout:  1500
    });
});

var ris = false;
var info = false;

function loadItem (item) {
    if (item == 'ris') {
        if (ris == false) {
            if (info != false) {
                unloadInfo(true);
                loadRistorante(true);
            } else {
                loadRistorante(false);
            }
        } else {
            unloadRistorante(false);
        }
    }
    if (item == 'info') {
        if (info == false) {
            if (ris != false) {
                unloadRistorante(true);
                loadInfo(true);
            } else {
                loadInfo(false);
            }
        } else {
            unloadInfo(false);
        }
    }
}

function loadRistorante (half) {
    $('#ris').fadeIn(1500);
    $('#home').hide();

    if (half == false) {
        $('#contents').animate({
            marginTop: "-=333"
        }, 1000, function() {
            $('#ristext').show(1000);
            ris = true;
        });
    } else {
        $('#ristext').show(1000);
        ris = true;
    }

}

function unloadRistorante (half) {
    $('#home').fadeIn(1500);
    $('#ris').hide();

    if (half == false) {
        $('#ristext').hide(1000,function() {
            $('#contents').animate({
                marginTop: "+=333"
            }, 1000);
            ris = false;
        });
    } else {
        $('#ristext').hide(1000);
        ris = false;
    }
}

function loadInfo (half) {
    $('#info').fadeIn(1500);
    $('#home').hide();
    $('#left > p').cycle('pause');

    if (half == false) {
        $('#contents').animate({
            marginTop: "-=333"
        }, 1000, function() {
            $('#infotext').show(1000);
            info = true;
        });
    } else {
        $('#infotext').show(1000);
        info = true;
    }
}

function unloadInfo (half) {
    $('#home').fadeIn(1500);
    $('#info').hide();
    $('#left > p').cycle('resume');

    if (half == false) {
        $('#infotext').hide(1000,function() {
            $('#contents').animate({
                marginTop: "+=333"
            }, 1000);
            info = false;
        });
    } else {
        $('#infotext').hide(1000);
        info = false;
    }
}
