$(function(){	
	
	//$('#overscroll').css('height', $(window).height() + 300);
	//$('#overscroll').css('width', $(window).width());
	
    $("#overscroll").overscroll({showThumbs: false});
	
	
	$(window).resize(function(){
		$('#overscroll').width($(window).width());
		$('#overscroll').height($(window).height());
	});
	
	
	  
	$(document).waitForImages(function() {
	  
	  
      var $container = $('#wall');

      $container.isotope({
		  itemSelector: '.box',
			masonry : {}
      });
	  
	  
      
      
      var $optionSets = $('#options .option-set'),
          $optionLinks = $optionSets.find('a');

      $optionLinks.click(function(){
        var $this = $(this);
		
		
		
		// Hide / show featured project
		
		if ($this.attr('data-option-value') == '*'){
			$('.feature').fadeIn('slow');	
		} else {
			$('.feature').fadeOut();
		}
		
		
		if($('#post_intro').is(':visible')){
			$('#post_intro').fadeOut();	
		}
		
		
		
        // don't proceed if already selected
        if ( $this.hasClass('selected') ) {
          return false;
        }
		
        var $optionSet = $this.parents('.option-set');
        $optionSet.find('.selected').removeClass('selected');
        $this.addClass('selected');
        $this.parent().addClass('selected');
  
        // make option object dynamically, i.e. { filter: '.my-filter-class' }
        var options = {},
            key = $optionSet.attr('data-option-key'),
            value = $this.attr('data-option-value');
        // parse 'false' as false boolean
        value = value === 'false' ? false : value;
        options[ key ] = value;
        if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
          // changes in layout modes need extra logic
          changeLayoutMode( $this, options )
        } else {
          // otherwise, apply new options
          $container.isotope( options );
		  
        }
		        
        return false;
		
      });
		
		//$('#wall').removeAttr('style');
		$('#overscroll').width($(window).width());
		$('#overscroll').height($(window).height());
		
	});
	
	
	  var element = document.getElementById('overscroll');
	  element.onselectstart = function () { return false; } // ie
	  element.onmousedown = function () { return false; } // mozilla
		
	// Initially we need to bind the mousewheel event to the window and allow the user to scroll up and down as though
	// the scroll bars were still there... Hiding the the scrollbars in the css stops the users mouse from moving up and down
	// therefore this is required.
	/*
	$(window).bind("mousewheel", function (ev, delta) {
    	var scrollTop = $(window).scrollTop();
    	$(window).scrollTop(scrollTop - Math.round(delta * 20));
	});
	*/
	
	// Close the intro overlay
	$('.closeIntro, #intro_wrapper').live('click', function(){
				
		$('#intro_wrapper').fadeOut(function(){
			// Now that the intro has been closed we do not want the user to be able to hover over block elements and scroll down.
			// the solution for this is to unbind the mousewheel event, this will disable the user from using the mouse wheel to scroll.
			$('html,body').animate({scrollTop : 0}, 2000);	
			
			$(window).unbind("mousewheel");
			$('#post_intro').fadeIn();
		});	
		
		return false;
	});
	
	
	// Hide the post into message
	$('#overscroll').mousedown(function(){
		$('#post_intro').fadeOut();
	});
	
	
	$('#post_intro').mousedown(function(){
		$(this).fadeOut();	
	});


	/* Project Box Info
	=======================*/
	
	$('.box').live('mouseenter mouseleave', function(event){
		
		
		var infoBox = $(this).find('section');
		var boxHeight = infoBox.height() + Number(40);
		
		if (event.type == 'mouseenter'){
			
			// Move the info to the bottom of the box out of sight.
			// Adding an additional 40px to compensate for the padding applied to the
			// section element
						
			infoBox.css('bottom', -boxHeight);
				
			// Pull the box up so that it is visible to the visitor 
			
			infoBox
				.stop()
				.show()
				.animate({'bottom' : 0}, 250);
			
		} else {
			
			infoBox
				.stop()
				.animate({'bottom' : -boxHeight}, 100);
			
			
		}
			
	});
	
	
	
});

