/* Copyright 2011-2012, Marc S. Brooks (http://mbrooks.info) */

/*
 * Initialize
 */
$(document).ready(function() {

    // .. lotus plugin
    $('#contact').LotusLightbox({
        viewSpeed : 200
    });

    // .. anchor link events
    $('.link_contact').click(function() {
        $('#contact').LotusLightbox('view');
    });

    // .. tooltip plugin
    $('.links').TulipTips({
        eventType : 'mouseenter'
    });

    // .. scroller plugin
    $('#projects').DaisyScroller();

    var aVisible = null;
    var pVisible = null;
    var sVisible = null;

    // .. project scroller
    $('#body div.main strong.projects').click(function() {
        if (sVisible) {
            hideScroller(function() {
                sVisible = null;
            });
        }
        else {
            viewScroller(function() {
                $(this).DaisyScroller('start');

                sVisible = true;
            });
        }
    });

    // .. photo animation
    $('#body div.about').mouseover(function() {
        if (aVisible) {
            viewPhotoColor();
        }
    });

    // .. footer links
    $('#footer div.links a.link_about').click(function() {
        if (sVisible) {
            hideScroller(function() {
                hideDefault(function() {
                    viewAbout(function() {
                        sVisible = null;
                        aVisible = true;
                    });
                });
            });
        }
        else
        if (aVisible) {
            hideAbout(function() {
                viewDefault(function() {
                    aVisible = null;
                });
            });
        }
        else {
            hideDefault(function() {
                viewAbout(function() {
                    aVisible = true;
                })
            });
        }
    });
});

/*
 * View the document elements
 */
$(window).load(function() {
    $('#header, #body, #footer').fadeIn('slow');
});

/*
 * View the content scroller
 */
function viewScroller(callback) {
    $('#projects').stop().slideDown({
        duration : 1000,
        easing   : 'easeOutBounce',
        complete : callback
    });
}

/*
 * Hide the content scroller
 */
function hideScroller(callback) {
    $('#projects').DaisyScroller('reset');
    $('#projects').stop().slideUp({
        duration : 1000,
        easing   : 'easeInExpo',
        complete : callback
    });
}

/*
 * View the main content
 */
function viewDefault(callback) {
    $('#body div.main').stop().fadeIn('slow', callback);
}

/*
 * Hide the main content
 */
function hideDefault(callback) {
    $('#body div.main').fadeOut('slow', callback);
}

/*
 * View the about content
 */
function viewAbout(callback) {
    $('#body div.about').show(0);
    $('#body div.about').stop().animate({
        left : '+=' + getObjCenter( $('#body div.about') )
    }, 1000, 'easeOutExpo', callback);

    $('a.link_about').css('color','#000000');
}

/*
 * Hide the about content
 */
function hideAbout(callback) {
    $('#body div.about').fadeOut('fast');
    $('#body div.about').stop().animate({
        left : '-=' + getObjCenter( $('#body div.about') )
    }, 1000, 'easeOutExpo', callback);

    viewPhotoVector();

    $('a.link_about').css('color','#3399CC');
}

/*
 * View the color photo
 */
function viewPhotoColor() {
    $('#body div.about div.photo img').stop().fadeOut('slow');
}

/*
 * View the vector photo
 */
function viewPhotoVector() {
    $('#body div.about div.photo img').fadeIn('slow');
}

/*
 * Return the X position to align center in the browser viewport
 */
function getObjCenter(object) {
    var winWidth = $(window).width();
    var objWidth = object.width();
    return (winWidth - ((winWidth - objWidth) / 2));
}

