$(document).ready(function()
{
	/*-------------------------------------------    
  	MASONRY:
	work page
	-------------------------------------------*/
	var 
	  speed = 1000,   // animation speed
	  $wall = $('ul#work-items'),
	  $nav = $('ul#work-categories li a'),

	  masonryOptions = {         // initial masonry options
	    columnWidth: 1, 
	    itemSelector: 'li.work-item:not(.invis)',
	    animate: true,
	    animationOptions: {
	      duration: speed,
	      queue: false
	    }
	  }
	;

	// run on window.load so we can capture any incoming hashes
	  $(window).load(function(){
	  // run masonry on start-up to capture all the boxes we'll need
	  $wall.masonry(masonryOptions);
	  if ( window.location.hash ) {
	    // get rid of the '#' from the hash
	    var possibleFilterClass = window.location.hash.replace('#', '');
	    switch (possibleFilterClass) {
	    // if the hash matches the following words
	    case 'branding' : case 'online' : case 'print' : 
	      // set masonry options animate to false
	      masonryOptions.animate = false;
	      // hide boxes that don't match the filter class
	      $wall.children().not('.'+possibleFilterClass).toggleClass('invis').hide();
		  //set nav current class  
		  $nav.removeClass('current');
		  $('ul#work-categories li a.'+possibleFilterClass).addClass('current');
      	  
		  // run masonry again, this time with the necessary stuff hidden
	      $wall.masonry(masonryOptions);
	      break;
	    }
	  }
	});

	$nav.click(function(){
	  $nav.removeClass('current');
	  
	  var 
	    cat = $(this).attr('class'),
	    filterClass = '.' + cat;
	  ;

	  if (filterClass == '.all') {
	    // show all hidden boxes
	    $wall.children('.invis').toggleClass('invis').fadeIn(speed);
	  } else {
	    // hide visible boxes
	    $wall.children().not(filterClass).not('.invis').toggleClass('invis').fadeOut(speed);
	    // show hidden boxes
		$wall.children(filterClass+'.invis').toggleClass('invis').fadeIn(speed);
	  }
	  $wall.masonry({ animate: true });
	  // set hash in URL
	  window.location.hash = cat;
	  $(this).addClass('current');
	  return false;
	});







	
	/*-------------------------------------------    
  	TOOLTIP:
	Sidewide tooltips
	-------------------------------------------*/




	/*-------------------------------------------    
  	FORMS:
  	Add initial value to fields with .filled class
	-------------------------------------------*/
	var filled = $('input.filled');
		
	if(filled.length > 0){
		for(var i = 0; i < filled.length; i++){
				
			
			$(filled[i]).addClass('empty');
			filled[i].initialValue = filled[i].value;
			
			filled[i].onclick = filled[i].onfocus = function(){
				$(this).removeClass('empty');
				$(this).addClass('filled');
				if(this.value == this.initialValue){
					this.value= '';
				}
			}
			
			filled[i].onblur = function(){
				if(this.value == this.initialValue || this.value == ''){
					$(this).addClass('empty');
					$(this).removeClass('filled');
					this.value = this.initialValue;
				}else{
					$(this).addClass('empty');
					$(this).removeClass('filled');
				}
			}
		}
	}
	else
	{
		return; 
	}


	/*-------------------------------------------    
  	SEARCH BOX:
  	Click to slide open/closed the site's search box
	-------------------------------------------*/

	$("a.search-btn").toggle(function(){	
	     $(".logo-expand").css({ height: '0px'});	     
	     $(".logo-expand").animate({ height: '3em', opacity: 'show' }, 'slow');	     
	     $("#search-container").animate({ height: 'show', opacity: 'show' }, 'slow');

	     
	   },function(){
	     $(".logo-expand").animate({ height: '0px'}, 'slow');	     
	     $("#search-container").animate({ height: 'hide', opacity: 'hide' }, 'slow');
	     $("#logo-expand").animate({ height: 'hide', opacity: 'hide' }, 'slow');


	   });


	/*-------------------------------------------    
  	HOMEPAGE CAROUSEL:
	-------------------------------------------*/

		// select #flowplanes and make it scrollable. use circular and navigator plugins
		$("#flowpanes").scrollable({size: 1}).circular(1).navigator({
		// ul.tabs now functions as our navigator
		navi:'ul.tabs'
	});


});

	/*-------------------------------------------    
  	FANCYBOX: [LIGHTBOX]
	-------------------------------------------*/
	
			$(document).ready(function() {
			/*
			*   Examples - images
			*/

			$("a#example1").fancybox({
				'titlePosition'	: 'inside'
			});

			$("a#example2").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a#example3").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'
			});

			$("a#example4").fancybox();

			$("a#example5").fancybox({
				'titlePosition'	: 'inside'
			});

			$("a#example6").fancybox({
				'titlePosition'	: 'over'
			});



		});




	/*-------------------------------------------    
  	LOAD FONTS BEFORE PAGE OR WAIT 3 SECONDS
	-------------------------------------------*/

	(function(){
	  // if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT
	  var d = document, e = d.documentElement, s = d.createElement('style');
	  if (e.style.MozTransform === ''){ // gecko 1.9.1 inference
	    s.textContent = 'body{visibility:hidden}';
	    e.firstChild.appendChild(s);
	    function f(){ s.parentNode && s.parentNode.removeChild(s); }
	    addEventListener('load',f,false);
	    setTimeout(f,3000); 
	  }
	})();

