$(document).ready(function(){

	/* tooltips */

	$('.tooltip').qtip({
		position: {
			target: 'mouse',
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomLeft'
			},
			adjust: {
				screen: true
			}
		},
		style: { 
			name: 'blue',
			tip: 'bottomLeft',
      	width: {
				max: 250
			},
      	padding: 15
		},
		show: {
			delay: 0
		}
	})

	/* search field
	   clear on focus, replace with default on blur
	*/

	$.fn.search = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
	$("#searchfield").search();


	/* external links
	   based on: http://www.learningjquery.com/2008/08/quick-tip-dynamically-add-an-icon-for-external-links
	*/

	$('a').filter(function() {
		return this.hostname && (this.hostname).split(":")[0] !== (location.hostname).split(":")[0];
	})
	.not(':has(img, div, mailto)')
	.addClass('external')
	.click(function() {
		window.open(this.href);
		return false;
	});


});
