$.fn.newWindow = function() 
{
	$('a').each(function() 
	{
		if ( ! this.href) return;

		if (this.href.indexOf(hostname) == -1 && this.href.search('mailto:') == -1 && $(this).attr('rel').indexOf('lightbox') == -1) 
		{
			var title = $(this).attr('title');
			$(this).addClass('external');
			$(this).attr('title', title + ' [Opens in new tab/window]');
		}
	});
	
	$(document).delegate('a.external', 'click', function() 
	{
		window.open(this.href);	        
		return false;
	});

	return this;
};

$.fn.greatestHeight = function () 
{
	var gheight = 0;
	
	this.each(function ()
	{
		var h = $(this).innerHeight();	
		
		if (h > gheight) 
		{ 
			gheight = h;
		}
	});
	
	this.height($(gheight).toEm());			
	
	return this;
};

$.fn.responser = function()
{
	this.css({opacity: 0.9}).hide().delay(100).slideDown(400).delay(2000).fadeOut(1200);
	
	return this;
}

/*-------------------------------------------------------------------- 
 * jQuery plugins: toEm() and toPx()
 * by Scott Jehl (scott@filamentgroup.com), http://www.filamentgroup.com
 * Copyright (c) Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 * Article: http://www.filamentgroup.com/lab/update_jquery_plugin_for_retaining_scalable_interfaces_with_pixel_to_em_con/
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping		  
 * Usage Example: $(myPixelValue).toEm(); or $(myEmValue).toPx();
--------------------------------------------------------------------*/

$.fn.toEm = function(settings){
	settings = jQuery.extend({
		scope: 'body'
	}, settings);
	var that = parseInt(this[0],10);
	var scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;">&nbsp;</div>').appendTo(settings.scope);
	var scopeVal = scopeTest.height();
	scopeTest.remove();
	return (that / scopeVal).toFixed(8) + 'em';
};


$.fn.toPx = function(settings){
	settings = jQuery.extend({
		scope: 'body'
	}, settings);
	var that = parseFloat(this[0]);
	var scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;">&nbsp;</div>').appendTo(settings.scope);
	var scopeVal = scopeTest.height();
	scopeTest.remove();
	return Math.round(that * scopeVal) + 'px';
};

var log = function(log_text) 
{
	if(window.console) console.log(log_text);
};

var hostname = location.hostname;

$(document).ready(function() 
{
	if(hostname.indexOf('www.') === 0) hostname = hostname.replace('www.', '');
	
	$(document).newWindow();
	
	$('#response').responser();
});
