

(function()
{

	$.fn.FlyoutNav = function(options)
	{

		// Saving scope of this
		$this = this;

		// Defaults
		var defaults = {
	};

	var options = $.extend(defaults, options);

	function init()
	{
		attachEvents();
	}

	function attachEvents()
	{
		var timer;

		$this.mouseenter(function()
		{
			var el = $(this);
			$(this).children("a.mnav-lnk").addClass("hover")
			timer = setTimeout(function()
			{
				el.children("div.flyout").show(200);
			}, 100);
		});

		$this.mouseleave(function()
		{
			$(this).children("ul").stop();
			clearTimeout(timer);
			$(this).children("a.mnav-lnk").removeClass("hover")
			$(this).children("div.flyout").hide(100);
		});

		// remove event listeners when user leaves the page for memory efficiency
		$(window).unload(function()
		{
			removeEvents();
		});
	}

	// remove event listeners if need be
	function removeEvents()
	{
		$this.unbind("mouseenter")
		$this.unbind("mouseleave");
	}

	// loop through all selectors and initialize
	return this.each(function(i)
	{
		init();
	});
};




$.fn.StartNewsTicker = function(){
    this.each(function(){
        var ticker = $(this);
        var delayInput = ticker.find("input[name=delay]");
        var delay = (delayInput.get(0) ? 1000 * delayInput.val() : 5000);
        var ticker = $(this);
        ticker.find(".ContentItem:first").show();
        function scrollTicker(){
            ticker.find(".ContentItem:first")
                .fadeOut('slow', function() {
                    var p = $(this).parent();
                    $(this).hide().remove();
                    p.append(this);
                    p.find(".ContentItem:first").fadeIn('slow');
                });
        }
        setInterval(scrollTicker, delay);
    });
};

})(jQuery);

$(function()
{
	$("#mainnav > li").FlyoutNav();
	$("#mainnav_alt > li").FlyoutNav();
	$('.newsticker').StartNewsTicker();
	$(".cli").FlyoutNav();
});



$(document).ready(function() {

// Watermarks
	watermark(jQuery('#searchInput'), 'Search');

	});
	
	function watermark(obj, text) {
	    // set the watermark text
	    jQuery(obj).val(text);
	    
	    // clear on focus
	    jQuery(obj).focus(function() {
	        if (jQuery(obj).val() == text) {
	            jQuery(obj).val('');
	        }
	    });
	    
	    // restore on blur
	    jQuery(obj).blur(function() {
	        if (jQuery(obj).val() == '') {
	            jQuery(obj).val(text);
	        }
	    });
	}
	
