var isiPad = (navigator.userAgent.match(/iPad/i) != null) || (navigator.userAgent.match(/iPhone/i) != null);

/*-----------------------------------------------------------------------------------*/
/*	Functions
/*-----------------------------------------------------------------------------------*/

	/*floatingMenu.add('float', {  
		// Represents distance from top or bottom browser window border depending upon property used. Only one should be specified.  
		targetTop: 128,  
		// targetBottom: 0,
		 
		// Prohibits movement on x-axis  
		prohibitXMovement: true,
		
		// Remove this one if you don't want snap effect  
		snap: false
	});*/

	function clearActive(){
		$("li.filter a").css( "background-color", "" ).css( "background-image", "" ).css( "border", "" );
		$("li.filter a").css( "color", "" );
	};
	
	function onAfter(curr, next, opts) {
    	var index = opts.currSlide;
		$('#prev-button')[index == 0 ? 'hide' : 'show']();
		$('#next-button')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	
(function ($) {
	$.fn.vAlign = function() { return this.each(function(i){		
		var ah = $(this).height();
		var ph = $(this).parent().height();
		var mh = (ph - ah) / 2;
		$(this).css('margin-top', mh);
	})};
})(jQuery);

(function ($) {
	$.fn.hAlign = function() { return this.each(function(i){		
		var aw = $(this).width();
		var pw = $(this).parent().width();
		var mw = (pw - aw) / 2;
		$(this).css('margin-left', mw);
	})};
})(jQuery);

(function ($) {
	$.fn.showPointer = function() { return this.each(function(i){		
		$(this).hover(function () {
			$(this).css('cursor', 'pointer'); 
		});
	})};
})(jQuery);


(function() {

$(document).ready(function() {

/*-----------------------------------------------------------------------------------*/
/*	Thumbnail Overlay
/*-----------------------------------------------------------------------------------*/

	function thumbnailOverlay() {
		$('.portfolio a').hover( function () {
			$(this).find('.overlay').stop().animate({ opacity: 1 }, 200);
			$(this).find('.title').stop().css('color','#e66600');
		}, function () {
			$(this).find('.overlay').stop().animate({ opacity: 0 }, 200);
			$(this).find('.title').stop().css('color','');
		});
	}
	thumbnailOverlay();


/*-----------------------------------------------------------------------------------*/
/*	Portfolio Sorting
/*-----------------------------------------------------------------------------------*/
	
	
	
	
	
	
	
	 
	if (jQuery().quicksand) {
		
		(function($) {
		  $.fn.sorted = function(customOptions) {
			var options = {
			  reversed: false,
			  by: function(a) { return a.text(); }
			};
			$.extend(options, customOptions);
			$data = $(this);
			arr = $data.get();
			arr.sort(function(a, b) {
			  var valA = options.by($(a));
			  var valB = options.by($(b));
			  if (options.reversed) {
				return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;				
			  } else {		
				return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;	
			  }
			});
			return $(arr);
		  };
		})(jQuery);
		
		// DOMContentLoaded
		jQuery(function() {
		
		  // bind radiobuttons in the form
		  var $filterType = jQuery('#filter li a').html();
		  var $filterSort = jQuery('#filter li.sort a').html();
		
		  // get the first collection
		  var $applications = jQuery('#items');
		
		  // clone applications to get a second collection
		  var $data = $applications.clone();
		
		  // attempt to call Quicksand on every form change
		  jQuery('#filter li a').click(function(e) {
			
			if (jQuery(this).html() == 'View All') {
			  var $filteredData = $data.find('li');
			} else {
			  var $filteredData = $data.find('li[data-type=' + jQuery(this).html() + ']');
			}
		
			
		  // if sorted by name
		  var $sortedData = $filteredData.sorted({
			by: function(v) {
			  return jQuery(v).find('strong').text().toLowerCase();
			}
		  });
		
			// finally, call quicksand
			$applications.quicksand($sortedData, {
			  duration: 600,
			  adjustHeight: 'dynamic'
			}, function () {
			  thumbnailOverlay();
			  refreshScrollers();
			});
			
			e.preventDefault();
		
		  });
		
		});
	
	}
        
});

})();
