/*
	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
*/
$(function() {
	$('div.csw').prepend('<p class="loading">Loading&hellip;<br /><img src="/img/style/ajax-loader.gif" alt="Loading&hellip;" /></p>');
});
var j = 0;
jQuery.fn.codaSlider = function(settings) {
	settings = jQuery.extend({
		easeFunc: 'easeInOutExpo',
		easeTime: 750,
		toolTip: false
	}, settings);
	return this.each(function() {
		var container = $(this);
		container.find("p.loading").remove();
		container.removeClass("csw").addClass("stripViewer");
		var panelWidth = container.find("div.panel").width();
		var panelCount = container.find("div.panel").size();
		var stripViewerWidth = panelWidth*panelCount;
		container.find("div.panelContainer").css("width" , stripViewerWidth);
		var navWidth = panelCount*2;
		if (location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
			var cPanel = parseInt(location.hash.slice(1));
			var cnt = - (panelWidth*(cPanel - 1));
			$(this).find("div.panelContainer").css({ left: cnt });
		} else {
			var cPanel = 1;
		};
		container.each(function(i) {
			$(this).after("<div class='stripNav' id='stripNav" + j + "'><ul><\/ul><\/div>");
			$(this).find("div.panel").each(function(n) {
				$("div#stripNav" + j + " ul").append("<li class='tab" + (n+1) + "'><a href='#" + (n+1) + "'>" + $(this).attr("title") + "<\/a><\/li>");
			});
			$("div#stripNav" + j + " a").each(function(z) {
				navWidth += $(this).parent().width();
				$(this).bind("click", function() {
					$(this).addClass("current").parent().parent().find("a").not($(this)).removeClass("current");
					var cnt = - (panelWidth*z);
					cPanel = z + 1;
					$(this).parent().parent().parent().prev().find("div.panelContainer").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				});
			});
			$("a.cross-link").click(function(){
				$(this).parents().find(".stripNav ul li a:eq(" + (parseInt($(this).attr("href").slice(1)) - 1) + ")").trigger('click');
			});
			if (location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
				$("div#stripNav" + j + " a:eq(" + (location.hash.slice(1) - 1) + ")").addClass("current");
			} else {
				$("div#stripNav" + j + " a:eq(0)").addClass("current");
			}
		});
		j++;
  });
};