var lastPTab;
var lastSTab;

$(document).ready(function()
{
    lastPTab = 'pnavAbout';
    lastSTab = 'snavAcademy';
    showNav('snavAbout', 'pnavAbout');
    showPage('academy', 'snavAcademy');
});

function hideAllNav()
{
    $('div#snavAbout').hide();
    $('div#snavSchedule').hide();
    $('div#snavGallery').hide();
    $('div#snavLearn').hide();
    $('div#snavContact').hide();
}

function showNav(name, target)
{
    hideAllNav();
    $('div#'+name).fadeIn(500);
    
    //$('a#'+lastPTab).css({'background-color' : '#75ba00', 'color' : '#fff'});
    $('a#'+lastPTab).css({'background-color' : 'transparent', 'color' : '#fff'});
    $('a#'+target).css({'background-color' : '#bacfa1', 'color' : '#666'});
    lastPTab = target;
}

function showPage(id, target)
{
    //$('div#content').slideUp(500);
    $.get('/?pid='+id,function(txt){
        $('div#content').hide();
        $('div#content').html(txt);
        $('div#content').fadeIn(1000);
    });
    
    $('a#'+lastSTab).css({'background-color' : '#bacfa1', 'color' : '#666'});
    $('a#'+target).css({'background-color' : '#fff', 'color' : '#666'});
    lastSTab = target;
}

function makeAppt(wheretooutput)
{
    $('input#submitbutton').attr('disabled', 'disabled');
    $(wheretooutput).append(' Submitting...');
    name = document.getElementById('name').value;
    phone = document.getElementById('phone').value;
    date = document.getElementById('date').value;
    
    $.post('/pages/makeappt.php',{
        name: name,
        phone: phone,
        date: date
    }, function(txt){
        $(wheretooutput).html(txt);
    });
}

function callMe(wheretooutput)
{
    $('input#ssubmitbutton').attr('disabled', 'disabled');
    $(wheretooutput).append(' Submitting...');
    phone = document.getElementById('cmphone').value;
    time = document.getElementById('whattime').value;
    
    $.post('/pages/callme.php',{
        phone: phone,
        time: time
    }, function(txt){
        $(wheretooutput).html(txt);
    });
}

function submitForm(wheretooutput)
{
    $('input#submitform').attr('disabled', 'disabled');
    $(wheretooutput).append(' Submitting...');
    email = document.getElementById('femail').value;
    fone = document.getElementById('ffone').value;
    message = phone = document.getElementById('fmessage').value;
    
    $.post('/pages/message.php',{
        email: email,
        fone: fone,
        message: message
    }, function(txt){
        $(wheretooutput).html(txt);
    });
}

function showPicture(picloc)
{
    $('div#picarea').hide();
    $('div#picarea').html('<img src="'+picloc+'" class="padded" />');
    $('div#picarea').fadeIn(1000);
}

function showSection(id, target)
{
   $.get('/?pid='+id,function(txt){
        $('div#'+target).hide();
        $('div#'+target).html(txt);
        $('div#'+target).fadeIn(1000);
    });
}