/* jQuery */
$(document).ready(function($) {

	// START: Dropdown Account Menu

	var $dropdown = $("#platform_account_dropdown");

	// First tier dropdown
	$dropdown.find('li:first').bind('mouseenter mouseleave',function(event){
	    var $this = $(this),
		$ul = $this.find('ul:first');

		if (event.type === 'mouseenter')
		{
			$.doTimeout('menu_first_level');
			
			// Note: rev 2651 added a check for animation in progress here, but if a slideUp
			//		 is the animation in progress, the menu won't open back up.
			if ($this.hasClass('expanded'))
			{
				return
			}

			$ul.stop(true,true).hide().slideDown(250);
			$this.addClass('expanded');
		}
		
		else
		{
			$.doTimeout('menu_first_level', 500, function(){
				$ul.stop(true, true).slideUp(250);
				$this.removeClass('expanded');
			});
		}
	});

	// Second tier dropdown
	$dropdown.find('ul li').bind('mouseenter mouseleave',function(event){
	    var $this = $(this),
		$ul = $this.find('ul:first'),
		data = $ul.data('dropdown'),
		timeout = 'menu_second_level_' + $this.index();

		// Stops the list from disappearing if reselected
		if (event.type === 'mouseenter')
		{
			if ($this.hasClass('flyout_expanded'))
			{
				$.doTimeout(timeout);
				return
			}
		}
		
		// Had to add check to make sure it exists, otherwise errors are thrown
		if ($ul.length)
		{
		    // Caching the width/height data.  Required to make the animation smooth (and gapless) across browsers.
		    if ( ! data )
		    {
				$ul.data('dropdown',{width:$ul.width(), height:$ul.height()});
				data = $ul.data('dropdown');
		    }

		    if (event.type === 'mouseenter')
		    {
				$this
					.addClass('flyout_expanded')
					.siblings('.flyout_expanded') // Hides sibling lists that might be expanded
					.removeClass('flyout_expanded')
					.find('ul:first')
					.stop(true).hide();

				$ul.css({'width':'0px','height':'7px', 'display': 'block'}).animate({ 'width': data.width },150,function(){
					$ul.animate({'height' : data.height },250);
				});
		    }
		    
		    else
		    {
				$.doTimeout(timeout, 350, function(){
					if ($this.hasClass('flyout_expanded'))
					{
						$this.removeClass('flyout_expanded');
						$ul.stop(true).hide();
					}
				});
		    }
		}
	});

	// END: Dropdown Account Menu
});

// Since global.js isn't called in account - checking to see if doTimeout is available or not.
// Talk with Micheal about a platform global js

if (typeof($.fn.doTimeout !== 'function'))
{
	(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);
}
