var hide_pop_out_box = true;
var default_search_text = 'Enter Keywords or Bible Verse';

$(document).ready(function(){

	/* Pop-out box controls */
	/*
	$(".popOut").css("display","none");
	
	$(".popOutMenu[rel]").hover(
		function () {
			// Hide all before displaying this one
			$(".popOut").css("display","none");
			hide_pop_out_box = false;
			var offset = $(this).offset();
			$("#" + $(this).attr("rel")).css({display:"block",position:"absolute",left:(offset.left+173)+"px",top:offset.top+"px"});
		},
		function () {
			hide_pop_out_box = true;
		}
	);

	$(".popOut").hover(
		function () {
			hide_pop_out_box = false;
		},
		function () {
			hide_pop_out_box = true;
		}
	);
	*/
	
	/* Pop-out Letter Menu */
	/*
	$("a[rel].letterNav").click(function () {
		$("a[rel="+$(this).attr("rel")+"].letterNav").removeClass('active');
		//$("a#"+$(this).attr("id")).toggleClass('tabLoading');
		
		$("#"+$(this).attr("rel")).load('get_categories.php?i='+$(this).attr("id"));
		//$("a[rel="+$(this).attr("rel")+"].ajaxTabs").removeClass('tabLoading');
		
		$(this).toggleClass('active');
		
		return false;
	});

	
	PopOutBox();
	*/
	
	/* Search Box */
	if( $("#searchField").val() == '' )
	{
		$("#searchField").val(default_search_text);
	}
	
	$("#searchField").focus(function () {
		if( $(this).val() == default_search_text )
		{
			$(this).val('');
		}
	});
	$("#searchField").blur(function () {
		if( $(this).val() == '' )
		{
			$(this).val(default_search_text);
		}
	});
	
	/* Auto Completer */
	$("#searchField").autocomplete('autocomplete.php', { onItemSelect:selectItem } );
	
	$('.viewMoreCatsLink').click(
		function()
		{
			var hidden = $('.hiddenCategories:hidden');
			if(hidden.length > 0)
			{
				hidden.animate({ opacity: 'show', height: 'show' }, 'fast');
				$('.viewMoreCatsLink').text('[ View Less ]');
			}
			else
			{
				var visible = $('.hiddenCategories:visible');
				if(visible.length > 0)
				{
					visible.animate({ opacity: 'hide', height: 'hide' }, 'fast');
					$('.viewMoreCatsLink').text('[ View More ]');
				}
			}
		}
	);
	
	// Submit form once an item is selected
	function selectItem(li)
	{
		document.headerSearch.submit();
	}
	
	jQuery('a.letterNav').click(
		function()
		{
			if(!jQuery(this).hasClass('letterNavSelected'))
			{
				var theAnchor = jQuery(this).attr('href').replace(/\#/,'');
				if(theAnchor != '' && theAnchor != 'undefined')
				{
					jQuery('a.letterNav.letterNavSelected').removeClass('letterNavSelected');
					jQuery('a#letterNav'+theAnchor).addClass('letterNavSelected');
				}
			}
			return true;
		}
	);
	
	if(jQuery('a.letterNav').length > 0)
	{
		if(window.location.hash && window.location.hash.replace(/\#/,'') != '')
		{
			var theAnchor = window.location.hash.replace(/\#/,'');
			jQuery('a#letterNav'+theAnchor).addClass('letterNavSelected');
		}
	}
});

// Keep the pop-out box hidden or shown
/*
function PopOutBox()
{
	if( hide_pop_out_box == true )
	{
		$(".popOut").css("display","none");
	}
	
	setTimeout('PopOutBox()', 1000);
}
*/

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

