/*
 * IMW CONTROLLER - Javascript controller for the site.
 */

var IMW = function( $ ) {
    /* Private members */
    
    /* Priviledged members */
    
    /* Private methods */
    
    // Mail spam protection
    function _mailme() {
        // Replace all of the mailto hrefs (avoid spam)
        var at = / at /;
        var dot = / dot /g;
        $('span.mailme').each(function() {
          var addr = $(this).text().replace(at,"@").replace(dot,".");
          $(this).after('<a class="m" href="mailto:'+addr+'" title="Send an email">'+ addr +'</a>')
                .hover(function(){window.status="Send a letter!";}, function(){window.status="";})
                .remove();
        });
    }
    
    // What runs on document.ready
    function _init() {
        
        // Mail spam protection
        _mailme();
        
        // Homepage slideshow
        if( IMW_HEROS.length > 0 ) {
            var $img = $(".hero img"),
                $header = $(".hero h1"),
                index = 1;
                
            setInterval(function() {
                // Swap out the image and header
                var current = IMW_HEROS[index];
                $img.attr("src", "/image.php/hero.jpg?width=620&image=" + current['image']);
                $header.text(current['excerpt']);
                
                index++;
                if( index >= IMW_HEROS.length ) index = 0;
                
            }, 8000)
        }
    };
    $(document).ready(_init);
    
    return {}
    
}( window.jQuery );
