/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
// Load the page
function showPage(page) {
    $("#contentContainer").empty();

    $.ajax( {
        type: "POST",
        url: page + '.php',
        dataType: "html",
        data: '{}',
        success: function(result) {
            //alert(result);
            $("#contentContainer").append(result);
        },
        error: function(result) {
            pageGetError(result);
        }
    })
}

function pageGetError(result) {
    //debugger;
    alert(result);
}

// Cycle photos in the photo box
function cyclePhotos() {
    $.ajax( {
        type: "POST",
        url: "photorotater.php",
        dataType: "html",
        data: "{}",
        success: function(result) {
            $("#photoBox1").empty();
            $("#photoBox1").append(result);
        },
        error: function(result) {
            pageGetError(result);
        }
    });

    $.ajax( {
        type: "POST",
        url: "photorotater.php",
        dataType: "html",
        data: "{}",
        success: function(result) {
            $("#photoBox2").empty();
            $("#photoBox2").append(result);
            setTimeout("cyclePhotos()", 5000);
        },
        error: function(result) {
            pageGetError(result);
        }
    });
}

function showPhoto(gallery, photo) {
    var img = '<img src="photos/' + gallery + '/' + photo + '" alt="' + photo + '" />';
    $("#photoPopup").empty();
    $("#photoPopup").append(img);
    $("#photoPopup").dialog({
        autoOpen: false,
        width: 600,
        modal: true,
        bgiframe: true,
        buttons: {
                "Close": function() {
                        $(this).dialog("destroy");
                }
        }
    });
    $('#photoPopup').dialog('open');
    return false;
}

function showGallery(gallery){
    $.ajax( {
        type: "POST",
        url: "photos.php",
        dataType: "html",
        data: "action=showphotos&data=" + gallery,
        success: function(result) {
            $("#contentContainer").empty();
            $("#contentContainer").append(result);
            //alert(result);
        },
        error: function(result) {
            pageGetError(result);
        }
    });
    return false;
}

function submitContactForm() {
    $("#contentContainer").empty();
    var contactName = $("#contactName").val();
    var contactEmail = $("#contactEmail").val();
    var contactSubject = $("#contactSubject").val();
    var contactMessage = $("#contactMessage").val();


    $.ajax( {
        type: "POST",
        url: 'contactSubmission.php',
        dataType: "html",
        data: 'contactName=' + escape(contactName) +
            '&contactEmail='  + escape(contactEmail) +
            '&contactSubject='  + escape(contactSubject) +
            '&contactMessage='  + escape(contactMessage),
        success: function(result) {
            //alert(result);
            $("#contentContainer").append(result);
        },
        error: function(result) {
            pageGetError(result);
        }
    })

    return false;
}
