(function($) {
    $.decodeHTML = function(value) {
        return $('<div/>').html(value).text();
    };
    $.encodeHTML = function(value) {
        return $('<div/>').text(value).html();
    };	
})(jQuery);

/* Nano Templates (Tomasz Mazur, Jacek Becela) */
/* http://github.com/trix/nano */

(function($){
  $.nano = function(template, data) {
    return template.replace(/\{([\w\.]*)\}/g, function (str, key) {
      var keys = key.split("."), value = data[keys.shift()];
      $.each(keys, function () { value = value[this]; });
      return (value === null || value === undefined) ? "" : value;
    });
  };
})(jQuery);

/**
 * 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]);
 */

(function($) {
	$.fn.equalHeights_ = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
						   
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		tallest=Math.round(tallest * 1.02);
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest);
			if (maxHeight) $(this).css("overflow","visible");
		});
	}
})(jQuery);

/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
 
(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	$.fn.equalizeCols = function(minHeight){
		var height = (minHeight) ? minHeight : 0;
		var reset = $.browser.msie && $.browser.version < 7 ? "1%" : "auto";
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, $(this).height());
			})
			.css("height", height)
			.each(function() {
				var h = $(this).height();
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
	};
})(jQuery);

(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	$.fn.equalizeBottom = function(minHeight){
		var lower = (minHeight) ? minHeight : 0;
		var reset = $.browser.msie && $.browser.version < 7 ? "1%" : "auto";
		
		var items=[];
		this.css("height", reset)
			.each(function() {
			    var $this=$(this);
				var height = $this.height();
				var bottom = $this.outerHeight() + $this.offset().top;
				items.push({elem: $this, height: height, bottom: bottom});
				lower = Math.max(lower,bottom);
			});
		$.each(items,function() {
		     this.elem.css("height", this.height+(lower-this.bottom));
		})
	    return this
	};
})(jQuery);

(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	$.fn.swapimage = function(options){
		
		var fn = $.fn.swapimage,
		over = function(){
			var o=fn.op;
			var $img=$('img',this);
			if ($img.length>0) $img.attr('src',toggleFileSuffix($img.attr('src'),o.imageSuffix,true));
		},
		out = function(){
			var o=fn.op;
			var $this = $(this);
			if (!$this.hasClass('this')) {
				var $img=$('img',this);
				if ($img.length>0) $img.attr('src',toggleFileSuffix($img.attr('src'),o.imageSuffix,false));
			};
		},
		toggleFileSuffix = function (src,suffix,yesno) {
		 var suffext = src.lastIndexOf(suffix + '.')>0?src.substring(src.lastIndexOf(suffix + '.')):'';
		 var ext = src.substring(src.lastIndexOf('.'));
		 if (suffext=='') {
		  if (yesno) src=src.replace(ext,suffix + ext);
		 } else {
		  if (!yesno) src=src.replace(suffext,ext);
		 }   
		 return src;
		};
		
		fn.o = [];
		fn.op = {};
		fn.defaults = {
			imageSuffix	: '_f2'
		};
		
		return this.each(function() {
			var s = this.serial = fn.o.length;
			var o = $.extend({},fn.defaults,options);
			fn.o[s] = fn.op = o;
			
			var $this=$(this);
			$this.hover(over,out);
			
			//preload
			$('img',this).each(function(){
				$('<img />').attr("src",toggleFileSuffix($(this).attr('src'),o.imageSuffix,true));
			});
			
			//current
			if ($this.hasClass('this')) {
				var $img=$('img',this);
				if ($img.length>0) $img.attr('src',toggleFileSuffix($img.attr('src'),o.imageSuffix,true));				
			}
		});
	};
})(jQuery);

$j(function($){ 
	$(".swapimage").swapimage();
	$(document).click(function(e){
		if (e.which==1) {
			var $a=$(e.target).closest('a');
			if ($a.length>0) {
				var href=$a.attr('href');
				if (href.substr(0,7)=='http://') {
					e.preventDefault();
					Go(href);
				}	
			}
		}
	});
});



