﻿


/*
Equalize heights plugin by Hallvarsson&Halvarsson
*/

(function($){
    
    /* PLUGIN IMPLEMENTATION/DEFINITION */
    
    var plugin = $.fn.equalizeHeights = function(options){
		var options = $.extend({}, $.fn.equalizeHeights.defaults, options);
		options.defaults = $.fn.equalizeHeights.defaults;
		
		options._this = this;
		
        var heightOfTallestElement = options.getHeightOfTallestElement(options, this);
        
        return this.each(function(){
            options.setHeightOfElement(options, $(this), heightOfTallestElement);
        });
    };
    
    /* PLUGIN DEFAULT OPTIONS */
    
    // Put lots of modular stuff here.
    
	plugin.defaults = {
		getHeightOfTallestElement:function(options, elements){
            var heightOfTallestElement = 0;
            
            elements.each(function(){
                var element = $(this);
                
                var elementHeight = element.height();
                
                if(elementHeight > heightOfTallestElement){
                    heightOfTallestElement = elementHeight;
                }
            });
            
            return heightOfTallestElement;
        },
		setHeightOfElement:function(options, element, height){
            var elementHeight = element.height();
            
            element.css("height", (height) + "px");
        }
	}
	
	/* OPTIONS API */
	
	// The following code enables all properties to also be functions, which is good.
	//
	// If a function is specified in options, then you can use the functionTarget parameter
	// to enable the use of "this" in those functions, and it should point to the object that
	// the function is being applied to form the beginnning.
	//
	// That is to say; $("a.more").plugin() <-- that "a.more" link is expected to be the "this"
	// variable in any specified functions.
	//
	// Also, the api provides a method for callbacks and a method for calling on methods.
	
	function valueIsValid(options, key){
		return options[key] == 0 || options[key]?true:false;
	}
	
	function getValue(options, key, functionTarget, opts){
		var value = options[key];
		
		if(typeof value == "function"){
			value = value.apply(functionTarget, new Array(options));
		}
		
		if(!value){
			if(opts && (opts["default"] == 0 || opts["default"])){
				return opts["default"];
			}
			
			return value;
		}
		
		if(opts && opts.suffix){
			return value + opts.suffix;
		} else {
			return value;
		}
	}
	
	function executeCallback(options, key, functionTarget){
		getValue(options, key, functionTarget);
	}
})(jQuery);















    