/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","visible");
		});
	}
})(jQuery);

/**
 * Scaling 1.0 - Scale any page element
 *
 * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
 * Dual licensed under:
 * 	MIT: http://www.opensource.org/licenses/mit-license.php
 *	GPLv3: http://www.opensource.org/licenses/gpl-3.0.html
 */
var SCALE_DOWN=1,SCALE_UP=2,SCALE_SMART=3,SCALE_MAX=4,SCALE_MIN=5,SCALE_RAW=6;(function(I){String.prototype.toInt=function(){return this.replace(/px/,"")*1};Number.prototype.toInt=function(){return this};I.scaling={asOriginal:false,makeOriginal:false,rescale:false,sqcorrect:true,mode:SCALE_SMART,target:"1x1"};var E=0,B=1,D=2,A=3,G=4,C=5,F=6;I.getScale=function(J){var K={x:1,y:1},H;switch(true){case J instanceof jQuery:H=J.eq(0);K.x=H.width().toInt();K.y=H.height().toInt();break;case typeof J=="number":K.x=J;K.y=J;break;case typeof J=="string"&&/%/.test(J):H=J.replace(/%/,"")/100;K.x=H.toInt();K.y=H.toInt();break;case typeof J=="string"&&/x|:/.test(J):H=J.replace(/x/,":").split(":");K.x=H[0].toInt();K.y=H[1].toInt();break;case J instanceof Array:K.x=J[0].toInt();K.y=J[1].toInt();break;case J.nodeType==1:case typeof J=="string":H=I(J).eq(0);K.x=H.width().toInt();K.y=H.height().toInt();break;case J instanceof Object&&"x" in J&&"y" in J:K.x=J.x.toInt();K.y=J.y.toInt();break;default:break}return K};I.fn.scale=function(H){var H=I.extend({},I.scaling,H),J=I.getScale(H.target);return this.each(function(){var L=I.getScale(this),O=I(this),T={},Q,P,N,S,M=false,K=false;if(!O.data("dimensions")||H.asOriginal){O.data("dimensions",L)}if(H.rescale){L=O.data("dimensions")}P=L.y>L.x?true:false;N=J.x==J.y?false:true;S=(P?L.x/L.y:L.y/L.x)>0.975;if(N){K=J.y>J.x?true:false;M=J.x>J.y?true:false}switch(H.mode){case SCALE_DOWN:Q=P?B:E;break;case SCALE_UP:Q=P?E:B;break;case SCALE_MAX:M=!M;K=!K;if(J.x>L.x&&J.y>L.y){return}Q=M?A:K?D:P?D:A;break;case SCALE_MIN:if(J.x<L.x&&J.y<L.y){return}Q=M?G:K?C:P?C:G;break;case SCALE_RAW:Q=F;break;case SCALE_SMART:var R=O.data("scaledTo")||{x:1,y:1};Q=(R.x/R.y)>(J.x/J.y)?P?B:E:P?E:B;break}switch(Q){case F:T.width=L.x*J.x;T.height=L.y*J.y;break;case A:case C:T.width=J.x;T.height=(L.y*J.x)/L.x;break;case D:case G:T.height=J.y;T.width=(L.x*J.y)/L.y;break;case B:T.height=(L.x*J.y)/J.x;break;case E:T.width=(L.y*J.x)/J.y;break}if(S&&H.sqcorrect){if(T.width&&T.width>L.x){T={height:(L.x*J.y)/J.x}}else{if(T.height&&T.height>L.y){T={width:(L.y*J.x)/J.y}}}}O.data("scaledTo",J);if(this.tagName.toLowerCase()=="img"){O.attr(T)}else{O.css(T)}if(H.makeOriginal){O.data("dimensions",{x:T.width||L.x,y:T.height||L.y})}})}})(jQuery);

;(function($) {
// Animated Scrolling for Same-Page Links
// @see http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links

$.fn.smoothScroll = function(options) {
  var opts = $.extend({}, $.fn.smoothScroll.defaults, options),
      locationPath = filterPath(location.pathname),
      scrollElem = scrollableElement('html', 'body');
      
  this.each(function() {
    var link = this,
        $link = $(this),
        hostMatch = ((location.hostname === link.hostname) || !link.hostname),
        pathMatch = (filterPath(link.pathname) || locationPath) === locationPath,
        thisHash = link.hash && link.hash.replace('#',''),
        scrollTargetExists = thisHash && !!$('#' + thisHash).length;

    if (hostMatch && pathMatch && scrollTargetExists) {
      var include = true,

          exclude = opts.exclude,
          elCounter = 0,
          el = exclude.length,

          excludeWithin = opts.excludeWithin,
          ewlCounter = 0,
          ewl = excludeWithin.length;
       
      while (include && elCounter < el) {
        if ($link.is(exclude[elCounter++])) {
          include = false;
        }
      }
      while (include && ewlCounter < ewl) {
        if ($link.parents(excludeWithin[ewlCounter++] + ':first').length) {
          include = false;
        }
      }

      if (include) {
        $link.data('scrollTarget', '#' + thisHash);
      }
    }

  });

  
  this.die('click.smoothscroll').live('click.smoothscroll', function(event) {
    var scrollTargetId = $(this).data('scrollTarget');
    if (scrollTargetId) {
      event.preventDefault();
       
      var scrollTargetOffset = $(scrollTargetId).offset().top;

      $(scrollElem).animate({scrollTop: scrollTargetOffset + opts.offset}, 400, function() {
        // location.hash = target;
      });
    }
  });
  return this;
  
  // private functions
  
  // don't pass window or document
  function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i < argLength; i++) {
      var el = arguments[i],
          $scrollElement = $(el);
      if ($scrollElement.scrollTop() > 0) {
        return el;
      } else {
        $scrollElement.scrollTop(1);
        var isScrollable = $scrollElement.scrollTop() > 0;
        $scrollElement.scrollTop(0);
        if (isScrollable) {
          return el;
        }
      }
    }
    return [];
  }
  
  function filterPath(string) {
    return string
      .replace(/^\//,'')
      .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
      .replace(/\/$/,'');
  }
  
  function debug($obj) {
    if (window.console && window.console.log) {
      window.console.log($obj);
    }
  }
};

// default options
$.fn.smoothScroll.defaults = {
  exclude: [],
  excludeWithin:[],
  offset: 0
};

})(jQuery);
