$(document).ready(function() {
	
	/**
	 * Task Selector
	 * Shown via quick-links. Uses timeout to allow a grace period when the user's mouse has
	 * left the task selector.
	 */
	var t; // timer for hiding
	var tasks = $('#tasks');
	
	var speed = 800; // slide speed
	var timeout = 300; // grace period before hiding tasks
	
	$('#quick-links a').stop().mouseover(function() {
		$(this).parent().animate({
			top: '-20px'
		}, {
			duration: 200
			, complete: function() {
				tasks.slideDown({
					duration: speed,
					easing: 'easeOutQuint'
				});
			}
		});
	});
	
	tasks.hover(function() { 
		clearTimeout(t);
	}, function() {
		t = setTimeout(function() {
			tasks.slideUp({
				duration: speed
				, easing: 'easeOutQuint'
				, complete: function() {
					$('#quick-links').animate({
						top: '0px'
					}, {
						duration: 200
					});
				}
			});
		}, timeout);
	});
	
});

/**
 * Retrieve URL parameters from the current window location, or a passed string
 * Usage: $.getUrlVar('pid'), $.getUrlVars(), $.getUrlVar('news', dom_item.href)
 */
$.extend({
	getUrlVars: function(source) {
		if (!source) source = window.location.href;
		
		var vars = [], hash;
		var hashes = source.slice(source.indexOf('?') + 1).split('&');
		
		for (var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		
		return vars;
	},
	getUrlVar: function(name, source){
		return $.getUrlVars(source)[name];
	}
});