$(document).ready(function() {
						   
	
	// Clear & Refill fields
	autoFill($("#email"), "Your email address");
	autoFill($("#name"), "Your name");
	autoFill($(".e2ma_signup_form_element input:eq(0)"), "your first name");
	autoFill($(".e2ma_signup_form_element input:eq(1)"), "your last name");
	autoFill($(".e2ma_signup_form_element input:eq(2)"), "your email (required)");
	
	
	

	function autoFill(id, v){
		$(id).css({ color: "#666" }).attr({ value: v }).focus(function(){
			if($(this).val()==v){
				$(this).val("").css({ color: "#000" });
			}
		}).blur(function(){
			if($(this).val()==""){
				$(this).css({ color: "#666" }).val(v);
			}
		});
	}
	
	
	
	// PRODUCT PAGIN - IMAGE PREVIEW
	$(".product-swatches li:eq(0)").addClass("on");
	
	// If click a swatch, show the correlating preview image
	 $(".product-swatches li").click(function () {
											   
		 
		// put the index # of the li that was just clicked into a variable
		var indexnum = $(".product-swatches li").index(this);
		
		
		// hide all the preview images and outlines around the swatches
		$(".product-preview dt").hide();
		$(".product-preview dd").hide();
		$(".product-swatches li").removeClass("on"); 
		
		
		// show the coorelating preview image and swatch outline 
		// (it matches the same order as the swatch)
		$(".product-preview dt:eq(" + indexnum + ")").show();
		$(".product-preview dd:eq(" + indexnum + ")").show();
		$(this).addClass("on");
	
	});
	
	
	
	
	
	
	
	
	$("#map a").css("color","");
	$("#map a").attr('rel','external');
	$("#map-outside-chicago a").css("color","");
	$("#map-outside-chicago a").attr('rel','external');



	
	
	
	// Swapping maps
	$(".inside-chicago dt").click(function () {
											   
		var mapID = $(this).attr("id");	
		var url = "/inc/maps.php div#" + mapID;

		$("#map").load(url,function() {
			$("#map a").css("color","");
			$("#map a").attr('rel','external');
			externalLinks();
		});
					   
	});
	
	
	
	
	
		// Swapping maps
	$(".outside-chicago dt").click(function () {
		
		var mapID = $(this).attr("id");	
		var url = "/inc/maps.php div#" + mapID;
		
		$("#map-outside-chicago").load(url,function() {
			$("#map-outside-chicago a").css("color","");
			$("#map-outside-chicago a").attr('rel','external');
			externalLinks();
		});
					   
	});
	
	
	
	
	
	
	// Email signup
	$("#e2ma_signup_submit_button").val("SIGN UP!");			   
	

	
	
	
	

});



function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;



// Left Column //





