//plugin spasticNav
//author: swe
//version: 1.0
(function(jQuery){
	jQuery.fn.spasticPointer = function(options){
		options = jQuery.extend({
			overlap : 20,
			speed : 500,
			reset : 1500, 
			color : '#ff0000', 
			easing : 'easeOutExpo',
			setwidth : 100
		}, options);
	
		return this.each(function(){
			var nav = jQuery(this), 
			currentPageItem = jQuery('li.active',nav),
			pointer,
			reset;
			
			jQuery('<li id="pointer" title="' + currentPageItem.title + '"></li>').css({ //add pointer to html
				width : options.setwidth,
		 		left : currentPageItem.position().left - ((options.setwidth - currentPageItem.width())/2) + 3, 
		 		backgroundColor : options.color,
				margin : 0
				
		 	}).appendTo(this); //tab-bar
		 	
		 	pointer = jQuery('#pointer', nav);
			
			jQuery('li',this).click(function() { 
				// pointer...pls follow me and add class "active"
				clearTimeout(reset);
				jQuery('li.tab-select').removeClass('active'); 
				jQuery(this).addClass('active');
				pointer.animate(
					{
						left : jQuery(this).position().left - ((options.setwidth - jQuery(this).width())/2) 
					},
					{
						duration : options.speed,
						easing : options.easing,
						queue : false
					}
				);
                change_type(this.title);
			});

		});// end return
	};

})(jQuery);


	
jQuery( document ).ready(function() {
	
	//set title of search category 
	jQuery('.tab-select a').hover(
		function(){
			var new_title = jQuery(this).attr('title');
			jQuery('.tab-bar h3').html(new_title);
		},
		function (){
			var new_title = jQuery(this).attr('title');
			var current_title = jQuery('.tab-select.active a').attr('title');
			 if (current_title !=  new_title){		
				 jQuery('.tab-bar h3').html(current_title);
			}
		}
	);
	
	// init pointer
		jQuery('ul.tabs-bar').spasticPointer({
			speed: 800,
			easing: 'easeInOutQuart',
			//overlap: 5,
			color: 'none',
			setwidth : 16,
			reset: 800	
		});	
		
	// pointer at first tabs lags a bit, set the correct position
	if(jQuery('.tab-select.car').hasClass('active')){
		jQuery('#pointer').css({left: 175});
	}

});

