$(document).ready(function(){

/* ---------------------- MAIN NAV DROPDOWNS ------------------------------ */

$('li#nav_practice-areas').hoverIntent(function(){
	$('ul#subnav-practice').stop().slideToggle("fast");
},function(){
	$('ul#subnav-practice').stop().slideToggle("fast");
});


$('li#nav_our-firm').hoverIntent(function(){
	$('ul#subnav-firm').stop().slideToggle("fast");
},function(){
	$('ul#subnav-firm').stop().slideToggle("fast");
});

$('li#navpracticearea').hover(function(){
	$('ul#practiceareas').toggle();
});


/* ---------------------- GOOGLE MAPS ------------------------------ */

	$("input.map_info").each(function() {
		var arrAddressData = $(this).val().split("_");
		var AddressName = arrAddressData[0];
		var Latitude = arrAddressData[1];
		var Longitude = arrAddressData[2];
		MakeMap("map_canvas_" + AddressName, Latitude, Longitude);
	});

	$("a#contactbutton").click(function(){
		var ContactAddress = $(this).attr("href");
		window.open(ContactAddress,'mywindow','width=420,height=420,screenX=350,screenY=150');
		return false;
	});
	
/* ---------------------- EMAIL PAGE ------------------------------ */
	
	$("img#emailpage").click(function(){
		mail_str = "mailto:?subject=Check out " + $("h1").text() + " at McCarthy Fingar.";
		mail_str += "&body=I thought you might be interested in " + $("h1").text() + ".";
		mail_str += "Go to: " + location.href;
		location.href = mail_str;
	});
	
/* ---------------------- PRINT PAGE ------------------------------ */

	$("img#printpage").click(function(){
		window.print();
	});


/* ---------------------- EXTERNAL LINKS  ------------------------------ */

/*

	$('a').filter(function() {
	    return this.hostname && this.hostname !== location.hostname;
	}).addClass("external");

*/
	
/* ---------------------- HEADER IMAGE GENERATOR  ------------------------------ */
	
	$.get("images/header/pictures.aspx?set=" + escape($("div#imgholder").html()),"", function(data){
	
		var strImages = '<img src="images/header/' + data.img1 + '.jpg" />' + 
						'<img src="images/header/' + data.img2 + '.jpg" />' + 
						'<img src="images/header/' + data.img3 + '.jpg" />' + 
						'<img src="images/header/' + data.img4 + '.jpg" />' + 
						'<img src="images/header/' + data.img5 + '.jpg" />';
		$("div#imgholder").html(strImages);
		
		$("div#featureimgreplace").html('<img src="images/contentbig/' + data.img3 + '.jpg" />');
		
	},"json")


	
	
});


/* ---------------------- FUNCTIONS ------------------------------ */


function MakeMap(ElementID,Latitude,Longitude) 
{
	var map = new GMap2(document.getElementById(ElementID));

	map.setCenter(new GLatLng(Latitude, Longitude), 15);
	map.setUIToDefault();
	
	var point = new GLatLng(Latitude, Longitude);
    map.addOverlay(new GMarker(point));

}
