/* ####################################################################
#   (c)2010 Elysian Community Management, LLC - All rights reserved   #
#                                                                     #
#   This file and its contents are protected under U.S. copyright     #
#   law. Any unauthorized alteration, distribution, or reproduction   #
#   will be prosecuted to the maximum possible extent of the law.     #
#                                                                     #
#                          www.ElysianCM.com                          #
#################################################################### */

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};


/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
* $("ul li").hoverIntent( showNav , hideNav );
* 
* // advanced usage receives configuration object only
* $("ul li").hoverIntent({
*	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
*	interval: 100,   // number = milliseconds of polling interval
*	over: showNav,  // function = onMouseOver callback (required)
*	timeout: 0,   // number = milliseconds delay before onMouseOut function call
*	out: hideNav    // function = onMouseOut callback (required)
* });
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($) { $.fn.hoverIntent = function(f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function(ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } }; var delay = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function(e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function() { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);


//////////////////////////////////////////////////////
// Menu Bar Extension
//
$.fn.menusystem = function (settings)
{
	var defaults	= {
		speed:			"fast",
		effect:			"slide"		// Options, currently are "fade" and "slide"
	},
	options		= $.extend(defaults, settings),

	// list of possible effects
	effects		= {
		fade:		{
			over:	"fadeIn",
			out:	"fadeOut"
		},
		slide:		{
			over:	"slideDown",
			out:	"slideUp"
		}
	};

	// attach the menusystem to each nominated input element
	return this.each(function () {
		
		var hoverOver	= function () {
			$("ul:first", this)[effects[options.effect].over](options.speed);
		},
		hoverOut	= function () {
			$("ul:first", this)[effects[options.effect].out](options.speed);
		},
		hoverConfig = {
			interval: 50,
			over: hoverOver,   
			timeout: 50,
			out: hoverOut    
		};

		// set classes on sub menus
		$("li:has(ul)", this).addClass("subMenuSystem");

		// Bind the actions
		$("li.subMenuSystem", this).hoverIntent(hoverConfig);
		$("ul", this).hide();
	});
};



//////////////////////////////////////////////////////
// Text-replace Extension
//
$.fn.textReplace = function (settings)
{
	var defaults	= {
		url:			"",
		fadeIn:			false
	},
	options		= $.extend(defaults, settings);

	// convert each string to its equivalent image
	return this.each(function () {
		
		var alt	= $(this).text();
		var tag	= "<img src='" + options.url + "' alt='" + alt + "' />";
			
		$(this).empty().append(tag);		
	});
};


$(document).ready(function() {
	$("#panelMain").equalHeights();
	$("#navigationHead").menusystem();
	$(".headingMainSellTitle").textReplace({url: "../images/ElysianText.gif"});
});


function navigateCommunity()
{
	var comm = $("#selectCommunity").val();
	if (comm === "")
	{
		alert("Please select a community to view from the drop down.");
		$("#selectCommunity").focus();
		return false;
	}
	else
	{
		window.location = "http://" + comm + ".loveyourhoa.com";
	}
}

