var debugSilder = false;
jQuery.fn.codaSlider = function(settings) {
	settings = jQuery.extend({
		easeFunc: "easeInOutExpo",
		easeTime: 1000,
		toolTip: false
	}, settings);
	return this.each(function() {
		var container = jQuery(this);
		var panelWidth = jQuery("li.panel").width();
		var panelCount = jQuery("li.panel").size();
		var viewPortWidth = panelWidth * 9;
		var stripViewerWidth = panelWidth * panelCount;
		jQuery("div#panelWrapper").css("width", viewPortWidth);
		jQuery("ul#panelContainer").css("width", stripViewerWidth);
		// dirty ie fix
		if(jQuery.browser.msie) {
		    jQuery("div.slider_frontpage").css("margin-bottom", 0);
		}
		var cnt = 0;

		container.each(function(i) {
			if (debugSilder) {
				jQuery("div#slider").after("<div id='debug' class='span-24 error'>&nbsp;</div>");
			}
			// Right nav
			jQuery("div#panelNavR").click(function(){
				/* if (cnt - viewPortWidth + stripViewerWidth <= 0 ) {
					cnt = 0;
				} else */
				if (cnt - viewPortWidth + stripViewerWidth < viewPortWidth) {
				    cnt = viewPortWidth - stripViewerWidth;
				} else {
				    cnt -= viewPortWidth;
				};
				jQuery("ul#panelContainer").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				if (debugSilder) { jQuery("div#debug").html(
				    " panelWidth:" + panelWidth +
					" panelCount:" + panelCount +
					" stripViewerWidth:" + stripViewerWidth +
					" viewPortWidth:" + viewPortWidth +
					" cnt:" + cnt
				); }
				return false;
			});
			// Left nav
			jQuery("div#panelNavL").click(function(){
				if (cnt + viewPortWidth >= 0 ) {
					cnt = 0;
				} else {
				    cnt += viewPortWidth;
				};
				jQuery("ul#panelContainer").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				if (debugSilder) { jQuery("div#debug").html(
				    " panelWidth:" + panelWidth +
					" panelCount:" + panelCount +
					" stripViewerWidth:" + stripViewerWidth +
					" viewPortWidth:" + viewPortWidth +
					" cnt:" + cnt
				); }
				return false;
			});
		});		
    });
};