jQuery(document).ready(function() {
	// attach the hover menu functionality to the topics nav item
	/*jQuery("#nav-global-wrapper li:first a").hover(
		showTopicNavigationAfterDelay,
		hideTopicNavigationAfterDelay
	);
	jQuery("#nav-topics").hover(
		function() {
			clearTimeout(delayedHidingOfTopicNavigation);
		},
		hideTopicNavigationAfterDelay
	);*/
	jQuery("#searchbar").focus(
		function() {
			jQuery(this).addClass("search_term");
			var searchTerm = jQuery(this).val();
			if (!searchTerm || searchTerm != searchLabel) {
				// don't do anything since the user must have entered a search term
			} else {
				// remove the searchLabel
				jQuery(this).val("");
			}
		}
	);
	jQuery("#searchbar").blur(
		function() {
			var searchTerm = jQuery(this).val();
			if (!searchTerm || searchTerm.trim() == "" || searchTerm.trim() == searchLabel) {
				// reset the search box
				jQuery(this).removeClass("search_term");
				jQuery(this).val(searchLabel);
			} else {
				// don't do anything since the user must have entered a search term
			}
		}
	);
	// init the search field (when loading a search result page)
	var searchTerm = jQuery("#searchbar").val();
	if (!searchTerm || searchTerm.trim() == "" || searchTerm.trim() == searchLabel) {
		// reset the search box
		jQuery("#searchbar").removeClass("search_term");
		jQuery("#searchbar").val(searchLabel);
	} else {
		jQuery("#searchbar").addClass("search_term");
	}
});

/* topics navigation *****************************************************************************
var delayedHidingOfTopicNavigation = null;

function showTopicNavigation() {
	clearTimeout(delayedHidingOfTopicNavigation);
	if (jQuery("#nav-topics").hasClass("visible")) {
		// don't do anything
	} else {
		// kill any delayed hiding processes
		jQuery("#nav-topics").addClass("visible");
		jQuery("#nav-topics").slideDown();
	}
}

function hideTopicNavigation() {
	if (jQuery("#nav-topics").hasClass("visible")) {
		jQuery("#nav-topics").removeClass("visible");
		jQuery("#nav-topics").slideUp();
	} else {
		// don't do anything
	}
}

function hideTopicNavigationAfterDelay() {
	clearTimeout(delayedHidingOfTopicNavigation);
	delayedHidingOfTopicNavigation = setTimeout(hideTopicNavigation,300);
}

function showTopicNavigationAfterDelay() {
	clearTimeout(delayedHidingOfTopicNavigation);
	delayedHidingOfTopicNavigation = setTimeout(showTopicNavigation,150);
}
*/
/* noyb stuff *************************************************************************************/
function dcmadr(nnnn) {
    var a = "";
    for(i=0,m=nnnn.length;i < m;i++){
        if(i%3==0){
            a += String.fromCharCode(nnnn.substr(i, 3)-37);
        }
    }
    return a;
}

function dcmt(nnnn) {
    var a = dcmadr(nnnn);
    location.href=('m'+'ail'+'t'+'o:'+a);
}

/* utils ******************************************************************************************/
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
