// A little plugin to preload images.  Feed it an array of img URLs
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


$(document).ready(function(){
	//srcArray = []; 
  // So this works, but I'm finding that it is sucking down lots of memory.  I should instead write out the height from php. 
	/*$('.grow').each(function(index, val){
		self = $(this); 
    var eq = index; 
		var height = 'narf'; 
    self.find('img').load(function(){
      height = $(this).height(); 
      set_height(height, eq); 
    });
	});
	function set_height(height, eq)
  {
    $('.grow').eq(eq).css('height', height);
    mason(); 
  }*/

/*	function mason()
	{
		$('#img-container').masonry({
			// options
			itemSelector : '.grow',
			columnWidth : 240, 
			animationOptions: { queue: false, duration: 2000 }, 
			isAnimated: true
		});
	}

	var $container = $('#img-container');
	$container.imagesLoaded(function(){
	  $container.masonry({
		itemSelector : '.grow',
		columnWidth : 240
	  });
});*/




	$('.grow').each(function(index, val){
		self = $(this); 
    	var eq = index; 
		var height = 'narf'; 
    	self.find('img').load(function(){
			height = $(this).height(); 
			width = $(this).width(); 
			console.log(width); 
			console.log(height); 
			if (width / height >= 1)
			{
				$(this).css('height', '100%')
			}
			else 
			{
				$(this).css('width', '100%')
			}
		});
	});

	function set_height(height, eq)
	{
    	$('.grow').eq(eq).css('height', height);
    	mason(); 
  	}




});

