
/***********************************************************************************************************************/

function setupBlogFeed() {
	
	var $ul = $("#blog_feed"); 
	if($ul.size < 1) return; 

	$.ajax({
		type: "GET", 
		url: "/blog/feed/", 
		dataType: "xml", 
		success: function(xml) {
			$(xml).find('item:lt(3)').each(function() {
				var $t = $(this);
				var title = $t.children('title').text();
				var link = $t.children('link').text(); 
				var d = new Date($t.children('pubDate').text()); 
				var datestamp = (d.getMonth()+1) + '/' + d.getDate() + '/' + (d.getFullYear() - 2000); 
				var $li = $("<li></li>").html("<span class='datestamp'>" + datestamp + "</span><a class='pagename' href='" + link + "'>" + title + "</a>"); 
				$ul.append($li); 
			}); 
		}
	}); 
}


function mailerConfirm(ref) {

	var msg = 	"If you are not a current client, please do not send us \n" +
			"any confidential information about legal matters in \n" +
			"which you may be involved. By clicking 'OK', you agree \n" +
			"that any information you send is not a confidence. \n" +
			"Sending an e-mail does not establish an attorney-client \n" +
			"relationship between you and us. ";

	if(confirm(msg)) window.location.href = ref;
}

function mailerConfirmInit() {
	$("#content").find("a[@href^=mailto]").click(function() {
		mailerConfirm($(this).attr('href'));
		return false; 
	}); 
}

function attorneyListSplit() {

	var $ul = $("#body_attorneys.body_profiles #bodycopy ul.nav"); 
	var total = $ul.children("li").size(); 
	var num = Math.ceil(total / 2); 	
	var split = null; 
	var lastLtr = '';

	$ul.children("li").each(function(n) {
		var ltr = $(this).text().substring(0, 1).toUpperCase(); 
		if(ltr == lastLtr) return; 
		var $h = $("<div class='letter'>" + ltr + "</div>")
			.css("font-weight", "bold"); 
		$(this).prev("li").css("margin-bottom", "1em"); 
		$(this).prepend($h); 
		lastLtr = ltr; 
		if(!split && n >= num) split = n; 
	}); 

	var $ul2 = $("<ul class='nav'></ul>")
		.css("position", "absolute")
		.css("top", "39px")
		.css("left", "622px"); 

	$ul2.append($ul.children("li:gt(" + (split-1) + ")")); 
	$ul.after($ul2);
}

/***********************************************************************************************************************/

$(document).ready(function() {

	/*** TOP SEARCH QUERY FIELD ***********************************************************/

	var searchDefaultValue = $("#search_query").val(); 

	$("#search_query").focus(function() {
		$(this).addClass("on");
		if($(this).val() == searchDefaultValue) $(this).val(''); 


	}).blur(function() {
		if(!$(this).val()) $(this).val(searchDefaultValue); 
		if($(this).val() == searchDefaultValue) $(this).removeClass("on"); 
	}); 


	/*** PAGES WITH SPLIT BODYCOPY COLUMN LISTS ******************************************/

	if($("#content.split").size()) {
		$("#content.split #bodycopy ul").each(function() {
			$(this).find("li:odd").addClass("odd"); 
			$(this).find("li:even").addClass("even"); 
		}); 
	}


	/*** GETNAV_PULLDOWN NAVIGATION *******************************************************/

	$("form.getnav_pulldown").each(function() {
		$(this).children("input[@type=submit]").hide(); 

		$(this).children("select").change(function() {
			var url = $(this).children("option:selected").attr("title");
			if(url.length) window.location = url; 	
			return true; 
		});
	}); 

	/*** PRACTICES ************************************************************************/

	if($("#body_practices").size() && !$(".body_all").size()) {
		// prevent 'All Practice Areas' navigation label from being on
		// except for the actual All Practice AReas page
		$("#subnav li.on a[@href$=all/]").removeClass("on"); 
	}


	/*** SPECIFIC TO INTERNET EXPLODER ****************************************************/

	if($.browser.msie) {
		// stop IE7 from causing bodycopy float to move when hover state in navigation
		var n = $("#subnav li").size()-1; // -1 to account for extra <li class='clear'>
		if(n > 1) {
			var height = Math.ceil(n / 2) * 19; 
			$("#subnav").css("height", height + "px"); 
		}
	}

	/*** GENERAL PURPOSE ******************************************************************/	

	$("#secondary_sidebar p:first-child").addClass("first"); 
	
	$("#secondary_sidebar_content .photo_container:empty").parent().addClass("nophoto").end().remove();

	if($("body").is(".body_profiles")) attorneyListSplit();

	mailerConfirmInit();
	setupBlogFeed();

	if($.browser.safari) $("body").addClass("safari"); 

}); 
