/**
 * @author dave
 */
(function($) {
    $.fn.BluntTab = function(settings){
		//alert('infunction');
		var config = {'TC' : $('#Tabs > .Tab')};
		if (settings) $.extend(config, settings);
		
		var $Tabs = $('ul.Tabbed >li a');
		var Url= $('ul.Tabbed li#Url').text();
		var $TC = config.TC;
		//alert($TC.html());
		
		$Tabs.filter(':first').addClass('ActiveTab');
		$TC.hide().filter(':first').show();
		$Tabs.each( function(e) { 
			$(this).mouseover( handleMouseOver ); 
			$(this).click( handleClick ); 
		});
    
    	function handleMouseOver() {
			//console.log(this);
			$TC.hide().filter(this.hash).show();
			$Tabs.removeClass('ActiveTab');
			$(this).addClass('ActiveTab');
			
			return false;
		}
    	
    	function handleClick(e) { 
    		//alert (this.hash);
    		var h=this.hash;
    		//alert (Url+'/'+h.replace('#', ''));
    		window.location = Url+'/'+h.replace('#', '');
    		return false; 
    	}

		return this;
	}
})(jQuery);

(function($) {
	$.fn.TabSwitcher = function (settings) { 
		var config = { };
		if(settings) $.extend(config, settings);
		
		var $self = $(this); 
		var items = new Array();
		var intervalID = 0;
		var index = 1; 
		var max = 0;
		
		
		
		
		$self.each(function(i, el) { 
			var aTag = $(el);
			var hash = $(el).attr('href');
			
			items.push( {'tag' : aTag, 'hash' : hash } );
			
			//console.log('tag : '+items[i].tag+' href: '+items[i].hash);
		});
		
		max = items.length -1;
		
		
		function switchTab() { 
			var aTag, hash, prevHash, prevIndex;
			var $nextSection, $prevSection;
			
			// get the link tag and hash value;
			aTag=items[index].tag; 
			hash=items[index].hash;
			
			//set up the last index that was shown;
			(index > 0) ? prevIndex=index -1 : prevIndex = max;
			
			prevHash = items[prevIndex].hash;
			
			//Get the section objects for manipulation;
			$nextSection =  $(hash);
			$prevSection = $(prevHash);
			
			
			$self.removeClass('ActiveTab');
			
			$(items[index].tag	).addClass('ActiveTab');

			
			$prevSection.fadeOut('fast', function() { $nextSection.fadeIn('fast'); });
			
			(index < max ) ? index++ : index = 0;
			
			//console.log(' switch Called index: '+index+' max: '+max);
			
		}
		
		intervalID = setInterval(function() { switchTab(); }, 4000);

	
	};
})(jQuery);
