

$.fn.equalHeights = function(px) {

	var currentTallest = 0;

	$(this).each(function(){
		
		if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
				
	});
	
	// for ie6, set height since min-height isn't supported
	if ($.browser.msie && $.browser.version == 6.0) { $(this).css({'height': currentTallest}); }
	$(this).css({'min-height': currentTallest}); 
	
	
	return this;
};


$(document).ready(function(){
        
    //quick links on click header dropdown
    $('#qlgo').remove();
    $("select.links").change(function() {
        window.location = $(this).val();
    });
    
    $('div.onelink h3').equalHeights();
    $('div.onelink ul').equalHeights();

    
    //input hover (go buttons)
    $("input.gobutton, image.hover").each(function() {
        var src = $(this).attr("src");
        var hover_src = src.replace(/.gif/,"h.gif");
        $(this).mouseover(function() {
            $(this).attr("src", hover_src);
        });
        $(this).mouseout(function() {
            $(this).attr("src",src);
        });
    });
    
    //open in new window
    $("a[rel='external']").click(function(e) {
        e.preventDefault();
        window.open($(this).attr("href"));
    })
    
    //add hover class to divs
    $("div.onelink").hover(
        function () {
          $(this).removeClass("onelink");
          $(this).addClass("onelink lhover");
        },
        function () {
          $(this).removeClass("onelink lhover");
          $(this).addClass("onelink");
        }
    );
    
    //add link through to divs
    $("div.onelink").mouseup(function() {
        window.location = $("a", this).attr("href");
    });
    
    $('div.third div.featured-content p').equalHeights();
    
    //change class of header form for different css
    $('#headoptions').removeClass("nojs").addClass("gotjs");
    
    //add validation to message form
    $("form#feedbackform").each(function() {
		// keep a reference to the current form in the loop
		var f = $(this);
		// look for the validation summary element in the form
		var container = f.find(".validation-summary");
		// give the validation summary an ID as well (because I couldn't be bothered to type it in the HTML every time)
		container.attr("id", "validation-summary");
		// if the validation summary already has list items generated from server side validation, show it
		// otherwise CSS display:none hides it
		if (container.find("li").length > 1) {
			container.show();
		}
		// apply the validate plugin
		// errorClass is the class applied to the form element on error
		// errorContainer and errorLabelContainer refer to the validation summary
		// wrapper tells it to add a <li> for each error (I could use a <div> or just a <span> etc)
		f.validate({
			errorClass: "invalid",
			errorContainer: container,
			errorLabelContainer: container,
			wrapper: "li"
		});
	});
	
	// Obfuscate reversed emails
	$("#hospice-finder .email strong").each(function()
	{
		var outp = "";
		
		for (i = 0; i <= this.innerHTML.length; i++)
	    	outp = this.innerHTML.charAt (i) + outp;
	  
		this.innerHTML = "<a href='mailto:" + outp + "'>" + outp + "</a>";
	});
    
});
