
(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.RotateGallery = function()
{

	$("div#gallery div.widgetnav span.tabnav").tabs("div#gallery > div.panel", {

		// enable "cross-fading" effect
		effect: 'fade',
		fadeOutSpeed: "slow",

		// start from the beginning after the last tab
		rotate: true

		// use the slideshow plugin. It accepts its own configuration
	}).slideshow({ autoplay: true, interval: 7000 });

	//$("div#gallery div.widgetnav a").click(function() { $("div#gallery div.widgetnav span.tabnav").tabs().stop(); alert('stop!'); });

};

$.fn.IndexTabs = function()
{

	$("div#indexes div.indextabs").tabs("div#indexes div.panels > div.panel", {


})

};


$.fn.PulldownLinks = function()
{


	var trigger = $("div#indexes div.pulldownlinks dl dt a.trigger");

	var target = $("div#indexes div.pulldownlinks dl");

	trigger.click(function()
	{

		target.toggleClass('activated');

		return false;

	});


};

})(jQuery);

// construct on dom ready
$(function()
{
	$(".change-location").FlyoutNav();
//	$("#mainnav > li").FlyoutNav();
	$("#mainnav > li").not('#mnav_Solutions').not('#mnav_Research').FlyoutNav();
	$("#mainnav_alt > li").FlyoutNav();
	$('#gallery').RotateGallery();
	$('#indexes').IndexTabs();
	$('#indexes').PulldownLinks();
});
