$(document).ready(function(){

	// Smooth scrolling
	//Source: http://www.learningjquery.com/2007/09/animated-scrolling-with-jquery-12
	$('.e_body_faq a[href*=#], .e_categoriesList a[href*=#], #tabs .e_tab_try a[href*=#], .toc a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname && $.browser.safari != true) {
		  var $target = $(this.hash);
		  $target = $target.length && $target
		  || $('[name=' + this.hash.slice(1) +']');
		  if ($target.length) {
			var targetOffset = $target.offset().top;
			$('html')
			.animate({scrollTop: targetOffset}, 700, 'swing', function(){  } );
		   return false;
		  }
		}
	});

	// Search box
	$("#searchstring").focus(function() { 
		if ( $(this).val() == "Search") 
		$(this).val("");
		$(this).addClass('e_on');
	});
	$("#searchstring").blur(function() { 
		if ( $(this).val() == "") 
		$(this).val("Search");
		$(this).removeClass('e_on');
	}); 
	

});


function checkSearch() {
	var searchStr = document.forms['searchstringForm'].searchstring.value;
	if (searchStr == "" || searchStr == "Search") { alert('Please enter a search term before proceeding.');  return false; }
	else { return true; }
}










(function($){	
	$(function(){		
		/* ------------------------ */
		/* ----- Services Box ----- */
		/* ------------------------ */
		if($("div.e_leftBar div.e_box.e_services").length){
			if($("div.e_leftBar div.e_box.e_services").length>1||$("div.e_leftBar div.e_box.e_services li.level2.selected").length){
				var serviceCollections = $("div.e_leftBar div.e_box.e_services");
				serviceCollections.each(function(){
					var collection = $(this);
					var selectedItemCollection = $('<ul id="collection-selected" class="selectedchildrenlevel2"></ul>');
					var consumerType="personal";
					if($("body").hasClass("business")||collection.hasClass("e_business")){
						consumerType="business";
					}
					var expandButton = $('<div class="collection-expand_btn" title="Click to see other '+consumerType+' legal services"></div>');
					var isOpen = false;
					collection.append(expandButton).find("#collection").prepend(selectedItemCollection).find("ul.childrenlevel2").hide().find("li.level2.selected").remove().appendTo(selectedItemCollection);
					
					var selectedItemContent = collection.append(expandButton).find("#collection-selected");
					if (!selectedItemContent.html().length) { selectedItemContent.addClass('e_off'); }			
					
					collection.find("div.e_foot").replaceWith(expandButton);
					expandButton.click(function(){
						if(isOpen){
							collection.find("ul.childrenlevel2").slideUp(200,function(){isOpen = false;});
							expandButton.removeClass("open").attr("tooltip","Click to see other "+consumerType+" legal services");
						}else{
							collection.find("ul.childrenlevel2").slideDown(200,function(){isOpen = true;});
							expandButton.addClass("open").attr("tooltip","Click to hide other "+consumerType+" legal services");
						}
					}).bind("mouseenter",function(){expandButton.addClass("hover");}).bind("mouseleave",function(){expandButton.removeClass("hover");});
				});
			}
			$("div.e_leftBar div.e_box.e_services").find("li.level2").filter("!.selected").bind("mouseenter",function(){$(this).addClass("hover");}).bind("mouseleave",function(){$(this).removeClass("hover");});
		}
	});
})(jQuery);
