window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){arguments.callee=arguments.callee.caller;var a=[].slice.call(arguments);(typeof console.log==="object"?log.apply.call(console.log,console,a):console.log.apply(console,a))}};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());

(function($){
	
	$.fn.DropNav = function(settings) {
		
		var config = {};
		if (settings) $.extend(config, settings);
  	
		this.each(function() {           
      
			var $self = $(this),
			_timer			=	'',
			_show_speed	= 200,
			_hide_speed	= 200,
			_pause_time	=	800,
			_curr_top 	=	false,
			_curr_sub		=	false,
			_top_els		=	'',
			_sub_els		=	'',
			_top_li_els	=	'';

			init_DropNav();
				
			function init_DropNav() {
				init_draw();
				init_events();
			}
			
			function init_draw() {
				_top_els = $self.find('#nav > li a').not("#nav li ul a");
				_sub_els = $self.find('#nav li ul');
				_top_li_els = $self.find('#nav > li').not("#nav li ul li");
				
				$(_sub_els).each(function () {
					
					var index = $(this).parent().attr('class').indexOf('first_child');
					
					if (index > -1) {
						var buffer = -11;
					} else {
						var buffer = -1;
					}
					
					var width = $(this).parent().width() + buffer;
					$(this).css('width', width);
				});
			}
			
			function init_events() {
				
				_top_els.hover(
				  function () {
						stop_timer();
						hide_sub(_curr_sub);
						top_mouseover(this);
						if ($(this).siblings().length > 0) {
							show_sub(this);
						}
				  }, 
				  function () {
						top_mouseout();
				    start_timer();
				  }
				);
				
				_sub_els.hover(
				  function () { stop_timer(); }, 
				  function () { start_timer(); }
				);
			}
			
			function show_sub (el) {

				var top = $(el);
				
				var sub = $($(el).siblings()[0]);
				sub.slideDown(_show_speed).show();
				
				_curr_top = top;
				_curr_sub = sub;
			}
			
			function hide_sub (el) {
				if (el) {
					var sub = $($(el).siblings()[0]);
				} else {
					var sub = $('');
				}
				
				if (_curr_sub) {
					if (_curr_sub.get(0) !== sub.get(0)) {
						_curr_sub.slideUp(_hide_speed);
						_curr_top.removeClass('active');
						_curr_sub = false;
					}
				}
			}
			
			function start_timer () { _timer = setTimeout(function () { hide_sub() }, _pause_time); }
			function stop_timer () { clearTimeout(_timer);	}
			
			function top_mouseover (el) {
				
				top_mouseout();
				
				//$(el).parent().addClass('active');
				
				index = _top_els.index(el);
				
				before_index 	= (index == 0) ? false: index - 1;
				after_index 	= (index == (_top_els.length - 1)) ? false: index + 1;
				
				$(_top_els[before_index]).parent().addClass('active-before');
				$(_top_els[after_index]).parent().addClass('active-after');
			}
			
			function top_mouseout () {
				
				_top_li_els.removeClass('active-before');
				_top_li_els.removeClass('active-after');
			}
			  
		}); 
      
		return this;
	} // DropNav End ------------------------------------------------------------------------------------------------------
	
	$.fn.FooterLogos = function(settings) {
		
		var config = {};
		if (settings) $.extend(config, settings);
  	
		this.each(function() {           
      
			var $self = $(this),
			_timer			=	'',
			_pause_time	=	4000,
			_anim_speed	=	1200,
			_fade_speed	= 800,
			_els				=	'',
			_curr_index	=	0,
			_length			=	0,
			_first_run	=	true,
			_easing			=	'easeOutExpo',
			_curr_hero_index = 0;

			init_FooterLogos();
				
			function init_FooterLogos() {
				init_draw();
			}
			
			function init_draw() {
				_els = $self.find('.logo');
				_els.hide();
				_el_w = $(_els[0]).outerWidth();
				//console.log(_el_w);
				_length = $self.width() - _el_w;
				//console.log(_length);
				//_length = _length + 800;
				
				//Hero syncing vars
				_hero_els = $('#hero-imgs').children();
				
				start_timer();
			}
			
			function rotate () {
				
				if (_first_run) {
					var next_index = _curr_index;
					var next_hero_index = _curr_hero_index + 1;
				} else {
					var next_index = (_curr_index == _els.length - 1) ? 0 : _curr_index + 1 ;
					var next_hero_index = (_curr_hero_index == _hero_els.length - 1) ? 0 : _curr_hero_index + 1 ;;
				}
				
				if (!_first_run) {
					$(_els[_curr_index]).fadeOut(_fade_speed, function () {
						
						$(_els[next_index]).css({ left : 0 - _el_w , display : 'block' });
						$(_els[next_index]).animate( { left : _length }, _anim_speed, _easing );
						
						if ($('#hero-imgs').length > 0) {
							$('#hero-imgs').cycle(next_hero_index);
						}
						
					});
					
				} else {
					
					$(_els[next_index]).css({ left : 0 - _el_w , display : 'block' });
					$(_els[next_index]).animate( { left : _length }, _anim_speed, _easing );
					
					if ($('#hero-imgs').length > 0) {
						$('#hero-imgs').cycle(next_hero_index);
					}
					
				}
				
				_curr_index = next_index;
				_curr_hero_index = next_hero_index;
				
				if (_first_run) {
					_first_run = false;
				}
				
				start_timer();
			}
			
			function start_timer () { _timer = setTimeout(function () { rotate() }, _pause_time); }
			function stop_timer () { clearTimeout(_timer);	}
		}); 

		return this;
	} // FooterLogos End ------------------------------------------------------------------------------------------------------
	
	$.fn.PromoBoxes = function(settings) {
		
		var config = {};
		if (settings) $.extend(config, settings);
  	
		this.each(function() {           
      
			var $self = $(this),
			_els				=	'',
			_curr_index = 0;

			init_PromoBoxes();
				
			function init_PromoBoxes() {
				init_draw();
				init_events();
			}
			
			function init_draw() {
				_els = $self.find('.hm-promo');
				_curr_index = 0;
			}
			
			function init_events () {
				
				_els.hover(
				  function () {
						toggle(this);
				  }, 
				  function () {
				  }
				);
				
			}
			
			function toggle (el) {
				var index = _els.index(el) + 1;
				
				$self.removeClass('active-' + _curr_index);
				$self.addClass('active-' + index);
				
				_curr_index = index;
				
			}
			
			function untoggle () {
				
			}
		});
			
		return this;
	} // PromoBoxes End ------------------------------------------------------------------------------------------------------
		

})(jQuery);



