$(document).ready(function() {
    $("button").button();
    getMain();
    getaysoPhotoShow();

    // create the image rotator
    setInterval("rotateImages()", 10000);

    $('#aysoBtnMainNavHome').click(function(event) {
        event.preventDefault();
        getMain();
    });
    $('#aysoBtnMainNavRegister').click(function(event) {
        event.preventDefault();
        $.get('/_ajax_php_include/registration.php', function(data) {
            $('#aysoMainContentWrapper').html(data);

            // start of tabs

            $('#tabs div').hide(); // Hide all divs
            $('#tabs div:first').show(); // Show the first div
            $('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
            $('#tabs ul li a').click(function(){ //When any link is clicked
                $('#tabs ul li').removeClass('active'); // Remove active class from all links
                $(this).parent().addClass('active'); //Set clicked link class to active
                var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
                $('#tabs div').hide(); // Hide all divs
                $(currentTab).show(); // Show div with id equal to variable currentTab
                return false;
            });

        // end of tabs

        });
    });
    $('#aysoBtnMainNavMaps').click(function(event) {
        event.preventDefault();
        $.get('/_ajax_php_include/maps.php', function(data) {
            $('#aysoMainContentWrapper').html(data);
        });
    });
    $('#aysoBtnMainNavSchedule').click(function(event) {
        event.preventDefault();
        $.get('/_ajax_php_include/schedule.php', function(data) {
            $('#aysoMainContentWrapper').html(data);
        });
    });
    $('#aysoBtnMainNavSponsors').click(function(event) {
        event.preventDefault();
        // $("#aysoMainContentWrapper").html("List of sponsors go here...");
        $("#aysoMainContentWrapper").html("");
    });
    $('#aysoBtnMainNavAbout').click(function(event) {
        event.preventDefault();
        // $("#aysoMainContentWrapper").html("About us goes here...");
        $("#aysoMainContentWrapper").html("");
    });
    $('#aysoBtnMainNavContact').click(function(event) {
        event.preventDefault();
        $.get('/_ajax_php_include/contact.php', function(data) {
            $('#aysoMainContentWrapper').html(data);
        });
    });
});

function getMain() {
    $.get('/_ajax_php_include/main.php', function(data) {
        $('#aysoMainContentWrapper').html(data);
    });
}

function getaysoPhotoShow() {
    $.get('/_ajax_php_include/photoshow.php', function(data) {
        $('#aysoPhotoShow').html(data);
    });
}

function rotateImages() {
    var oCurPhoto = $('#aysoPhotoShow div.current');
    var oNxtPhoto = oCurPhoto.next();
    if (oNxtPhoto.length == 0) {
        oNxtPhoto = $('#aysoPhotoShow div:first');
    }

    oCurPhoto.removeClass('current').addClass('previous');
    oNxtPhoto.css({
        opacity: 0.0
    }).addClass('current').animate({
        opacity: 1.0
    }, 3000, function() {
        oCurPhoto.removeClass('previous');
    });
};
