 
if($.browser.msie && $.browser.version <7)
{
}else
{
    //Cufon.replace('h3', {hover: true} );
	//Cufon.replace('h2, h3, h4, h5');
	//Cufon.replace('fieldset legend');
	//Cufon.replace('#actual-nav li a', {hover: true});
}

function SetMap(){
	if(typeof(map.AddressLookup) == "undefined")
	{
		setTimeout("SetMap()",500);
	}else{
		$("#map-zip").trigger('submit');
	}
}
var map = "";
$(document).ready(function(){//begin doc ready
	//Date range picker
	if($('#date-range').size() > 0)
	{
		$('#date-range').daterangepicker({presets:[]});
		$(".calendar-select").bind('click',function(){	$("#date-range").focus().trigger('click'); return false;});
	}
	//hide/show divs for servies area
	function SimpleSwitcher(ele)
	{
		var switcher = ele.find('.switcher');
		switcher.find("li:first").addClass("active");
		ele.find("div.faded").filter(":not(:first)").hide(); // hide all networks except first
	   switcher.find('li').bind('click',function(){
			var item = this.id;
			item = item.slice(4,20);  // removes "nav-" prefix
			switcher.find("li.active").removeClass("active");
			$(this).addClass("active");
			if(!ele.find('#'+item).is(":visible"))
			{
				ele.find("div.faded").hide();
				ele.find('#'+item).fadeIn("fast");
			}
			return false;
	    })
	}
	
	$("#articles").each(function(){ SimpleSwitcher($(this)); });
	$("#local-deaths").each(function(){ SimpleSwitcher($(this)); });
	
	$('*:contains(" &")').each(function()
	{
	  if($(this).children().length < 1)
	  {
	       $(this).html($(this).text().replace("&",'<span class="amp">&amp;</span>'));
	  }
	});
	
//jMaps stuff
//small maps
	var GetNewResults = function NewResults(latlng)
	{
		var zoom = map.getZoom();
		$.getJSON("assets/scripts/getFuneralHomes.php?lat="+latlng.y+"&lng="+latlng.x+"&zoom="+zoom+"&limit=20",function(data)
		{
			map.ClearMarkers();
			map.UpdateMarkers(data.data);
		});
	};
	if($("#map").length != 0)
	{
		$.getJSON("assets/scripts/getFuneralHomes.php?lat=42.42&lng=-83.02&limit=20",function(data)
		{
			map = $("#map").jMap({
				events: {dragend:GetNewResults},
				traffic:false,
				markers:data.data
			});
		});
	}
//Large map on directors page
	var LargeGetNewResults = function LNewResults(latlng)
	{
		var zoom = map.getZoom();
		$.getJSON("assets/scripts/getFuneralHomes.php?lat="+latlng.y+"&lng="+latlng.x+"&zoom="+zoom+"&lettered=true",function(data)
		{
			map.ClearMarkers();
			map.UpdateMarkers(data.data);
			PopulateBottomBox(data.data);
		});
	};
	if($("#lmap").length != 0)
	{
		$.getJSON("assets/scripts/getFuneralHomes.php?lat=42.40324&lng=-83.0535&lettered=true",function(data)
		{
			map = $("#lmap").jMap({
				events: {dragend:LargeGetNewResults},
				traffic:false,
				markers:data.data
			});
			PopulateBottomBox(data.data);
		});
	}

	function PopulateBottomBox(listing)
	{
		while(listing.length>10){listing.pop();}
		var box = $("#directors-results");
		box.html('');
		$.each(listing,function(){
			box.append("<li><img src='"+this.icon.image+"'>"+this.html+"</li>");
		});
		box.children('li:odd').addClass('even');
	}
//end jmap

	$("#search-category").find('a').bind('click',function()
	{
		$(this).toggleClass('active');
		var input = $(this).next('input');
		if($(this).hasClass('active'))
		{
			input.val('true');
		}else{
			input.val('false');
		}
		return false;
	});
	
	$(".notice-image a").fancybox();
	
	$(".share-email").click(function(){
		$(this).parents('.share-buttons').animate({width:'328px'}).find('.form-fields').fadeIn('slow');
		return false;
	});
	

	
	$('.form-fields').hover(function(){return true;}, function()
	{ 
		$(this).fadeOut('fast').parents('.share-buttons').animate({width:'35px'},'fast',function()
		{
			$(this).attr('style', '');
		}); 
	});
	
	$("#emailform").jValidator({ajax:true});
	$("#newobform").jValidator({ajax:false});
	var GuestBookSubmit = function(data)
	{
		var first = $("#newGB").find('input[name=first]').attr('value');
		var last = $("#newGB").find('input[name=last]').attr('value');
		var message = $("#newGB").find('textarea').attr('value');
		$("#gbfields").fadeIn('slow');
		if(data.success == true)
		{
			$("#gbfields").html(data.response);
			var newEntry = $(".book-entry:first").clone();
			newEntry.find("h4").html(first+" "+last);
			newEntry.find("p").html(message);
			newEntry.insertBefore(".book-entry:first");
			newEntry.fadeIn('slow');
		}else{
			$("#gbfields").append(data.response);
		}
	};
	$("#newGB").jValidator({onSuccess:GuestBookSubmit});
	var NewCenter = function(point)
	{
      gmap.setCenter(point, map.opts.zoom);
		LargeGetNewResults(point);
	};
	
	$("#map-zip").bind("submit",function()
	{
		map.AddressLookup($(this).find('input:first').val()+" mi", NewCenter);
		return false;
	});
	if(typeof($_GET.zip) != "undefined")
	{
		SetMap();
	}
	
	$("#symbol-pikcer").bind("change",function()
	{
		var a = "url(/assets/images/icons/"+$(this).attr('value')+".gif)";
		$("#symbol-preview").css({'background':a});
	});
	
	$("#resultSearch").bind("submit",function()
	{
		var url = $(this).find('input:first').attr('value');
		url = url+"&name="+$(this).find('input[name=name]').attr('value');
		window.location = "results.php?"+url;
		return false;
	});
	
	$("a.close").click(function()
	{
		$(this).parents('div:first').slideUp('fast');
		$.cookie('alertClose',"true",100000000);
	});
	if($.cookie('alertClose') == "true")
	{
		$("a.close").trigger('click');
	}
		
	// tool tips for share buttons
	$('.share-buttons ul li a').tipsy({gravity: $.fn.tipsy.autoNS});
	
	$('.print-button').bind('click',function()
	{
		//print stuff
		var frameName = "printer";
		$("iframe[name=printer]").remove();
		var frame = $( "<iframe name='" + frameName + "'>" );

		frame.css({ 
			"width":"500px",
			"height":"500px",
			"position":"absolute",
			"left":"-9999px"}).appendTo($("body:first")).attr('src',$(this).attr('href'));

		return false;
	});

});//end doc ready

