(function($){  
     $.fn.spotlight = function() {  
      	var currentPod = 1;
      	var currentlyScrolling = false;
      	var maxPods = 0;
      	var timer = null;
        var base = this;
		var el = null;
        
        this.scrollToPod = function(moveTo)
		{	if(moveTo != currentPod)
			{	var thisPod = $('.pod-'+currentPod,el);
				var nextPod = $('.pod-'+moveTo,el);
				if(!currentlyScrolling)
				{	currentlyScrolling = true;
					thisPod.animate({marginLeft: -340},400,function(){
						var parent = $(el).parent();
						$('.button',parent).removeClass('selected');
						$('#button-'+moveTo,parent).addClass('selected');
					});
					nextPod.css({marginLeft: 340}).show();
					nextPod.animate({marginLeft: 0},400,function(){currentlyScrolling = false;});
					currentPod = moveTo;
				}
			}
		};
        this.timerTick = function()
        {	if(currentPod >= maxPods){
			   	base.scrollToPod (1);						
			}else{
				base.scrollToPod (currentPod + 1);		
			}
			timer = setTimeout(function(){base.timerTick(el)},5000);		        	
        }
        
		return this.each(function() {  
			el = this;
			$(this).find('.pod').each(function(){
				maxPods++;
				$(this).addClass('pod-'+maxPods);
				buttonEl = $('<div class="button" id="button-'+maxPods+'"></div>');
				buttonEl.click(function(){
					var id = $(this).attr('id').split('-');
					clearTimeout(timer);
					base.scrollToPod(id[1]);
				});
				if(maxPods > 1)
				{	$(this).hide();
					
				}else
				{	buttonEl.addClass('selected');
				}
				$(el).parent().append(buttonEl);
			});
			timer = setTimeout(function(){base.timerTick()},3000);
        });
        
		
     };  
})(jQuery);  
	
	$('#spotlight-slider').spotlight();
	/*
	var podNo = 1;
	var lastPod = 1;
	var scrolling = false;
	var maxPods = 0;
	

	
	$('#test').click(function(){	
		var thisPod = $('#spotlight-slider .pod-'+podNo);
		if(podNo < maxPods){podNo++;}else{podNo = 1;}
		var nextPod = $('#spotlight-slider .pod-'+podNo);
		    thisPod.animate({marginLeft: -340});
		    nextPod.css({marginLeft: 340}).show();
		    nextPod.animate({marginLeft: 0});
	});
	function timer()
	{	if(podNo >= maxPods)
		{	scrollSpotlightTo(1);						
		}else
		{	scrollSpotlightTo(podNo + 1);						
		}
		scrollingTimer=setTimeout(timer,5000);
	}
	
	
	$('#spotlight-pod .button').click(function(){
		id = $(this).attr('id').split('-');
		clearTimeout(scrollingTimer);
		scrollSpotlightTo(id[2]);
	});
	*/
