function addItemToBox(id) {
    
    // place menu box id in form
    $('#item_menubox_id').val(id);
    
    // get mouse position
    var y = parseInt($('#mouse_pos_y').html()) + 10;
    var x = parseInt($('#mouse_pos_x').html()) -  0;
    
    // move floating window and display
    $('#additemform').css("top", y +"px");
    $('#additemform').css("left", x +"px");
    $('#additemform').fadeIn();
}

function submitAddItemToBox() {
    
    $.post("include/additemtobox.php", { name: $('#item_name').val(), short_description: $('#item_short_description').val(), long_description: $('#item_long_description').val(), menubox_id: $('#item_menubox_id').val() }, function(data){
        //$("#additemform").html(data);
        reloadNavRight();
		reloadNavleft();
        $('#additemform').fadeToggle();
        
        // clear form
        $('#item_name').val("");
        $('#item_short_description').val("");
        $('#item_long_description').val("");
        $('#item_menubox_id').val("");
    });
}

function cancelAddItemToBox() {
    $('#item_name').val("");
    $('#item_short_description').val("");
    $('#item_long_description').val("");
    $('#item_menubox_id').val("");
    $('#additemform').fadeOut();
}

function addBoxRight() {
    // get mouse position
    var y = parseInt($('#mouse_pos_y').html()) + 10;
    var x = parseInt($('#mouse_pos_x').html()) - 50;
    
    // move floating window and display
    $('#addboxformright').css("top", y +"px");
    $('#addboxformright').css("left", x +"px");
    $('#addboxformright').fadeIn();
}

function addBoxLeft() {
    // get mouse position
    var y = parseInt($('#mouse_pos_y').html()) + 10;
    var x = parseInt($('#mouse_pos_x').html()) - 50;
    
    // move floating window and display
    $('#addboxformleft').css("top", y +"px");
    $('#addboxformleft').css("left", x +"px");
    $('#addboxformleft').fadeIn();
}   

function submitAddBoxRight() {
    $.post("include/addboxright.php", { name: $('#box_name_right').val() }, function(data){
        //$("#addboxform").html(data);
        reloadNavRight();
        $('#addboxformright').fadeToggle();
        
        // clear form 
        $('#box_name_right').val("");
    });
}

function submitAddBoxLeft() {
    $.post("include/addboxleft.php", { name: $('#box_name_left').val() }, function(data){
        //$("#addboxform").html(data);
        reloadNavleft();
        $('#addboxformleft').fadeToggle();
        
        // clear form 
        $('#box_name_left').val("");
    });
}

function cancelAddBox() {
    $('#box_name_right').val("");
	$('#box_name_left').val("");
    $('#addboxformright').fadeOut(); 
	$('#addboxformleft').fadeOut()
}

function removeBox(id) {
    if (!confirm("Removing this box will remove all item entries and all associated files.  Continue?")) return;
    $.post("include/removebox.php", { id: id }, function(data){
        //$("#navigation_right").html(data);
        reloadNavRight();
		reloadNavleft();
    });
}

function removeFile(id) {
    if (!confirm("Are you sure you want to remove the file?")) return;
    $.post("include/removefile.php", { id: id }, function(data){
        location.reload(true);
    });
}

function removeItem(id) {
    if (!confirm("Are you sure you want to remove the item and all its associated files?")) return;
    $.post("include/removeitem.php", { id: id }, function(data){
        //alert(data);
        reloadNavRight();
		reloadNavleft()
    });
}


function addDocument(id) {
    var y = parseInt($('#mouse_pos_y').html()) + 10;
    var x = parseInt($('#mouse_pos_x').html()) + 10;
    
    // move floating window and display
    $('#adddocumentform').css("top", y +"px");
    $('#adddocumentform').css("left", x +"px");
    $('#adddocumentform').fadeIn();
}

function cancelAddDocument() {
    //clear fields
    $('#file_name').val("");
    $('#file_file').val("");
    
    //hide
    $('#adddocumentform').fadeOut();
}   

function editItem(id) {
    // get mouse position
    var y = parseInt($('#mouse_pos_y').html()) + 10;
    var x = parseInt($('#mouse_pos_x').html()) - 250;
    
    // move floating window and display
    $('#edititemform').css("top", y +"px");
    $('#edititemform').css("left", x +"px");
    
    $('#edititemform').fadeIn();
    
    $.post("include/edititem.php", { id: id }, function(data){
        $('#edititemform').html(data);
        
    });
}

function submitEditItem() {
    $.post("include/submitedititem.php", { id: $('#edit_item_id').val(), name: $('#edit_item_name').val(), short_description: $('#edit_item_short_description').val(), long_description: $('#edit_item_long_description').val() }, function(data){
        //alert(data);
        location.reload(true);    
    });
    
    
}

function cancelEditItem() {
    $('#edititemform').fadeOut();
}

function reloadNavRight() {
    $.post("include/nav_right.php", function(data){
        $("#navigation_right").html(data);
    });

}   
function reloadNavleft() {
    $.post("include/nav_left.php", function(data){
        $("#navigation_left").html(data);
    });

} 

jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 