/* 
 * Handles dynamic content show/hide on 2011 homepage redesign
 */

var curTab = '';

$(document).ready(function() {
    $('#nav-main-buy').attr('href', '#');
    $('#nav-main-buy').click(function() { return showContent('buy'); });
    $('#nav-main-learn').attr('href', '#');
    $('#nav-main-learn').click(function() { return showContent('learn'); });
    $('#nav-main-help').attr('href', '#');
    $('#nav-main-help').click(function() { return showContent('help'); });
    $('.subcontent-button').attr('href','#');
    $('.subcontent-button').click(function() { return showSubcontent( $(this).attr('id') ); });
    $('.close-subcontent').attr('href','#');
    $('.close-subcontent').click(function() { return hideSubcontent(); });
    $('.info-suitcase').hide();
    $('.link-suitcase').attr('href','#');
    $('.link-suitcase').click(function() { return showInfobox( $(this).html() ); });
    $('.exit-suitcase').click(function() { return hideInfobox(); });
});

function showContent(panel) {
    curTab = panel;
    //addTabToHistory();

    $('#content-buy').hide();
    $('#content-learn').hide();
    $('#content-help').hide();
    $('#content-' + panel).show();
    $('#nav-main-buy').removeClass('active');
    $('#nav-main-learn').removeClass('active');
    $('#nav-main-help').removeClass('active');
    $('#nav-main-' + panel).addClass('active');
    hideSubcontent();
    return false;
}

function showSubcontent(panel) {
    $('.subcontent').hide();
    $('#subcontent-' + panel).show();
    $('.subcontent-button').removeClass('active');
    $('#' + panel).addClass('active');
    if(initConfirmationDialog)
    {
        initConfirmationDialog();    
    }
    return false;
}

function hideSubcontent() {
    $('.subcontent').hide();
    $('.subcontent-button').removeClass('active');
    return false;
}

function showInfobox(panel) {
    $('.info-suitcase').hide();
    $('.list-suitcase').hide();
    $('#content-' + panel).show();
    return false;
}

function hideInfobox() {
    $('.info-suitcase').hide();
    $('.list-suitcase').show();
    return false;
}

function addTabToHistory() {
    var url = '/' + curTab + '/';

    var stateObj = { foo: url };
    history.pushState(stateObj, url, url);


//location.href = url
// Does not work alone
// Does not work with pushState
// Does not work with replaceState

// window.location.assign(url);
// Does not work alone
// Does not work with pushState

// document.location = url
// Does not work alone
// Does not work with pushState

// document.location.replace(url)
// Does not work alone

// window.location.href = url
// Does not work alone
// Does not work with pushState

}
