/*
 * RYcarousel.js - A jQuery Plugin
 * A jQuery plugin for creating carousels, can be embeded within RYaccordions.
 *
 * By Andy Tennison (andrew@tennisons.com / http://www.tennisons.com)
 * For Radley Yeldar (http://www.ry.com/)
 *
 * Version 1.0.1
 * May 5th, 2009
 *
 * Copyright (c) 2009 Andy Tennison
 * Dual licensed under the MIT and GPL licenses.
*/

(function($){$.fn.RYcarousel=function(E){var F=$.extend({},$.fn.RYcarousel.defaults,E);if(jQuery.easing['jswing']==undefined){F.animation='swing'};return this.each(function(d){var f=0;var g=0;$(this).append('<div class="navContainer"></div>');var h=$(this).children('.navContainer');var j=$(this).children(F.inner);var k=0;var l=($(this).children(F.inner).children(F.slide).length)-1;var m=($(this).find(F.slide).css('width')).replace(/px/,'');var n=($(this).css('width')).replace(/px/,'');if(l>=2){if(F.prevNext){h.append('<a class="prev">previous</a><a class="next">Next</a>');var o=h.children('.prev');var p=h.children('.next')};if(F.ends){h.append('<a class="beginning">beginning</a><a class="end">end</a>');var q=h.children('.beginning');var r=h.children('.end')};if(F.play){h.append('<a class="play">play</a>');var s=h.children('.play')};if(F.miniNav){h.append('<ul class="miniNav"></ul>');var u=h.children('.miniNav')}};var k=m*(l+1);if(F.SlideOffset){l=l-(n/m)+1};for(i=0;i<=l;i++){if(F.miniNav){u.append('<li>'+(i+1)+'</li>')}};j.width(k);y(g,f);z(g,f);q.click(function(){g=0;x(f,g);D()});o.click(function(){g=f-F.slideMove;x(f,g);D()});p.click(function(){g=f+F.slideMove;x(f,g);D()});r.click(function(){g=l;x(f,g);D()});var v=false;s.click(function(){if(v==false){s.text('pause').addClass(F.on);v=true;A()}else{s.text('play').removeClass(F.on);v=false;C()}});if(F.autoPlay&&F.play){s.click()};var w=u.children('li');w.bind("mouseenter mouseleave",function(e){$(this).toggleClass("hover")}).bind("click",function(e){e.preventDefault();g=w.index(this);x(f,g)});function x(a,b){if(b<=0&&F.loop=='stop'||b<0&&a>0&&F.loop=='beginning'||b>l&&a==l&&F.loop=='beginning'){g=0}else if(b>=l&&F.loop=='stop'||b<0&&a==0&&F.loop=='beginning'||b>l&&a<l&&F.loop=='beginning'){g=l};y(g,f);z(g,f);var c=m*g;if(F.constantVelocity){F.speed=c*2};j.animate({'left':-c},{duration:F.speed,easing:F.animation});f=g};function y(a,b){p.removeClass(F.disable);r.removeClass(F.disable);o.removeClass(F.disable);q.removeClass(F.disable);if(a==0&&F.loop=='stop'){o.addClass(F.disable);q.addClass(F.disable)}else if(a==l&&F.loop=='stop'){p.addClass(F.disable);r.addClass(F.disable)}};function z(a,b){u.children('li').eq(b).removeClass('on');u.children('li').eq(a).addClass('on')};function A(){t=setTimeout(B,F.delay)}function B(){g=f+F.slideMove;if(g>=l&&f<l&&F.loop=='stop'){g=l;w.eq(g).click();s.click()}else if(g>l&&F.loop=='stop'){g=l;C();s.click()}else if(g>l&&f<l&&F.loop=='beginning'){g=l;w.eq(g).click();t=setTimeout(B,F.delay)}else if(g>l&&F.loop=='beginning'){g=0;w.eq(g).click();t=setTimeout(B,F.delay)}else{w.eq(g).click();t=setTimeout(B,F.delay)};f=g};function C(){clearTimeout(t)};function D(){if(v==true){C();A()}}})}})(jQuery);


$.fn.RYcarousel.defaults = {
	// set main carousel elements
	inner: '.RYC_inner',	// carousel inner
	slide: '.RYC_slide',	// slide class
	disable: 'disable', 	// disable class name
	on: 'on',				// on/active class name
	
	// controls to show, true = show, false = hide
	prevNext: true,			// prev/next one frame
	ends: true,				// to beginning/end
	play: true,				// linked with autoply
	miniNav: true,			// mini navigation showing total number of slides
	
	// main interactions
	slideMove: 1,			// number of slides to move by each time prev or next is clicked.
	speed: 500,
	constantVelocity: false,
	animation: 'easeInOutCirc',
	SlideOffset: true,		// if = true, prevents the user clicking 'next' to empty cells
	
	// looping (stop / beginning / continious)
	loop: 'stop',			// stop = stop at end / beg
	autoPlay: false,
	delay: 2500
	
};
