/*
 * Royal Slider  v3.0
 *
 * Copyright 2011, Dmitry Semenov
 * 
 * August 2011
 */


(function($) {

	function RoyalSlider(element, options) {
		if("ontouchstart" in window) {
			this.hasTouch = true;
		} else {
			this.hasTouch = false;
		}
		
		this.slider = $(element);
		var self = this;
		this.settings = $.extend({}, $.fn.royalSlider.defaults, options);
		
		if(this.hasTouch) {
			this.settings.directionNavAutoHide = false;
			this.settings.hideArrowOnLastSlide = true;
		}
		this.isSlideshowRunning = false;
		this._slideshowHoverLastState = false;
		
		this._dragContainer = this.slider.find(".royalSlidesContainer");
		this._slidesWrapper = this._dragContainer.wrap('<div class="royalWrapper"/>').parent();
		this.slides = this._dragContainer.find(".royalSlide");
		
		this._removeFadeAnimation = false;	
		
		
		
		if(this.settings.removeCaptionsOpacityInIE8) {
			if ($.browser.msie  && parseInt($.browser.version) <= 8) {
			 this._removeFadeAnimation = true;	
			}
		}
		
		
		this.slider.css("overflow","visible");
		
		this.sliderWidth = 0;
		this.sliderHeight = 0;
		
		
		this.slideshowTimer = '';
		
		this.numSlides = this.slides.length;
		
		this.currentSlideId = 0;
		this.lastSlideId = -1;
		
		this.isAnimating = true;
		
		// Used for checking back/forward drag direction
		this._currentDragPosition = 0;
		this._lastDragPosition = 0;	
		
		// Stores caption animations and clears after next slide is shown
		this._captionAnimateTimeouts = [];
		this._captionAnimateProperties = [];
		
		this._blockClickEvents = false;
		
		this._tx = 0;
		this._startMouseX = 0;
		//used for detecting horizonal or vertical drag move
		this._startMouseY = 0;
		this._startPos = 0;
		
		this._isDragging = false;
		
		this.wasSlideshowPlaying = false;
		/*if(this.settings.slideshowAutoStart) {
			_wasSlideshowPlaying = true;
		}*/
		
		this._isHovering = false;
		
		// Setup Slideshow
		if(this.settings.slideshowEnabled) {
			if(this.settings.slideshowDelay > 0) {	
				if(this.settings.slideshowPauseOnHover) {				
					this.slider.hover(
						function() {
							self._isHovering = true;							
							self.stopSlideshow(true);
						},
						function() {
							self._isHovering = false;							
							self.resumeSlideshow(true);
						}
					);				
				}
			}			
		}
		
		
		// Adding grab/grabbing cursors
		var cursCoords = ""; 
		if($.browser.msie) {
			if(parseInt($.browser.version) == 7) {
				this.isIE7 = true;
				this._dragContainer.css("cursor","move");
			} else {
				this.isIE7 = false;	
			}
		} 
		if($.browser.opera) {
			_grabCursor = "move";
			_grabbingCursor = "move";
		} else {
			if($.browser.mozilla) {
				_grabCursor = "-moz-grab";
				_grabbingCursor =  "-moz-grabbing";
			} else {
				_grabCursor =  "url(img/cursors/grab.cur), move";
				_grabbingCursor =  "url(img/cursors/grabbing.cur), move";
			}
			_grabCursor = $.browser.mozilla ? "-moz-grab" : "url(img/cursors/grab.cur), move";
			_grabbingCursor = $.browser.mozilla ? "-moz-grabbing" : "url(img/cursors/grabbing.cur), move";
		}
		this._setGrabCursor();
		
		
		
		// Setup control nav (thumbs/bullets)
		if(this.settings.controlNavEnabled) {
			var _navigation;
			var _navigationContainer;
			
			if(!self.settings.controlNavThumbs) {				
				_navigationContainer = $('<div class="royalControlNavOverflow"><div class="royalControlNavContainer"><div class="royalControlNavCenterer"></div></div></div>');
				_navigation = _navigationContainer.find('.royalControlNavCenterer');		
			} else {
				if(self.settings.controlNavThumbsNavigation) {
					_navigationContainer = $('<div class="royalControlNavOverflow royalThumbs" style="left:42px; width:'+(this.slider.width() - 84) + 'px;"><div class="royalControlNavThumbsContainer"></div></div>');
					
					_navigation = _navigationContainer.find('.royalControlNavThumbsContainer');	
					this._slidesWrapper.after("<a href='#' class='thumbsArrow left disabled'></a>");
					this._slidesWrapper.after("<a href='#' class='thumbsArrow right'></a>");
				}else {
					_navigationContainer = $('<div class="royalControlNavOverflow royalThumbs"><div class="royalControlNavContainer"><div class="royalControlNavCenterer"></div></div></div>');
					_navigation = _navigationContainer;		
				}
				
			}
			
			var cSlideId = 0;
			this.slides.each(function(){	
				if(self.settings.controlNavThumbs) {								
					_navigation.append("<a href='#' class='royalThumb' style='background-image:url("+ $(this).attr("data-thumb") +");'/>");				
				} else {					
					_navigation.append('<a href="#"/>');	
				}	
				cSlideId++;	
			});		
			
			this.navItems = _navigation.children();
			this.navItems.eq(0).addClass("current");
			this.navItems.eq(this.navItems.length - 1).addClass("last");
			
			this._slidesWrapper.after(_navigationContainer);
			
			// Thumbnails navigation
			if(self.settings.controlNavThumbs && self.settings.controlNavThumbsNavigation) {
				this.thumbsArrowLeft = this.slider.find("a.thumbsArrow.left");
				this.thumbsArrowRight = this.slider.find("a.thumbsArrow.right");
				this._thumbsNavContainer = _navigation;
				
				this._thumbsContainerMoveOffset = parseInt(_navigationContainer.width());				
				this._numThumbItems = this.navItems.size();
				this._outerThumbWidth = this.navItems.eq(0).outerWidth(true);
				this._thumbsItemsWidth = this._outerThumbWidth * this._numThumbItems;
				this._thumbsNavContainer.css("width",this._thumbsItemsWidth + "px");

				this._currThumbsView = 0;
				this._numThumbViews = Math.ceil(this._thumbsItemsWidth / this._thumbsContainerMoveOffset);
				this._fullItemsPerView = Math.floor(this._thumbsContainerMoveOffset / this._outerThumbWidth);
				
				this.thumbsArrowLeft.click(function(e){
					e.preventDefault();
					if(self._currThumbsView > 0) {
						self._currThumbsView--;
						self._animateThumbs();
					}
				});
				this.thumbsArrowRight.click(function(e){
					e.preventDefault();
					if(self._currThumbsView < self._numThumbViews - 1) {
						self._currThumbsView++;
						self._animateThumbs();
					}
				});
			}
		}
		
		
		//hide all captions on start
		if(this.settings.captionAnimationEnabled) {
			this._slidesWrapper.find(".royalCaption").css("display", "none");			
		}
		
		
		//Direction navigation (arrows)
		if(this.settings.directionNavEnabled) {	
			this._slidesWrapper.after("<a href='#' class='arrow left'/>");
			this._slidesWrapper.after("<a href='#' class='arrow right'/>");
			
			
			this.arrowLeft = this.slider.find("a.arrow.left");
			this.arrowRight = this.slider.find("a.arrow.right");
			
			if(this.arrowLeft.length < 1 || this.arrowRight.length < 1) {
				this.settings.directionNavEnabled = false;
			} else if(this.settings.directionNavAutoHide) {
				this.arrowLeft.hide();
				this.arrowRight.hide();
				
				this.slider.bind("mousemove.arrowshover",function() {
					self.arrowLeft.fadeIn("fast");
					self.arrowRight.fadeIn("fast");
					self.slider.unbind("mousemove.arrowshover");
				});
			
			
				this.slider.hover(
					function() {
						self.arrowLeft.fadeIn("fast");
						self.arrowRight.fadeIn("fast");
					},
					function() {
						self.arrowLeft.fadeOut("fast");
						self.arrowRight.fadeOut("fast");				
					}
				);	
			}	
			if(this.settings.hideArrowOnLastSlide) {
				this.arrowLeft.css("visibility", "hidden");
			}	
		}
		
		
				
		// Manage window resize event with 100ms delay
		var resizeTimer;
		$(window).bind('resize', function() {		
			if (resizeTimer) 
				clearTimeout(resizeTimer);			
			resizeTimer = setTimeout(function() { self._onResize(); }, 100);			
		});
		this._onResize();	
		
		// loading screen handling
		if(this.settings.welcomeScreenEnabled) {
			// gets url of image to preload (background-image of slide)
			var bgImageURL = this.slides.eq(0).css("background-image");
			
			if(bgImageURL != "" && bgImageURL != "none") {
				var imageObj = new Image();  
				$(imageObj).load(function() {
				  self.settings.loadingComplete.call(self);
				  self.slider.find(".royalLoadingScreen").fadeOut(self.settings.welcomeScreenShowSpeed, function(){$(this).remove(); });
				  setTimeout(function(){self._startSlider();},self.settings.welcomeScreenShowSpeed + 100);
				});
				
				bgImageURL =  bgImageURL.substring(4, bgImageURL.length - 1);	
				if(bgImageURL.charAt(0) == '"' || bgImageURL.charAt(0) == "'") {
					bgImageURL = bgImageURL.substring(1,bgImageURL.length - 1);
				}
				imageObj.src = bgImageURL;
				
			} else {
				var loadingScreen = this.slider.find(".royalLoadingScreen");
				if(loadingScreen) {
					self.settings.loadingComplete.call(self);
					loadingScreen.fadeOut(self.settings.welcomeScreenShowSpeed, function(){$(this).remove(); });
					setTimeout(function(){self._startSlider();},self.settings.welcomeScreenShowSpeed + 100);
				} else {
					setTimeout(function(){self._startSlider(); self.slider.find(".royalLoadingScreen").remove(); self.settings.loadingComplete.call(self);},100);	
				}
			}
								
		}	else {
			setTimeout(function(){self._startSlider(); self.slider.find(".royalLoadingScreen").remove(); self.settings.loadingComplete.call(self);},100);	
		}
	} /* RoyalSlider Constructor End
	/* -------------------------------------RoyalSlider Prototype------------------------------------------------------*/
	RoyalSlider.prototype = {
		// Move to slide with specified id
		goTo:function(id) {	
			if(!this.isAnimating) {
				this.isAnimating = true;
				var self = this;
				
				this._dragContainer
					.unbind("mousedown")
					.unbind("touchstart")
					.unbind("MozTouchDown");
				
				this._blockClickEvents = true;
					
				if(this.settings.controlNavEnabled) {					
					this.navItems.eq(this.currentSlideId).removeClass('current');
					this.navItems.eq(id).addClass("current");
				}
				this.lastSlideId = this.currentSlideId;
				this.currentSlideId = id;	
				
				if(this.settings.directionNavEnabled && this.settings.controlNavThumbs && this.settings.controlNavThumbsNavigation)
				{					
					// move thumbs view
					for(var i = 0; i < this._numThumbViews; i++) {
						if(id >= this._fullItemsPerView * i && id < this._fullItemsPerView * (i + 1)) {							
							this._currThumbsView = i;
							this._animateThumbs();
							break;
						}
					}
				}
				
				
				if(this.settings.directionNavEnabled)
				{
					if(this.settings.hideArrowOnLastSlide) {
						if(this.lastSlideId == 0) {
							this.arrowLeft.css("visibility", "visible");
						} else if(this.lastSlideId == this.numSlides - 1) {
							this.arrowRight.css("visibility", "visible");
						}
						
						if(this.currentSlideId == 0) {
							this.arrowLeft.css("visibility", "hidden");
						} else if(this.currentSlideId == this.numSlides - 1) {
							this.arrowRight.css("visibility", "hidden");
						}					
					}
				}

				
				this.settings.beforeSlideChange.call(this);
				
				this.stopSlideshow();
				
				// Animate slide
				this._dragContainer.animate(
					{left: -this.currentSlideId * this.sliderWidth}, 
					this.settings.slideTransitionSpeed,
					this.settings.slideTransitionEasing, 
					function(){self._onSlideAnimationComplete();}
				);	
			}
		},	
		// go to prev slide (cyclic)
		prev:function() {
			if(this.currentSlideId <= 0) { 
				this.goTo(this.numSlides - 1);				
			} else {
				this._moveSlideLeft();
			}	
		},
		// go to next slide (cyclic)
		next:function() {
			//go from last to first
			if(this.currentSlideId >= this.numSlides - 1) {				
				this.goTo(0);		
			} else {
				this._moveSlideRight();
			}	
		},
		resumeSlideshow: function(playedFromHover){
			if(this.settings.slideshowEnabled) {
				if(this.slideshowTimer == '') {
					if(playedFromHover) {
						if(!this._slideshowHoverLastState) {
							return;
						}
					}					
					this.slideshowTimer = setInterval(function() { self.next(); }, this.settings.slideshowDelay);
					this.isSlideshowRunning = true;
					var self = this;					
				}
			}			
		},		
		
		stopSlideshow: function(stoppedFromHover){
			if(this.settings.slideshowEnabled) {
				if(stoppedFromHover) {
					this._slideshowHoverLastState = 	this.isSlideshowRunning;
				} else {
					this._slideshowHoverLastState = false;
					this.isSlideshowRunning = false;
				}
				clearInterval(this.slideshowTimer);
				this.slideshowTimer = '';
			}					
		},
		_animateThumbs:function() {				
			if(this._currThumbsView == 0) {
				this.thumbsArrowLeft.addClass("disabled");
			} else {
				this.thumbsArrowLeft.removeClass("disabled");
			}
			if(this._currThumbsView == this._numThumbViews - 1) {
				this.thumbsArrowRight.addClass("disabled");
			} else {
				this.thumbsArrowRight.removeClass("disabled");
			}
			var offset = -this._thumbsContainerMoveOffset * this._currThumbsView;
			this._thumbsNavContainer.animate(
				{left: offset + "px"}, 
				this.settings.controlNavThumbsSpeed,
				this.settings.controlNavThumbsEasing
			);
		},
		_startSlider:function() {
			var self = this;
			if(this.settings.controlNavEnabled) {
				this.navItems.bind("click", function(e){ 
					e.preventDefault(); 
					if(!this._blockClickEvents)
						self._onNavItemClick(e);
				});
			}
			if(this.settings.directionNavEnabled) {
				this.arrowRight.bind('click', function(e) {
					e.preventDefault();	
					if(!this._blockClickEvents)
						self.next();
				});
				
				this.arrowLeft.bind('click', function(e) {
					e.preventDefault();
					if(!this._blockClickEvents)
						self.prev();
				});	
			}
			this._onSlideAnimationComplete();
			if(this.settings.slideshowEnabled && !this.settings.slideshowAutoStart) {
				this.stopSlideshow();
			}
		},
		_setGrabCursor:function() {
			if (!this.isIE7) {
				this._dragContainer.css("cursor",_grabCursor);
			}
		},
		_setGrabbingCursor:function() {
			 if (!this.isIE7) {
				this._dragContainer.css("cursor",_grabbingCursor);
			 }
		},
		_moveSlideRight:function() {			
			if(this.currentSlideId < this.numSlides - 1) {
				this.goTo(this.currentSlideId+1);			
			} else {
				this.goTo(this.currentSlideId);
			}		
		},
		_moveSlideLeft:function() {
			if(this.currentSlideId > 0) { 
				this.goTo(this.currentSlideId-1);
			} else {
				this.goTo(this.currentSlideId);
			}			
		},
		// handling browser resize	
		_onResize:function() {
			
			var totalWidth = parseInt(this._slidesWrapper.width());
			var totalHeight = parseInt(this._slidesWrapper.height());
			
			if(totalWidth != this.sliderWidth || totalHeight != this.sliderHeight) {
				this.sliderWidth = totalWidth;
				this.slides.each(function(){			
					$(this).css({height: totalHeight + "px", width: totalWidth + "px"});	      	
				});
				this._dragContainer.css({"left":-this.currentSlideId * this.sliderWidth, width:this.sliderWidth * this.numSlides});
			}
			
		},
		_onNavItemClick:function(e) {		
			this.goTo($(e.currentTarget).index());	
		},
		// Start dragging the slide
		_onDragStart:function(e) {	
				
			if(!this._isDragging) {	
				var point;
				
				if(this.hasTouch) {
					
					
					//parsing touch event
					var currTouches = e.originalEvent.touches;
					if(currTouches && currTouches.length > 0) {
						point = currTouches[0];
					}					
					else {	
						return false;						
					}
					
					
						
				} else {
					point = e;
					e.preventDefault();		
				}
				
				if(this.slideshowTimer != '') {
					this.wasSlideshowPlaying = true;
					this.stopSlideshow();
				} else {
					this.wasSlideshowPlaying = false;
				}
					
				
				this._setGrabbingCursor();			
				this._isDragging = true;
				var self = this;
				
				$(document).bind("mousemove touchmove MozTouchMove", function(e) { self._onDragMove(e); });
				$(document).bind("mouseup touchend MozTouchRelease", function(e) { self._onDragRelease(e); });		
				
				this._tx = parseInt(this._dragContainer.css("left"));	
				
				this._startMouseX = point.clientX;
				this._startMouseY = point.clientY;
				
				this._startPos = parseInt(this._dragContainer.css("left"));
			}	
			return false;	
		},
		_onDragMove:function(e) {	
			var point;
			if(this.hasTouch) {
				var touches = e.originalEvent.touches;
				// If touches more then one, so stop sliding and allow browser do default action
				if(touches.length > 1) {
					return false;
				}
				point = touches[0];	
				// If drag direction on mobile is vertical, so stop sliding and allow browser to scroll
				if(Math.abs(point.clientY - this._startMouseY) + 10 > Math.abs(point.clientX - this._startMouseX)) {
					return false;
				}
				e.preventDefault();				
			} else {
				point = e;
				e.preventDefault();		
			}
			
			
			// Helps find last direction of drag move
			this._lastDragPosition = this._currentDragPosition;
			var distance = point.clientX - this._startMouseX;
			if(this._lastDragPosition != distance) {
				this._currentDragPosition = distance;
			}
			
			if(distance != 0)
			{			
				if(this.currentSlideId == 0) {			
					if(distance > 0) {
						distance = Math.sqrt(distance) * 5;
					}			
				} else if(this.currentSlideId == (this.numSlides -1)) {		
					if(distance < 0) {
						distance = -Math.sqrt(-distance) * 5;
					}	
				}
				
				this._dragContainer.css("left", this._tx + distance);		
			}			
			return false;		
		},
		_onDragRelease:function(e) {	
			
			if(this.wasSlideshowPlaying) {
				this.resumeSlideshow();
			}
			if(this._isDragging) {			
				this._isDragging = false;			
				this._setGrabCursor();
				this.endPos = parseInt(this._dragContainer.css("left"));
				this.isdrag = false;
				
				$(document)					
					.unbind("mousemove")
					.unbind("touchmove")
					.unbind("MozTouchMove")			
					.unbind("mouseup")
					.unbind("touchend")
					.unbind("MozTouchRelease");
					
				if(this.endPos == this._startPos) {
					return;	
				}	
				
			
				// calculate slide move direction
				if(this._startPos - this.settings.minSlideOffset > this.endPos) {		
					
					if(this._lastDragPosition < this._currentDragPosition) {		
						this.goTo(this.currentSlideId );
						return false;					
					}
					
					this._moveSlideRight();
				} else if(this._startPos + this.settings.minSlideOffset < this.endPos) {		
					if(this._lastDragPosition > this._currentDragPosition) {			
						this.goTo(this.currentSlideId );
						return false;
					}
					this._moveSlideLeft();
					
				} else {
					this.goTo(this.currentSlideId );
				}
			}
			
			return false;
		},		
		// Slide animation complete handler
		_onSlideAnimationComplete:function() {		
			
			var self = this;
			
			
			this.resumeSlideshow();
			
			
			
			this._blockClickEvents = false;
			
			this._dragContainer.bind("mousedown touchstart MozTouchDown", function(e) {  self._onDragStart(e); });			
			
			
			
			if(this.settings.captionAnimationEnabled && this.lastSlideId != this.currentSlideId) {
				// hide last image caption
				if(this.lastSlideId != -1 ) {
					this.slides.eq(this.lastSlideId).find(".royalCaption").css("display", "none");				
				}
				setTimeout(function() { self._showCaption(this.currentSlideId);}, 10);			
			}
			this.isAnimating = false;
			this.settings.afterSlideChange.call(this);
			
			
		
		},
		// Show caption with specified id
		_showCaption:function (id) {	
		
			var caption = this.slides.eq(this.currentSlideId).find(".royalCaption");
			
			if(caption.length) {
				caption.css("display", "block");
				
				var self = this;			
				var currItem;				
				var captionItems = caption.children();
								
				var fadeEnabled;
				var moveEnabled;				
				var effectName;
								
				var effectsObject;
				var moveEffectProperty;
				var currEffects;
				var newEffectObj;
				
				var moveOffset;
				var delay;
				var speed;
				var easing;
				
				var moveProp;
				// clear previous animations
				if(this._captionAnimateTimeouts.length > 0) {
					for(var a = this._captionAnimateTimeouts.length - 1; a > -1; a--) {  
						clearTimeout(this._captionAnimateTimeouts.splice(a, 1));
					}
				}
				if(this._captionAnimateProperties.length > 0) {
					var cItemTemp;
					for(var k = this._captionAnimateProperties.length - 1; k > -1; k--) {  
						cItemTemp = this._captionAnimateProperties[k];
						if(cItemTemp != undefined) {
							cItemTemp.captionItem.css(cItemTemp.css);
						}
						this._captionAnimateProperties.splice(k, 1);
						
					}
				}
			
				// parse each caption item on slide
				for(var i = 0; i < captionItems.length; i++) {
					currItem = $(captionItems[i]);			
					
					
					effectsObject = {};
					fadeEnabled = false;
					moveEnabled = false;
					moveEffectProperty = "";
					
					
					
					if(currItem.attr("data-show-effect") == undefined) {
						currEffects = this.settings.captionShowEffects;	
					} else {
						currEffects = currItem.attr("data-show-effect").split(" ");
					}
					
					
					// parse each effect in caption
					for(var q = 0; q < currEffects.length; q++) {			
						
						if(fadeEnabled && moveEnabled) {
							break;	
						}			
					
						effectName = currEffects[q].toLowerCase();
						
						if(!fadeEnabled && effectName == "fade") {
							fadeEnabled = true;
							effectsObject['opacity'] = 1;
						} else if(moveEnabled) {
							break;
						} else if(effectName == "movetop") {
							moveEffectProperty = "margin-top";
						} else  if(effectName == "moveleft") {
							moveEffectProperty = "margin-left";
						} else  if(effectName == "movebottom") {						
							moveEffectProperty = "margin-bottom";
						} else  if(effectName == "moveright") {
							moveEffectProperty = "margin-right";
						}
						
						if(moveEffectProperty != "") {
							effectsObject['moveProp'] = moveEffectProperty;						
							effectsObject['moveStartPos'] = parseInt(currItem.css(moveEffectProperty));
							moveEnabled = true;
						}
					
						
						
					}
					
					moveOffset = parseInt(currItem.attr("data-move-offset"));					
					if(isNaN(moveOffset)) {					
						moveOffset = this.settings.captionMoveOffset;
					}
					
					
					delay = parseInt(currItem.attr("data-delay"));
					if(isNaN(delay)) {
						delay = self.settings.captionShowDelay * i + 10;
					}
					
					speed = parseInt(currItem.attr("data-speed"));
					if(isNaN(speed)) {
						speed = self.settings.captionShowSpeed;
					}
					
					easing = currItem.attr("data-easing");
					if(easing == undefined) {
						easing = self.settings.captionShowEasing;
					}
					
					newEffectObj = {};
					
					
					if(moveEnabled) {	
						moveProp = effectsObject.moveProp;
							
						if(moveProp == "margin-right") {						
							moveProp = "margin-left";
							newEffectObj[moveProp] = effectsObject.moveStartPos + moveOffset + "px";						
						} else if(moveProp == "margin-bottom") {
							moveProp = "margin-top";
							newEffectObj[moveProp] = effectsObject.moveStartPos + moveOffset + "px";	
						} else {
							newEffectObj[moveProp] = effectsObject.moveStartPos - moveOffset + "px";				
						}
							
						
					}
					if(!self._removeFadeAnimation && fadeEnabled) {
						newEffectObj.opacity = 0;
					}
					
					currItem.hide().css(newEffectObj);	
					
				
					
					if(moveEnabled) {	
						newEffectObj[moveProp] = effectsObject.moveStartPos + "px"; 
					}
					if(!self._removeFadeAnimation && fadeEnabled) {
						newEffectObj.opacity = 1;
					}	
					
						
					this._captionAnimateProperties.push({captionItem:currItem, css:newEffectObj});
					
					this._captionAnimateTimeouts.push(setTimeout((function (cItem, animateData, cSpeed, cEasing, cId, objFadeEnabled) {	
						return function() {	
								delete self._captionAnimateProperties[cId];
								cItem.show().animate(animateData, cSpeed, cEasing);
											
						};
					})(currItem, newEffectObj, speed, easing, i, fadeEnabled), delay));				
				}		
			}			
			
		}	/* _showCaption end */
	}; /* RoyalSlider.prototype end */

	/* Good Luck! :) */







	
    $.fn.royalSlider = function(options) {    	
    	return this.each(function(){
    		var royalSlider = new RoyalSlider($(this), options);
    		$(this).data("royalSlider", royalSlider);
        });
    };

    $.fn.royalSlider.defaults = {
		directionNavEnabled:true,               // Direction (arrow) navigation (true or false)
		directionNavAutoHide:false,             // Direction (arrow) navigation auto hide on hover. (On touch devices arrows are always shown)
		
		slideTransitionSpeed:400,               // Slide transition speed in ms (1000ms = 1s)
		slideTransitionEasing:"easeInOutSine",  // Easing type for slide transition. Types: http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html
		
		captionAnimationEnabled:true,           // Set to false if you want to remove all animations from captions  
		captionShowEffects:["fade","moveleft"], // Default array of effects: 
												// ["fade" or "" + "moveleft", or "moveright", or "movetop", or "movebottom"]
		captionMoveOffset:20,                   // Default distance for move effect in px
		captionShowSpeed:400,                   // Default caption show speed in ms
		captionShowEasing:"easeOutCubic",       // Default caption show easing
		captionShowDelay:200,                   // Default delay between captions on one slide show
		
		controlNavEnabled:true,                 // Control navigation (bullets, thumbs)  enabled
		controlNavThumbs:false,	                // Use thumbs for control navigation (use data-thumb="myThumb.jpg" attribute in html royalSlide item)
		controlNavThumbsNavigation:true,        // Enables navigation for thumbs
		controlNavThumbsSpeed:400,				// Thumbnails navigation move speed (1000ms = 1s)
		controlNavThumbsEasing:"easeInOutSine", // Thumbnails navigation easing type
		
		slideshowEnabled:true,                 // Autoslideshow enabled          
		slideshowDelay:5000,                    // Delay between slides in slideshow
		slideshowPauseOnHover:true,             // Pause slideshow on hover
		slideshowAutoStart:true,                // Auto start slideshow 
		
		welcomeScreenEnabled:true,              // Welcome (loading) screen enabled
		welcomeScreenShowSpeed:500,             // Welcome screen fade out speed
		
		minSlideOffset:20,                      // Minimum distance in pixels to show next slide while dragging
		hideArrowOnLastSlide:false,             // Auto hide right arrow on last slide and left on first slide. Always true for touch devices.
		
		removeCaptionsOpacityInIE8:false,        // If animated caption with fade effect has no background color, so turn this option on. 
                                                // Fix for pixelated text bug in IE8 and lower. Removes fade effect animation.
		
		beforeSlideChange: function(){},        // Callback, triggers before slide transition
		afterSlideChange: function(){},         // Callback, triggers after slide transition
		
		loadingComplete: function() {}          // Callback, triggers after loading complete
    };

    $.fn.royalSlider.settings = {};

})(jQuery);
