jQuery.fn.labelOver = function(overClass) {
	return this.each(function(){
		var label = jQuery(this);
		var f = label.attr('for');
		if (!f) return;
		var input = jQuery('#' + f);
		
		this.hide = function() {
			label.hide();
			//label.css({ color: #ffffff })
		}
		
		this.show = function() {
			if (input.val() == '') label.show();
			//if (input.val() == '') label.css({ textIndent: 0 })
		}

		// handlers
		input.focus(this.hide);
		input.blur(this.show);
		label.addClass(overClass).click(function() {
			input.focus();
		});
		if (input.val() != '') this.hide(); 
	})
}

jQuery.url = function(name) {
	return ((new RegExp("[\\?&]" + name + "=([^&#]*)")).exec(window.location.href) || [null,null])[1];
}

$(document).ready(function() {

    $("#global_keywords").autocomplete("/text/querycompletion", { delay:200 });

    $('#user-nav *').tooltip({
        track: true,
        delay: 1,
        showURL: false,
        showBody: " - ",
        fade: 250
    });

    $('#site-nav *').tooltip({
        track: true,
        delay: 1,
        showURL: false,
        showBody: " - ",
        fade: 250
    });

    $('#scroller').cycle({
        fx: 'fade',
        speed: 1000,
        sync: 1,
        fit: 1,
        pause: 1,
        timeout: 4000,
        cleartype: 1
    });

	$('div#sidebar').filter('.right').css({
		marginRight: 15
		,width: 170
	});
	$('a[rel="external"]').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	$('.label-over label').labelOver('over-apply');
	
	// This is for the paging next/previous links
	$("div#paging span.previous").hover(
		function () {
			$(this).css({color:"#000000", cursor:"pointer"});
		},
		function () {
			$(this).css({color:"#07658E", color:"#1F638A"});
		});
	
	$("div#paging span.next").hover(
		function () {
			$(this).css({color:"#000000", cursor:"pointer"});
		},
		function () {
			$(this).css({color:"#07658E", color:"#1F638A"});
		});
});
