/*
	jQuery Coda-Slider v1.1 - http://www.ndoherty.com/coda-slider
	
	Copyright (c) 2007 Niall Doherty
	
	Inspired by the clever folks at http://www.panic.com/coda
	Many thanks to Gian Carlo Mingati. Coda-Slider is a heavily modified version of his slideViewer, which can be found at  http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html
	
	Requirements:
	-  jQuery 1.2 ... available via  http://www.jquery.com
	-  jQuery easing plugin (1.2) ... available via  http://gsgd.co.uk/sandbox/jquery/easing/
	- jQuery easing compatability plugin ... available via  http://gsgd.co.uk/sandbox/jquery/easing/
	- CSS included in index.html
*/

jQuery(function(){
		$('div.panelContainer').css('position','relative');
		$('.panelContainer div.panel:eq(0)').addClass('currPan');
		$(".panelContainer").animate({ left: 0}, 750, "expoinout");
		$('a.cross-link:eq(0)').addClass('currLink');
		$('a#prev').css('display','none');
});
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);
		// Remove the preloader gif...
		container.find("p.loading").remove();
		// Self-explanatory...
		container.removeClass("csw").addClass("stripViewer");
		// 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)+50;
		// Use the above width to specify the CSS width for the panelContainer element...
		//container.find("div.panelContainer").width(stripViewerWidth);
		// Set the navWidth as a multiple of panelCount to account for margin-right on each li
		var navWidth = panelCount*2;
		$('div.panelContainer',container).css('position','relative');
		$("div.panelContainer div.panel",container).each(function() { $(this).css('float','left'); });
		
		
		container.each(function(i) {
			
		});
		$("a.cross-link").each(function() {
			var panId = parseInt($(this).attr("href").slice(1)) - 1;
			$(this).attr("href",'javascript:void(0);');
			var cnt = - (panelWidth*panId);
			cPanel = panId + 1;
			$(this).bind("click",function() {
				$("a.cross-link").removeClass('currLink');
				$('.panelContainer div.panel').removeClass('currPan');
				$('.panelContainer div.panel:eq('+panId+')').addClass('currPan');
				$(".panelContainer").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				$(this).addClass('currLink');
				if(panId==0) $('a#prev').css('display','none');
				else $('a#prev').css('display','');
				if(panId==panelCount-1) $('a#next').css('display','none');
				else $('a#next').css('display','');
			});
		});
		$('a.arrow_nav').click(function() {
			var dir = $(this).attr('id');
			switch(dir) {
				case 'next':
					var mod = 1;
					break;
				case 'prev':
					var mod = -1;
					break;
			}
			var cId = $('div.panelContainer div.currPan').attr('id');
			cId = parseInt(cId.replace(/panel/,''))-1;
			if((cId+mod)!=-1 && (cId+mod)<panelCount)
			{
				var cnt = - (panelWidth*(cId+mod));
				$("a.cross-link").removeClass('currLink');
				$('.panelContainer div.panel').removeClass('currPan');
				$('.panelContainer div.panel:eq('+(cId+mod)+')').addClass('currPan');
				$(".panelContainer").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				$('a.cross-link:eq('+(cId+mod)+')').addClass('currLink');
			}
			if(cId+mod==0) $('a#prev').css('display','none');
			else $('a#prev').css('display','');
			if(cId+mod==panelCount-1) $('a#next').css('display','none');
			else $('a#next').css('display','');
		});
		
  });
};
