var frontend = {
    init: function()
    {
        // Initialize layout
        this.layout.init();

        // Initialize tables
        this.tables.init();

        if($('.spotlight').length > 0) this.spotlight.init();
        
        // Initialize jobs
        if($('.jobs').length > 0) this.jobs.init();
    },

    layout: {
        init: function()
        {
            this.parseExternalLinks();
			//this.parseRteYoutube();

            // Wrap each ol > li element in a div (to use color for the numbering)
            $('.rte ol li').wrapInner('<div></div>');

            // Add extra class to ol
            $('.rte ol').addClass('numbered');

            // Parse thumbnails
            $('.thumb').wrap('<div class="thumb"></div>');
        },

        parseExternalLinks: function()
        {
            $('a[rel=external]').click(function(e){
                open(this.href);
                e.preventDefault();
            });
        },

       /**
         * Set the minimum height
         * Is needed because navigation is positioned absolutely
         */

        setMinHeight: function(target)
        {
            // Set min-height of #main div, based on outerheight of target
            $('#main').css('min-height', (target.outerHeight()) + 'px');
        }
    },

    tables: {
        init: function()
        {
            // Add class 'first' to first th & td in table
            $('table th:last-child').addClass('last');
            $('table td:last-child').addClass('last');

            // Hide thead section when not first class
            // $('table:not(.first) thead').hide();
        }
    },

    spotlight: {
        init: function()
        {
            // Create control ul
            $control = $('<ul class="controls"></ul>');

            // Hide all spotlight items
            $('.spotlight .item').hide();

            // Get h2's from spotlight items
            $('.spotlight h2').each(function(i) {

                // Get count (i+1)
                var count = i + 1;

                // Create li element
                $el = $(('<li class="control-' + count + '" rel="spotlight-' + count + '"></li>'))

                // Append h2 to element
                .append($(this))

                // Hovering
                .hover(
                    function() {
                        $(this).addClass('hover')
                    },
                    function() {
                        $(this).removeClass('hover');
                    })

                // Assign listener to a.button
                .click(function(e) {

                    // Remove .selected from controls
                    $('.controls li').removeClass('selected');

                    // Add selected class
                    $(this).addClass('selected');

                    // Hide all spotlight items
                    $('.spotlight .item').hide();

                    // Show selected item
                    $('#' + $(this).attr('rel')).show();

                    e.preventDefault();
                });

                // Append element to control ul
                $control.append($el);
            });

            // Attach h2's to control ul

            // Attach ul to DOM
            $('.spotlight .col-1').append($control);

            // Auto select last
            if($('.control-1').length > 0) $('.control-1').trigger('click');
        }
    },
    
    jobs: {
        init: function()
        {        
            // Init ajaxLightbox
            $('a[rel="lightbox"]').ajaxLightbox({ overlayColor: '#0d3c71', overlayOpacity: 0.8 });
            
            // Iterate job items
            $('.jobs li').each(function(i) {
                $this = $(this);
                        
                // When hovered
                $this.hover(
                    // Hover in
                    function() {
                        $(this).find('div').show();
                    }, 
                    // Hover out
                    function() {
                        $(this).find('div').hide();
                    }
                );
            });
        }
    }
};


$(document).ready(function()
{
	// General javascript interaction
	frontend.init();
});
