// JavaScript Document
openPA = false; 
$(document).ready(function() {
	
	//ADD 'LAST' to LI elements for IE
	$('li:last-child').addClass('last');
		
	
	//SLIDE TOGGLE FOR 'WHAT' BOX
	$('.what').toggle(function() {
		closePracticeAreas();
		openP = false;

		$(this).addClass("open").animate({
			width: '700',
	  	left: '240'
			}, 800);
	},
	function() {
		$(this).animate({
			width: '220',
	  	left: '719'
			}, 400, function() {$(this).removeClass("open")});
	});	
	
	//SLIDE TOGGLE FOR 'WHY' BOX
	$('.why').toggle(function() {
		closePracticeAreas();
		openP = false;

		$(this).addClass("open").animate({
			width: '700',
	  	left: '240'
			}, 800);
	},
	function() {
		$(this).removeClass("open").animate({
			width: '220',
	  	left: '240'
			}, 400, function() {$(this).removeClass("open")});
	});
	
	//SLIDE TOGGLE FOR 'CAREERSBOX' BOX
	$('.careersBox').toggle(function() {
		$(this).addClass("open").animate({
			width: '700',
	  	left: '240'
			}, 800);
	},
	function() {
		$(this).removeClass("open").animate({
			width: '220',
	  	left: '240'
			}, 400);
	});
	
	//PRACTICE AREAS POP-UP AND NAV - INDEX BEHAVIOUR
	
	$("body.index .main-nav ul li:nth-child(2) a").attr("id", "practiceAreas");
	
	$('.practice-box').hide();
	
	$('#practiceAreas').attr('href', 'javascript:void');
	
	$('#practiceAreas').click(function() {
		if(openPA == true) {
			window.location = '/practice-areas';
		} else {
			openPA = true;
			$('.practice-box').show();
		}
	});

	$('#practiceAreas').click(function() {
		openP = true;
		$(this).attr('href', '#');
	});
	
	$("html").click(function() {
		closePracticeAreas();
		openP = false;
	});
	
	//PRACTICE AREA DROP DOWNS
	$('ul.drop-down a.trigger').click(function() {
	  
		$(this).parent().children('ul').slideToggle('fast', function() {
    	// Animation complete.
 		});

		$(this).parent().toggleClass("expanded");
		return false;
	});

	//AUTOMATE DROPDOWN
	url = window.location.href;
	if (url.indexOf("#") !=-1) {
		url = url.split('#');
		$("#" + url[1]).addClass("expanded");
		$("#" + url[1]).children('ul').show();
		 $.scrollTo( '#' + url[1], {duration:1000} );
	};

	$('a.collapse-all').removeAttr("href").addClass("expandedClick");
	
	$('a.expand-all').click(function(){
		$(this).removeAttr("href").addClass("expandedClick");
		$("a.collapse-all").attr("href","javascript:void(0)").removeClass("expandedClick");
		$('li.top-level').children('ul').slideDown('fast', function() {
    	// Animation complete.
 		});
		$('li.top-level').addClass("expanded");
		return false;
	});
	
	$('a.collapse-all').click(function(){
		$(this).removeAttr("href").addClass("expandedClick");
		$("a.expand-all").attr("href","javascript:void(0)").removeClass("expandedClick");
	  $('li.top-level').children('ul').slideUp('fast', function() {
    	// Animation complete.
 		});
		$('li.top-level').removeClass("expanded");
		return false;
	});
  
	
	
	//OUR PEOPLE HOVER IMAGE OVERLAY


	$("div.thumb-overlay").hide();

	$("a.name-link").hover(function(){
		
		var picID = $(this).attr("id");
	
		$("div#pic" + picID).show() },
		function () {$("div.thumb-overlay").hide();});
	
	//


	$("input#contact_interests").click(function() {
		$("div#contact_practice_areas").hide();
		$("div#contact_other").hide();
		if($(this).val() == "Other") {$("div#contact_other").show();}
		if($(this).val() == "Contact me about:") {$("div#contact_practice_areas").show();}
	});

//CONTACT INTERACTIVE MAP

	$(".mapHeader .overlay").hide();
	
	$(".mapHeader a.trigger").click(function() {
	
		var clickedID = $(this).attr("id")
		
		$(".mapHeader .overlay").hide();
		$("div#" + clickedID).show();
		return false;
	
	});
	
	$(".mapHeader").click(function() {$(".overlay").hide();});
	
//END DOC READY	
});

var openP = false;

function closePracticeAreas() {
	if(openP == false) {
		openPA = false;
		$('#practiceAreas').attr('href', 'javascript:void');
		$('.practice-box').hide();
	}
}

