/*
	jQuery Coda-Slider v1.1.1 - http://www.ndoherty.com/coda-slider
	Copyright (c) 2007 Niall Doherty
	
	Heavily modified by Brent Traut for use on http://taubmancollege.umich.edu/	
*/

function sliderTimer() {
	if (!jQuery('#badges').hasClass('hover'))
		jQuery('#badges .next_previous:first a:last').click();

	setTimeout('sliderTimer();', 5000);
}

var j = 0;

jQuery.fn.codaSlider = function(settings) {

	settings = jQuery.extend({
		easeFunc: "expoinout",
		easeTime: 750,
		toolTip: false
	}, settings);
	
	return this.each(function() {
		var container = jQuery(this);
		// Get the width of a panel, set from CSS...
		var panelWidth = container.find("div.panel").width();
		// panelCount gives us a count of the panels in the container...
		var panelCount = container.find("div.panel").size();
		// Calculate the width of all the panels when lined up end-to-end...
		var stripViewerWidth = panelWidth*panelCount;
		// Use the above width to specify the CSS width for the panelContainer element...
		container.find("div.panelContainer").css("width" , stripViewerWidth);
		
		// Always start with the first panel.
		var cPanel = 1;
		
		// Create appropriate nav
		container.each(function(i) {

			jQuery('.panel', i).each(function (k) {

				// Set up the hovers.
				jQuery(this).hover(function () {
					jQuery(this).parent().parent().addClass('hover');
				}, function () {
					jQuery(this).parent().parent().removeClass('hover');
				});

				// Set up the links on < and >.
				jQuery('.next_previous', k).each(function () {

					// Set up the < link.
					jQuery('a:first', this).click(function() {
						if (cPanel == 1) {
							var cnt = - (panelWidth*(panelCount - 1));
							cPanel = panelCount;
						} else {
							cPanel -= 1;
							var cnt = - (panelWidth*(cPanel - 1));
						};
						
						jQuery(this).parent().parent().parent().parent().parent().find("div.panelContainer").animate({ left: cnt }, settings.easeTime, settings.easeFunc);
						return false;
					});
	
					// Set up the > link.
					jQuery('a:last', this).click(function() {
						if (cPanel == panelCount) {
							var cnt = 0;
							cPanel = 1;
						} else {
							var cnt = - (panelWidth*cPanel);
							cPanel += 1;
						};
						
						jQuery(this).parent().parent().parent().parent().parent().find("div.panelContainer").animate({ left: cnt }, settings.easeTime, settings.easeFunc);
						return false;
					});
					
				});
				
			});
		});
		
		setTimeout('sliderTimer();', 5000);
		
		j++;
  });
};