﻿
(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,

 

  // start on a random slide

  initialIndex: Math.floor(Math.random()*$("div#gallery > div.panel").length)

 

  // 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();
});

var _qs;
	function parseQuerystring()
	{
		_qs = new Object();
		if (location.search && location.search.length > 1)
		{
			var srch = location.search.substring(1).split('&');
			for (var i = 0; i < srch.length; i++)
			{
				var pr = srch[i].split('=');
				if (pr.length >= 2 && pr[0].length > 0)
				{
					_qs[pr[0]] = pr[1];
				}
			}
		}
	}

function GetQuerystring(key)
	{
		if (!_qs) parseQuerystring();
		return _qs[key];
	}