$(function() {
	var registry = PHORK.registry,
		$window = $(window)
	;
	
	//remove outline from clicked links and set up external links open a new window
	$('a[rel=external]').attr('target','_blank');
	$('a').click(function() { this.blur(); });
	
	//add the javascript stylesheet
	$('<link>').appendTo('head').attr({
		rel: 'stylesheet',
		type: 'text/css',
		href: registry.constants.baseUrl + '/css/themes/lolla/common/javascript.css'
	});
	
	//add the pre-populated labels to all the labeled inputs
	$('div.labeled').livequery(function() {
		$(this).find('input,textarea').each(function() {
			var $this = $(this),
				$label = $('label[for=' + $this.attr('id') + ']')
			;
			
			$this
				.bind('focus', function() {
					$label.hide();
				})
				.bind('blur', function() {
					if (!$this.val()) {
						$label.show();
					}
				})
			;
			
			if ($this.val()) {
				$label.hide();
			}
			
			$label
				.removeClass('js-hide')
				.bind('click', function() {
					$this.trigger('focus');
				})
			;
		});
	});
});
