

(function($){
    var screenSize = $(document).height(); // Changes the blob total height
    var freezeBlob = false;
	var BLOB_WIDTH_SIZE = 155; 
	
	 $(document).ready(function(){
			//BLOB_WIDTH_SIZE blob on page load
             $('#blob').hide(); 
      });
	  
 
    $.fn.spasticNav = function(options){
        options = $.extend({
            overlap:  $(window).height(), // Changes the height of the blob to the size of the inner window.
            speed: 1100,
            reset: 1500,
            color: '#3c3c3c',
            easing: 'easeOutExpo'
        }, options);
        
        return this.each(function(){
            var nav = $(this), currentPageItem = $('#selected', nav), blob, reset;
            
            $('<li id="blob"></li>').css({
                width: BLOB_WIDTH_SIZE, // ORIGINAL VALUE --> currentPageItem.outerWidth(),
                height: options.overlap,
                marginLeft: 20, // Off-set of blob from the left 
                left: currentPageItem.position().left,
                top: 0,
                backgroundColor: options.color
            }).appendTo(this);
            
			
			// Needed for resizing reasons.
			$(window).resize(function() {
				blob.css({
				height: $(window).height()
				});
			});
			
			$(window).scroll(function() {
				blob.css({
				height: $(document).height()
				}); 
			});


            
            blob = $('#blob', nav);
            
            // TODO: UNCOMMENT LINE TO DISPLAY blob
            //blob.hide();
            
            
            $('#nav li a').click(function(){
                // Reset the color for all nav links
                //$("#nav li a").css({'color' : '#999999'});
                
                freezeBlob = false;
                $('#blob').fadeIn(1000);
                clearTimeout(reset);
                blob.animate({
                    opacity: 1,
                    left: $(this).position().left,
                    width: BLOB_WIDTH_SIZE // Specify the width of the blob. ORIGINAL -> $(this).width() + 120 
                }, {
                    duration: options.speed,
                    easing: options.easing,
                    queue: false
                });
            }, function(){ 
                // mouse out  
                reset = setTimeout(options.reset);
            });
             
              
			// ORIGINAL BEHAVIOUR - Check to see if user is still on top of the area of interest
            /*$(document).click(function(event){ 
                if ($(event.target.parentNode).is('div#nav_links') ||
				$(event.target).is('div#header') || 
				$(event.target.parentNode.parentNode).is('div#nav_links') || 
				$(event.target).is('li#blob') || 
				$(event.target.parentNode).is('ul#nav') || 
				$(event.target).is('img') ||
				$(event.target).is('a')) {
					  freezeBlob = true;
                }
				else{ 
					if(freezeBlob){
						// Reset the UI components to plain.
						resetWebUI(blob);
						freezeBlob = false;
					}
				
				} 
            }); */
            
            // ORIGINAL BEHAVIOUR - Handle UI events when user mouseEnters the blob
             $('#nav li a').click(function(event){
                hideGalleries();
            });  
        }); // end each 
    };
    
})(jQuery);
$('#nav').spasticNav();

