$(document).ready(function() {
	
	var hoverconfig = {    
	     over: show_description, // function = onMouseOver callback (REQUIRED)    
	     interval: 500, // number = milliseconds delay before onMouseOut    
	     out: hide_description // function = onMouseOut callback (REQUIRED)    
	};
	
		
		// equal heights
		$.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);
				});
			}
			
		// init_functions
		add_classes();
		adjust_columns();
		
		$("#lib-description-box").hide();
		
		$("#library-pictures ul li").hoverIntent(hoverconfig);
		
		$("#library-pictures").mouseout(function() {
			$("#lib-description-box").fadeOut(200);
		});
		
		init_summaries();
		
		linkNewWindow();
		
  
		
});

function add_classes() {
	$(".subcolumns .column:odd").addClass('last');
	$(".column ul li:last-child").addClass('last');
	}

function adjust_columns() {
	$(".equalize").equalHeights();
	}
	
function show_description() {
	$("#lib-description-box").fadeOut(200);
	var description = $(this).find("p").text();
	$("#lib-description-box").empty();
	$('<p>' + description + '</p>').prependTo("#lib-description-box");
	$("#lib-description-box").fadeIn(500).delay(2000).fadeOut(200);
}

function hide_description() {
	return false;
}


function init_summaries() {
	$("#help-diagram li").hoverIntent(fading, doNothing);
	}

function fading(){
	var $this = $(this);
	def = $this.find(".hm-def");
	hov = $this.find(".hm-hov");
	$(def).fadeOut(150);
	$(hov).delay(150).fadeIn(300);
	$this.parent().addClass("active");
}
	
function doNothing(){
	var $this = $(this);
	def = $this.find(".hm-def");
	hov = $this.find(".hm-hov");
	$(hov).fadeOut(150);
	$(def).delay(150).fadeIn(300);
	$this.parent().removeClass("active");
	}

function linkNewWindow(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");	
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;				
	};
	this.set = function(obj){
		obj.target = "_blank";
		obj.className = obj.className + " external";
	};	
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};		
};
