 /*
 * [ 0.2 ] Original by Jonathan Howard
 * [ 0.3 ] Updated for current jQuery releases,
 *         and formatted for jQuery namespace by Charles Phillips
 *         <charles@doublerebel.com>
 *
 * jQuery Pause
 * version 0.3
 *
 * Requires: jQuery 1.2 (I think that's when jQuery updated the queue method)
 *
 * Feel free to do whatever you'd like with this, just please give credit where
 * credit is due.
 *
 *
 *
 * pause() will hold everything in the queue for a given number of milliseconds,
 * or 1000 milliseconds if none is given.
 *
 *
 *
 * unpause() will clear the queue of everything of a given type, or 'fx' if no
 * type is given.
 */

(function($) {
	$.fn.extend({
		pause: function(milli,type) {
			milli = milli || 1000;
			type = type || "fx";
			return this.queue(type,function(){
				var self = this;
				setTimeout(function(){
					$(self).dequeue();
				},milli);
			});
		},
		clearQueue: function(type) {
			return this.each(function(){
				type = type || "fx";
				if(this.queue && this.queue[type]) {
					this.queue[type].length = 0;
				}
			});
		},
		unpause: $.fn.clearQueue
	});
})(jQuery);



(function($){
	$.fn.navigation = function(o)
	{
		return this.each(function(){
			new $nav(this,o);
		});
	};
	
	$.navigation = function(e,o)
	{	
		var n = $(e);
		var mainNav = n.find('ul li').not('ul li li')
		
		n.find('ul').eq(0).addClass("jsEnabled");
		
		// console.log($('#nav ul').not('div.sub-nav li').outerHeight());
		// 		n.find('.sub-nav .container').height()
		

		
		n.hover(
			function () {
				n.focus();
			}, 
			function () {
				n.blur()
			}
		);
		
		
				
		n.bind("blur", function() {
		    $(e).find('li').removeClass('active');
			$('.blackOut').fadeTo("fast", 0, function(){
				$('.blackOut').remove()
			})
				
		});
		
		n.bind("focus", function() {
			
		});
				
		mainNav.each(function(){
			new $mbtn(this,e);
		})
	};
	
	$.navigation.mainButton = function(btn,e){
		var isHover = false;
		var numMainmenu = $('#nav li.l1').size();
		$(btn).addClass("primary");
		$(btn).find('.sub-nav ul').wrapList({ itemsPerColumn: numMainmenu - 1 })
		
		var s = $(btn).find('.sub-nav .container:first ul').not('.sub-nav .container ul .container ul').size();
		
		var direction = 'ltr'
		if($('#page').hasClass('rtl')){ direction = 'rtl';}
		var cw;
		if(s==1){
			cw= 180;
		}
		else
		{
			if(direction == 'ltr')
			{
				cw=140;
			}
			else
			{
				cw=180;
			}
		}
		
		var h = $('#nav ul li').not('div.sub-nav li').size();
		var hi = $('#nav ul li a').height() +3;
		
		$(btn).find('.sub-nav .container:first').not('.sub-nav .container .container').width(s*cw)
		$(btn).find('.sub-nav .container').height((h*hi)+19)

		$(btn).find('a').eq(0).click(function() {
			$(e).find('ul li').not('ul li li').removeClass('active');
			$(this).parent().addClass('active');

		   if ($(this).parent().eq(0).hasClass('click')) { 
              		return true;
           	}
			
			if( ($(this).parent().hasClass('primary')) || !($(this).parent().hasClass('click'))  )
			{
				if($('div.blackOut').length == 0){
					$('#main').append('<div class="blackOut"></div>');
					$('.blackOut').show();
					$('.blackOut').fadeTo(0, 0)
					$('.blackOut').fadeTo(400, 0.7)
				}
			}
			
			if( ($(this).parent().hasClass('multi-level')) || ($(this).parent().hasClass('single-level')) ){
				
				$(this).parent().find('.sub-nav').eq(0).fadeTo(0, 0)
				$(this).parent().find('.sub-nav').eq(0).fadeTo("fast", 1)
			}
			
			if( ($(this).parent().hasClass('multi-level')) || ($(this).parent().hasClass('l2')) ){
			   //make all children display: block;
			   //console.log('no redirect/refresh');
				return false; //remain on page if elements underneath top nav - sc 14/09/09 5.30pm
			};

			return false;
		});
	}
	
	showSection = function(ul){
		var w = $(ul).width();
	//	$(ul).width(0);
	//	$(ul).animate({width:w})	
	}
	
	var $showSection = $.navigation.showSection;
	var $mbtn = $.navigation.mainButton;
	var $nav = $.navigation;
})(jQuery);

