 /* Jquery WCM Slideshow by code@woodscreativemedia.com
* v1.1.5
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
* @Dependancies jquery.easing.js
*/

Slideshow = {

		// Initialise The Slideshow and Options
		
		// Options
		defaults : {
			width 	: 960, // The width of the slideshow container
			height 	: 400, // The height of the slideshow container
			autoplay : true, // Auto play slides?	
			wait	: 4000, // The time to wait in m/s for automode
			speed 	: 1000, // The speed of the slideshow transition in m/s
			easing 	: 'easeOutExpo' // The easing type for the transition
		},
		
		Init : function (options)
		{
			// User Defined
			Slideshow.options = $.extend(Slideshow.defaults,options);

			// Globals
			Slideshow.now = 0;
			Slideshow.count = $('.slide').size();
			Slideshow.max_x = Slideshow.options.height;
			Slideshow.max_y = (Slideshow.count-1)*Slideshow.options.height;
			Slideshow.done = true;
			Slideshow.timerID = 0;
			
			// Interface
			$('.slideshow-ui-next').click ( function () {
				Slideshow.Next();
			});
			$('.slideshow-ui-prev').click ( function () {
				Slideshow.Prev();
			});
			$('.slideshow-ui-goto').click ( function () {
				index = $(this).attr("rel");
				Slideshow.Goto(index);
			});
			$('.slideshow-ui-autoplay').click ( function () {
				Slideshow.ToggleAutoPlay();
			});
			
			Slideshow.Start();
		},
		Start : function ()
		{
			if (Slideshow.options.autoplay) Slideshow.timerID = setTimeout(Slideshow.Next,Slideshow.options.wait);
		},
		ToggleAutoPlay : function ()
		{
			// Toggle Autotplay On/Off
			if (Slideshow.options.autoplay == true) {
				Slideshow.options.autoplay = false;
				$('.slide-nav-autoplay-on').removeClass('slide-nav-autoplay-on').addClass('slide-nav-autoplay-off');
				//alert("off");
				Slideshow.Reset();
			} else {
				Slideshow.options.autoplay = true;
				$('.slide-nav-autoplay-off').removeClass('slide-nav-autoplay-off').addClass('slide-nav-autoplay-on');
				//alert("on");
				Slideshow.Start();
			};
		},
		Reset : function ()
		{
			// Clear the Slideshow Timer
			if (Slideshow.timerID) clearTimeout(Slideshow.timerID);
		},
		Goto : function (index)
		{
			// Goto a Specific Slide
			Slideshow.Reset();
			pos = Slideshow.options.height*(index-1);
			if (pos < 0) pos = 0;
			if (pos > Slideshow.max_y) pos = Slideshow.max_y;
			Slideshow.Move(pos);
		},
		Next : function ()
		{
			// Goto next slide
			Slideshow.Reset();
			pos = Slideshow.now+Slideshow.options.height;
			if (pos > Slideshow.max_y) pos = 0;
			Slideshow.Move(pos);
		},
		Prev : function ()
		{
			// Goto to the previous slide
			Slideshow.Reset();
			pos = Slideshow.now-Slideshow.options.height;
			if (pos < 0) pos = Slideshow.max_y;
			Slideshow.Move(pos);
		},
		Move : function (pos)
		{
			// Move the Carousel
			Slideshow.done = false;
			Slideshow.now = pos;
			$('#slideshow-carousel').clearQueue();
			$('#slideshow-carousel').stop();
			$('#slideshow-carousel').animate(
				{'top' : -(pos)},
				Slideshow.options.speed,
				Slideshow.options.easing,
				function () {
					Slideshow.done = true;
					if (Slideshow.options.autoplay) Slideshow.timerID = setTimeout(Slideshow.Next,Slideshow.options.wait);
				}
			);
		}
};

$(document).ready(function() {

    // Slideshow Start
	options = {
		width: 960,
		height: 400,
		autoplay : true,
		wait : 8000,
		speed : 1000
	}
	Slideshow.Init(options);

});
