window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};

(function($){
	$.fn.equalize = function(){
		var element = this;
		

			var currentTallest = 0,
				currentRowStart = 0,
				rowDivs = new Array(),
				$el,
				topPosition = 0;
						
			$(element).each(function() {
				$el = $(this);
				topPostion = $el.position().top;
				
				if (currentRowStart != topPostion) {
					// we just came to a new row.	Set all the heights on the completed row
					for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
						rowDivs[currentDiv].height(currentTallest);
					}			 
					// set the variables for the new row
					rowDivs.length = 0; // empty the array
					currentRowStart = topPostion;
					currentTallest = $el.height();
					rowDivs.push($el);
				} else {
					// another div on the current row.	Add it to the list and check if it's taller
					rowDivs.push($el);
					currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);   
				}
			
				// do the last row
				for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
					rowDivs[currentDiv].height(currentTallest);
				}
			});
		
	};
})(jQuery);

(function($) {
	
	
	// uses jjcycle so the jquery cycle is not duplicated
	$('#slider')
	.jjcycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 4000 // 0 no animation
	});
	
	$(".frame>a").equalize();
	$(".views .grid").click(function() {
		$(".frame>a").equalize();
	});



	
	
})(jQuery)

