var thumbCount = 0;
var timer;

function delayHide() {
	timer = setTimeout('hideAll()', 100);
}
function hideAll(id) {
	cancelHide();
    $(".meetourteam_pop, .calendar_pop,  not('#'+id)").hide();
	//$("#map_image").attr("src", "/resourcecenter/common/images/map/map.gif");
}
function cancelHide() {
	if (window.timer) clearTimeout(timer);
}

function hide() {
	if(mapstate) {
		mapstate.hide();
		mapstate = null;
	}
}
function show(id) {
	var obj = id.split('_pop');
	if ('meetourteam' == obj[0]) {
   		hideAll(id);
		$("#"+id).css("top", $("#thumb"+obj[1]).offset().top-300);
		$("#"+id).css("left", $("#thumb"+obj[1]).offset().left-310);	
	} else if ('calendar' == obj[0]) {
   		hideAll(id);
		$("#"+id).css("top", $("#calendar_link"+obj[1]).offset().top - $("#"+id).height());
		$("#"+id).css("left", $("#calendar_link"+obj[1]).offset().left-36);	
	} else if ('map' == obj[0]) {
		hide();
		mapstate = $('#'+id);
		$("#"+id).css("top", _mapOffset.top + mapCoords[obj[1]][1] - parseInt($("#"+id).height()/2),10);
		$("#"+id).css("left", _mapOffset.left + mapCoords[obj[1]][0] - 40);
		//$("#map_image").attr("src", "/resourcecenter/common/images/map/map-" + ndx + ".gif");
	}
	
	$("#"+id).show();
}


function isDefined(property) {
  return (typeof property != 'undefined');
}

var _mapOffset = {};
var mapstate;
$( function() 
{
	var left = 0;
	if (isDefined($("#slider").css("left"))) {
		left = $("#slider").css("left");
		left = parseInt(left.substring(0, left.length - 2));
	}
	
	_mapOffset = $("#map").offset();
	
	$("#left_arrow").click(
		function() { 
			if (left < 0) {
				left = left + 64;
				$("#slider").animate({"left": "+=64px"}, 300);
				$(".meetourteam_pop").each(
					function() {
						var px = parseInt($(this).css("left").substring(0, $(this).css("left").length - 2));
						$(this).css("left", px + 64);
					});				
				
			}		
		});
	
	$("#right_arrow").click(
		function() { 
			//we show 3 attorneys so don't scroll past the total - 3
			if (left > ((thumbCount -3) * -64)) { 
				left = left - 64;
				$("#slider").animate({"left": "-=64px"}, 300);
				$(".meetourteam_pop").each(
					function() {
						var px = parseInt($(this).css("left").substring(0, $(this).css("left").length - 2));
						$(this).css("left", px - 64);
					});
			}			
		});	

	/* popup event handlers */
	$(".thumb").each(
		function() {
			var ndx = $(this).attr("id").substr($(this).attr("class").length);
			$(this).mouseover (function() {show("meetourteam_pop"+ndx);});
			$(this).mouseout (function() {delayHide();});
		});
	$(".calendar_link").each(
		function() {
			var ndx = $(this).attr("id").substr($(this).attr("id").length - 8);	
			$(this).mouseover (function() {show("calendar_pop"+ndx);});
			$(this).mouseout (function() {delayHide();});
		});
	$(".statelink").each(
		function() {
			var state = $(this).attr("id");	
			$(this).mouseover (function() {show("map_pop"+state);});
			$(this).mouseout (function() {delayHide();});
		});

	$(".meetourteam_pop, .calendar_pop").mouseover(function() {cancelHide();});
	$(".meetourteam_pop, .calendar_pop").mouseout(function() {delayHide();});	
	/* popup event handlers */
});

var mapCoords = new Array();
mapCoords["al"] = new Array(55, 212);
mapCoords["ak"] = new Array(203, 233);
mapCoords["az"] = new Array(195, 176);
mapCoords["ar"] = new Array(367, 189);
mapCoords["ca"] = new Array(156, 143);
mapCoords["co"] = new Array(261, 135);
mapCoords["ct"] = new Array(158, 115);
mapCoords["dc"] = new Array(151, 141);
mapCoords["de"] = new Array(135, 115);
mapCoords["fl"] = new Array(73, 252);
mapCoords["ga"] = new Array(88, 207);
mapCoords["hi"] = new Array(146, 230);
mapCoords["id"] = new Array(188, 125);
mapCoords["il"] = new Array(33, 152);
mapCoords["in"] = new Array(55, 146);
mapCoords["ia"] = new Array(360, 115);
mapCoords["ks"] = new Array(333, 141);
mapCoords["ky"] = new Array(41, 167);
mapCoords["la"] = new Array(383, 214);
mapCoords["me"] = new Array(170, 117);
mapCoords["md"] = new Array(125, 127);
mapCoords["ma"] = new Array(155, 115);
mapCoords["mi"] = new Array(71, 163);
mapCoords["mn"] = new Array(352, 115);
mapCoords["ms"] = new Array(30, 220);
mapCoords["mo"] = new Array(363, 142);
mapCoords["mt"] = new Array(244, 117);
mapCoords["ne"] = new Array(331, 115);
mapCoords["nv"] = new Array(167, 120);
mapCoords["nh"] = new Array(160, 115);
mapCoords["nj"] = new Array(156, 117);
mapCoords["nm"] = new Array(265, 182);
mapCoords["ny"] = new Array(127, 110);
mapCoords["nc"] = new Array(90, 170);
mapCoords["nd"] = new Array(323, 117);
mapCoords["oh"] = new Array(82, 140);
mapCoords["ok"] = new Array(344, 194);
mapCoords["or"] = new Array(150, 132);
mapCoords["pa"] = new Array(105, 115);
mapCoords["ri"] = new Array(174, 115);
mapCoords["sc"] = new Array(103, 192);
mapCoords["sd"] = new Array(323, 115);
mapCoords["tn"] = new Array(35, 187);
mapCoords["tx"] = new Array(344, 207);
mapCoords["ut"] = new Array(205, 131);
mapCoords["vt"] = new Array(145, 115);
mapCoords["va"] = new Array(99, 145);
mapCoords["wa"] = new Array(155, 117);
mapCoords["wv"] = new Array(99, 140);
mapCoords["wi"] = new Array(20, 110);
mapCoords["wy"] = new Array(250, 115);