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.SpiritusNav = function(settings) {
		
		var config = {};
		if (settings) $.extend(config, settings);
  	
		this.each(function() {           
      
			var $self = $(this),
			_timer			=	'',
			_show_speed	= 400,
			_hide_speed	= 200,
			_pause_time	=	2000,
			_curr_sub		=	false;

			init_SpiritusNav();
				
			function init_SpiritusNav() {
				init_draw();
				init_events();
			}
			
			function init_draw() {}
			
			function init_events() {
				
				$self.find('.topnav').hover(
				  function () {
						hide_sub(this);
						stop_timer();
				    show_sub(this);
				  }, 
				  function () {
				    start_timer();
				  }
				);
				
				$self.find('.subnav').hover(
				  function () { stop_timer(); }, 
				  function () { start_timer(); }
				);
			}
			
			function show_sub (el) {
				
				var sub = $(el).parent().find("ul.subnav");
				
				sub.slideDown(_show_speed).show();
				_curr_sub = sub;
			}
			
			function hide_sub (el) {
				var sub = $(el).parent().find("ul.subnav");
				
				if (_curr_sub) {
					if (_curr_sub.get(0) !== sub.get(0)) {
						_curr_sub.slideUp(_hide_speed);
					}
				}
			}
			
			function start_timer () { _timer = setTimeout(function () { hide_sub() }, _pause_time); }
			function stop_timer () { clearTimeout(_timer);	}
			  
		}); 
      
		return this;
	} // SpiritusNav End ---------------------------
	
	$.fn.SpiritusHero = function(settings) {
		
		var config = {};
		if (settings) $.extend(config, settings);
  	
		this.each(function() {           
      
			var $self 		= $(this),
			_timer				=	'',
			_show_speed		= 400,
			_hide_speed		= 200,
			_pause_time		=	5000,
			_paused				=	false,
			_tabs 				=	[],
			_heros				=	[],
			_curr_index		=	0;

			init_SpiritusNav();
				
			function init_SpiritusNav() {
				init_draw();
				init_events();
			}
			
			function init_draw() {
				_tabs = config.tabs;
				_heros = config.heros;
				$(_tabs[_curr_index]).addClass('active');
			}
			
			function init_events() {
				
				_tabs.click(function (e) {
					e.preventDefault();
					toggle_hero($(this))
				});
				
				$self.hover(
				  function () { stop_timer(); }, 
				  function () { start_timer(); }
				);
				
				start_timer();
				
			}
			
			function toggle_hero (el) {
				var index  = _tabs.index(el);
				
				if (index != _curr_index) {
					$(_heros[_curr_index]).fadeOut(500);	
					$(_heros[index]).css('z-index', _heros.length).delay(100).fadeIn();
					
					$(_tabs[_curr_index]).removeClass('active');
					$(_tabs[index]).addClass('active');
					
					_curr_index = index;
				}
			}
			
			function timed_toggle () {
				if (!_paused) {
					var next_index = (_curr_index == (_tabs.length - 1)) ? 0: _curr_index + 1;
					toggle_hero( $(_tabs[next_index]) );
					start_timer();
				}
			}
			
			function start_timer () { _timer = setTimeout(function () { timed_toggle() }, _pause_time); }
			function stop_timer () { clearTimeout(_timer);	}
			  
		}); 
      
		return this;
	} // SpiritusHero End ---------------------------
})(jQuery);



