/*--------------------------------------------------------------------
 * The following source code is a modified version of the original plugin "EqualHeights" for jQuery.
 *
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2009 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)

 * JQuery Plugin : "EqualHeights-Light"
 * Modified by : Michael (http://www.webdevcodex.com)
 * Description : Does not use px-em dependencies based from the original version. Also fixes a small bug which does not allow divs to be of equal heights if there are more than 2 divs.

------------------------------------------------------------------------*/

jQuery.fn.equalheight = function () {
    jQuery(this).each(function () {
        var currentTallest = 0; //create currentTallest var

        //go through every child of the mother div
        jQuery(this).children().each(function (i) {
            var $this = $(this);

            var skip = false;

            //skip absolute positioned elements
            if ($this.css("position").toLowerCase() == "absolute" ||
                $this.css("position").toLowerCase() == "fixed" ||
                $this.hasClass("dontEqualize") ||
                this.nodeName.toLowerCase() == "script" ||
                $this.is(":hidden")) {
                skip = true;
            }

            if (skip == false) {
                //Set back to the original height before recalculating
                if ($this.data("origHeight") != null) {
                    if (jQuery.browser.msie && jQuery.browser.version == 6.0) {
                        $this.css({ 'height': $this.data("origHeight") });
                    }
                    $this.css({ 'min-height': $this.data("origHeight") });
                }

                //keep checking every child's height and get the height of the tallest div											  
                if ($this.height() > currentTallest) { currentTallest = $this.height(); }
            }
        });

        //set currentTallest as pixels
        currentTallest = currentTallest + "px";

        //If browser is Microsoft Internet explorer, then use css "height: yypx"
        if (jQuery.browser.msie && jQuery.browser.version == 6.0) {
            jQuery(this).children().each(function () {
                var $this = $(this);
                var skip = false;

                //skip absolute positioned elements
                if ($this.css("position").toLowerCase() == "absolute" ||
                    $this.css("position").toLowerCase() == "fixed" ||
                    $this.hasClass("dontEqualize") ||
                    this.nodeName.toLowerCase() == "script" ||
                    $this.is(":hidden")) {
                    skip = true;
                }

                if (skip == false) {
                    if ($this.data("origHeight") == null) {
                        $this.data("origHeight", $this.css("height"));
                    }
                    $this.css({ 'height': currentTallest });
                }
            });
        }

        //use css "min-height: yypx"
        //jQuery(this).children().css({'min-height': currentTallest}); 
        jQuery(this).children().each(function () {
            var $this = $(this);
            var skip = false;

            //skip absolute positioned elements
            if ($this.css("position").toLowerCase() == "absolute" ||
                    $this.css("position").toLowerCase() == "fixed" ||
                    $this.hasClass("dontEqualize") ||
                    this.nodeName.toLowerCase() == "script" ||
                    $this.is(":hidden")) {
                skip = true;
            }

            if (skip == false) {
                if ($this.data("origHeight") == null) {
                    $this.data("origHeight", $this.css("min-height"));
                }
                $this.css({ 'min-height': currentTallest });
            }
        });
    });
    return this;
};
