function initMainMenu()
{
	// initialize the superfish main nav
	$('ul.sf-menu').superfish({
		speed:			150, 
		delay:			150
	}).supposition()
}

function expandableMenus()
{

	// expandable side menus on various pages
	// #practiceList - ul id=practiceList
	// #childrenList

	$('ul.results_list li:has(ul), #childrenList li.withChildren')
		.each(function(){
		thisItem = $(this);

		thisItem.addClass('withChildren');

		thisItem.click(function(event){
			// make sure we clicked on this list item, and not a child of it
			if(this == event.target)
			{
				var item = $(this);

				subItems = item.find('li');

				if( item.hasClass('expanded') )
				{
					item.toggleClass('expanded');
				}
				else
				{
					subItems.hide();
					item.toggleClass('expanded');
					subItems.slideToggle();			
				}
			}
		});
	});
}

function siteSearchLabel()
{
	$('#sitesearch')
	.attr('value', 'Search')
	.focus(function(){
		if(this.value == this.title)
			this.value = '';
	})
	.blur(function(){
		if($.trim(this.value) == '')
		{
			this.value = this.title
			this.addClass('defaultValue');
		}
	});
}

//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//	makes an input have an "inline label"
//	depends on a real label existing (use css to hide the real label)
//
function magicInputLabel( selector )
{
	// they want to have default text for name/keyword fields
	// but we don't want that default text submitted
	$(selector).each(function(){
		this.title = $(this).prev('label[for='+this.id+']')
			.text();

		// if we have no defaultValue, set one
		if( !this.defaultValue )
		{
			this.defaultValue = this.title;
			this.value = this.defaultValue;
			$(this).addClass('defaultValue');
		}
	})

	// add focus listener
	.blur(function(){
		// if the value is empty, set it to the label
		if( !$.trim(this.value) || (this.value == this.title) )
		{
			this.value = this.title;
			$(this).addClass('defaultValue');
		}
	})
	.focus(function(){
		if( this.value == this.title )
		{
			this.value = '';
		}
		$(this).removeClass('defaultValue');
	})
	.parents('form').submit(function() {
		$(selector).each(function(){
			if( this.value == this.title )
				this.value = '';
		});
		return true;
	});
}

//	makes the first item of a select be an "inline label"
//	depends on a real label existing (use css to hide the real label)
//
function magicSelectLabel( selector )
{
	// they want to have default text for name/keyword fields
	// but we don't want that default text submitted
	jQuery(function(){
		$(selector).each(function(){
			this.title = $(this).prev('label[for='+this.id+']')
				.text();
			
			// get the first item and change the text
			var optionLabel = $(this).children('option[value=**]')
			
			optionLabel.text('- '+this.title+' -')
		})		
	});
}

function css3()
{
	// various css3 selectors for the sake of old IEs
	$('#subContent > :first-child, #mainContent > :first-child, #subNav li:first-child')
	.addClass('firstChild')
}

// expand bios in the right hand sidebar
function areaBioExpando()
{
	$('#areaBioList ul li')
	.hide();
	
	$("<li id='bioListExpander'>View Attorneys +</li>")
	.click(function(){
		$(this).remove();
		
		$('#areaBioList ul')
		.hide()
		.children()
		.show();
		
		$('#areaBioList ul')
		.slideDown();
	})
	.appendTo('#areaBioList ul');
}

// animate home case studies
function homeCases()
{
	var animTime = 800;
	var pause = 5000;
	
	var topZ = 3000;
	var bottomZ = 1000;
	
	$('.homeCaseItem:first')
	.css({zIndex: topZ})
	.fadeTo(animTime, 1)
	.delay(pause)
	.fadeTo(animTime, 0, function(){
		$(this)
		.css({zIndex: bottomZ})
		.appendTo($('#homeCases'))
		
		homeCases()
	});
}

jQuery(function(){
	initMainMenu();
	expandableMenus();
	siteSearchLabel();
	
	magicInputLabel('.search_form input');
	magicSelectLabel('.search_form select');
	
	css3();
	
	$('.homeCaseItem').css({opacity: 0});
	homeCases();
	
	areaBioExpando();
	
	Cufon.replace('#pageTitle'); // Works without a selector engine
	Cufon.now();
});

// adds a body class ".loaded" once the dom is ready to go
// useful for UDM and other things
$(window).load(function(){ $('body').addClass('loaded') });
