(function ($) {
    Emma = {};
    Emma.Log = function(msg) {
        if (typeof(console) != "undefined") {
            console.log(msg);
        }
    };

    Emma.Main = function() {
        $(".fancybox_image").fancybox({
            'hideOnContentClick': true,
            'type' : 'image',
            'cyclic': true,
            'titlePosition': 'inside'
        });
    };

    Emma.hideProjects = function() {
        $('.portfolio-page').hide();
    };

    Emma.setupProjectTitles = function() {
        $('.project h3').each(function(index) {
            var title = $(this);

            title.hover(
                function () {
                    $(this).addClass('pointer');
                    $(this).find('a').addClass('active');
                },
                function () {
                    $(this).removeClass('pointer');
                    $(this).find('a').removeClass('active');
                }
            );

            var current_page = title.parent().find('.portfolio-page');
            title.bind('click', function() {
                $('.portfolio-page').not(current_page).slideUp();
                var page = title.parent().find('.portfolio-page');
                page.slideToggle();
                //$('html, body').animate({scrollTop:title.offset().top}, 500);
            });
        });
    };
    
    Emma.openProjectFromHash = function() {
        if (window.location.hash) {
            var projectSelectorID = window.location.hash;
            $(projectSelectorID).find('.portfolio-page').slideToggle();
        }
    };

})(jQuery);

$(function () {
    Emma.Main();
    Emma.hideProjects();
    Emma.setupProjectTitles();
    Emma.openProjectFromHash();
});

