( function( $ ) {
    
    $.rainbowHover = function ( box, options )
    {
        var options = options || {};
        
        options.flashSpeed = options.flashSpeed || 80;
        
        options.colors = options.colors || [
            '#00FFFF',
            '#FF00FF',
            '#FFFF00'
        ];
        
        options.randomize = options.randomize || false;
        
        options.flashOther = options.flashOther || false;
        
        options.eventType = options.eventType || 'hover';
        
        options.outlineWidth = options.outlineWidth || 1;
        
        var colorCount = options.colors.length;
        var currColor  = -1;
        
        var flashing = 0;
        
        var $hoverObj = $(box);
        
        var $box = options.flashOther ? $(options.flashOther ) : $hoverObj;
        
        var defaultColor = $box.css('background-color');
        
        $box.css('outline', options.outlineWidth + 'px solid transparent');
        
        $hoverObj.hover(startFlash, killFlash);
        
        function startFlash() {
            flashing = setInterval(flashIt, options.flashSpeed);
        }
        
        function killFlash() {
            clearInterval( flashing );
            
            $box.css({
                backgroundColor : defaultColor,
                outlineColor : 'transparent'
            });
            
            if ( options.resetColorEachTime ) currColor = -1;
        }
        
        function flashIt() {
            if ( options.randomize ) {
                currColor = Math.floor( Math.random() * colorCount );
            }
            else {
                currColor++;
                if ( currColor >= colorCount ) currColor = 0;
            }
            
            $box.css({
                backgroundColor : options.colors[ currColor ],
                outlineColor : options.colors[ currColor ]
            });
        }
    };
    
    $.fn.rainbowHover = function ( options )
    {
        
        this.each( function() 
            {
                new $.rainbowHover( this, options );
            }
        );
        
        return this;
    };
})( jQuery );


$(function() {

    $.scrollingParallax('/img/sandbox-background.jpg', {
        staticSpeed : .1
    });
    
    $('#mainWrap a').rainbowHover({
        //randomize : true
    });
    
    $('.youtubin').youtubin();
    
    $('.youtubin-click').youtubin({
        replaceTime : 'click',
        wrapper : '<p></p>'
    });
    
    $.adsLast([
        '#google-ad-1',
        '#google-ad-2',
        '#google-ad-3'
    ]);

});