1/**
2 * BxSlider v4.1.1 - Fully loaded, responsive content slider
3 * http://bxslider.com
4 *
5 * Copyright 2012, Steven Wanderski - http://stevenwanderski.com - http://bxcreative.com
6 * Written while drinking Belgian ales and listening to jazz
7 *
8 * Released under the WTFPL license - http://sam.zoy.org/wtfpl/
9 */
10
11;(function($){
12
13	var plugin = {};
14
15	var defaults = {
16
17		// GENERAL
18		mode: 'horizontal',
19		slideSelector: '',
20		infiniteLoop: true,
21		hideControlOnEnd: false,
22		speed: 500,
23		easing: null,
24		slideMargin: 0,
25		startSlide: 0,
26		randomStart: false,
27		captions: false,
28		ticker: false,
29		tickerHover: false,
30		adaptiveHeight: false,
31		adaptiveHeightSpeed: 500,
32		video: false,
33		useCSS: true,
34		preloadImages: 'visible',
35		responsive: true,
36
37		// TOUCH
38		touchEnabled: true,
39		swipeThreshold: 50,
40		oneToOneTouch: true,
41		preventDefaultSwipeX: true,
42		preventDefaultSwipeY: false,
43
44		// PAGER
45		pager: true,
46		pagerType: 'full',
47		pagerShortSeparator: ' / ',
48		pagerSelector: null,
49		buildPager: null,
50		pagerCustom: null,
51
52		// CONTROLS
53		controls: true,
54		nextText: 'Next',
55		prevText: 'Prev',
56		nextSelector: null,
57		prevSelector: null,
58		autoControls: false,
59		startText: 'Start',
60		stopText: 'Stop',
61		autoControlsCombine: false,
62		autoControlsSelector: null,
63
64		// AUTO
65		auto: false,
66		pause: 4000,
67		autoStart: true,
68		autoDirection: 'next',
69		autoHover: false,
70		autoDelay: 0,
71
72		// CAROUSEL
73		minSlides: 1,
74		maxSlides: 1,
75		moveSlides: 0,
76		slideWidth: 0,
77
78		// CALLBACKS
79		onSliderLoad: function() {},
80		onSlideBefore: function() {},
81		onSlideAfter: function() {},
82		onSlideNext: function() {},
83		onSlidePrev: function() {}
84	};
85
86	$.fn.bxSlider = function(options){
87
88		if(this.length == 0) return this;
89
90		// support mutltiple elements
91		if(this.length > 1){
92			this.each(function(){$(this).bxSlider(options)});
93			return this;
94		}
95
96		// create a namespace to be used throughout the plugin
97		var slider = {};
98		// set a reference to our slider element
99		var el = this;
100		plugin.el = this;
101
102		/**
103		 * Makes slideshow responsive
104		 */
105		// first get the original window dimens (thanks alot IE)
106		var windowWidth = $(window).width();
107		var windowHeight = $(window).height();
108
109
110
111		/**
112		 * ===================================================================================
113		 * = PRIVATE FUNCTIONS
114		 * ===================================================================================
115		 */
116
117		/**
118		 * Initializes namespace settings to be used throughout plugin
119		 */
120		var init = function(){
121			// merge user-supplied options with the defaults
122			slider.settings = $.extend({}, defaults, options);
123			// parse slideWidth setting
124			slider.settings.slideWidth = parseInt(slider.settings.slideWidth);
125			// store the original children
126			slider.children = el.children(slider.settings.slideSelector);
127			// check if actual number of slides is less than minSlides / maxSlides
128			if(slider.children.length < slider.settings.minSlides) slider.settings.minSlides = slider.children.length;
129			if(slider.children.length < slider.settings.maxSlides) slider.settings.maxSlides = slider.children.length;
130			// if random start, set the startSlide setting to random number
131			if(slider.settings.randomStart) slider.settings.startSlide = Math.floor(Math.random() * slider.children.length);
132			// store active slide information
133			slider.active = { index: slider.settings.startSlide };
134			// store if the slider is in carousel mode (displaying / moving multiple slides)
135			slider.carousel = slider.settings.minSlides > 1 || slider.settings.maxSlides > 1;
136			// if carousel, force preloadImages = 'all'
137			if(slider.carousel) slider.settings.preloadImages = 'all';
138			// calculate the min / max width thresholds based on min / max number of slides
139			// used to setup and update carousel slides dimensions
140			slider.minThreshold = (slider.settings.minSlides * slider.settings.slideWidth) + ((slider.settings.minSlides - 1) * slider.settings.slideMargin);
141			slider.maxThreshold = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin);
142			// store the current state of the slider (if currently animating, working is true)
143			slider.working = false;
144			// initialize the controls object
145			slider.controls = {};
146			// initialize an auto interval
147			slider.interval = null;
148			// determine which property to use for transitions
149			slider.animProp = slider.settings.mode == 'vertical' ? 'top' : 'left';
150			// determine if hardware acceleration can be used
151			slider.usingCSS = slider.settings.useCSS && slider.settings.mode != 'fade' && (function(){
152				// create our test div element
153				var div = document.createElement('div');
154				// css transition properties
155				var props = ['WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective'];
156				// test for each property
157				for(var i in props){
158					if(div.style[props[i]] !== undefined){
159						slider.cssPrefix = props[i].replace('Perspective', '').toLowerCase();
160						slider.animProp = '-' + slider.cssPrefix + '-transform';
161						return true;
162					}
163				}
164				return false;
165			}());
166			// if vertical mode always make maxSlides and minSlides equal
167			if(slider.settings.mode == 'vertical') slider.settings.maxSlides = slider.settings.minSlides;
168			// save original style data
169			el.data("origStyle", el.attr("style"));
170			el.children(slider.settings.slideSelector).each(function() {
171			  $(this).data("origStyle", $(this).attr("style"));
172			});
173			// perform all DOM / CSS modifications
174			setup();
175		};
176
177		/**
178		 * Performs all DOM and CSS modifications
179		 */
180		var setup = function(){
181			// wrap el in a wrapper
182			el.wrap('<div class="bx-wrapper"><div class="bx-viewport"></div></div>');
183			// store a namspace reference to .bx-viewport
184			slider.viewport = el.parent();
185			// add a loading div to display while images are loading
186			slider.loader = $('<div class="bx-loading" />');
187			slider.viewport.prepend(slider.loader);
188			// set el to a massive width, to hold any needed slides
189			// also strip any margin and padding from el
190			el.css({
191				width: slider.settings.mode == 'horizontal' ? (slider.children.length * 100 + 215) + '%' : 'auto',
192				position: 'relative'
193			});
194			// if using CSS, add the easing property
195			if(slider.usingCSS && slider.settings.easing){
196				el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing);
197			// if not using CSS and no easing value was supplied, use the default JS animation easing (swing)
198			}else if(!slider.settings.easing){
199				slider.settings.easing = 'swing';
200			}
201			var slidesShowing = getNumberSlidesShowing();
202			// make modifications to the viewport (.bx-viewport)
203			slider.viewport.css({
204				width: '100%',
205				overflow: 'hidden',
206				position: 'relative'
207			});
208			slider.viewport.parent().css({
209				maxWidth: getViewportMaxWidth()
210			});
211			// make modification to the wrapper (.bx-wrapper)
212			if(!slider.settings.pager) {
213				slider.viewport.parent().css({
214				margin: '0 auto 0px'
215				});
216			}
217			// apply css to all slider children
218			slider.children.css({
219				'float': slider.settings.mode == 'horizontal' ? 'left' : 'none',
220				listStyle: 'none',
221				position: 'relative'
222			});
223			// apply the calculated width after the float is applied to prevent scrollbar interference
224			slider.children.css('width', getSlideWidth());
225			// if slideMargin is supplied, add the css
226			if(slider.settings.mode == 'horizontal' && slider.settings.slideMargin > 0) slider.children.css('marginRight', slider.settings.slideMargin);
227			if(slider.settings.mode == 'vertical' && slider.settings.slideMargin > 0) slider.children.css('marginBottom', slider.settings.slideMargin);
228			// if "fade" mode, add positioning and z-index CSS
229			if(slider.settings.mode == 'fade'){
230				slider.children.css({
231					position: 'absolute',
232					zIndex: 0,
233					display: 'none'
234				});
235				// prepare the z-index on the showing element
236				slider.children.eq(slider.settings.startSlide).css({zIndex: 50, display: 'block'});
237			}
238			// create an element to contain all slider controls (pager, start / stop, etc)
239			slider.controls.el = $('<div class="bx-controls" />');
240			// if captions are requested, add them
241			if(slider.settings.captions) appendCaptions();
242			// check if startSlide is last slide
243			slider.active.last = slider.settings.startSlide == getPagerQty() - 1;
244			// if video is true, set up the fitVids plugin
245			if(slider.settings.video) el.fitVids();
246			// set the default preload selector (visible)
247			var preloadSelector = slider.children.eq(slider.settings.startSlide);
248			if (slider.settings.preloadImages == "all") preloadSelector = slider.children;
249			// only check for control addition if not in "ticker" mode
250			if(!slider.settings.ticker){
251				// if pager is requested, add it
252				if(slider.settings.pager) appendPager();
253				// if controls are requested, add them
254				if(slider.settings.controls) appendControls();
255				// if auto is true, and auto controls are requested, add them
256				if(slider.settings.auto && slider.settings.autoControls) appendControlsAuto();
257				// if any control option is requested, add the controls wrapper
258				if(slider.settings.controls || slider.settings.autoControls || slider.settings.pager) slider.viewport.after(slider.controls.el);
259			// if ticker mode, do not allow a pager
260			}else{
261				slider.settings.pager = false;
262			}
263			// preload all images, then perform final DOM / CSS modifications that depend on images being loaded
264			loadElements(preloadSelector, start);
265		};
266
267		var loadElements = function(selector, callback){
268			var total = selector.find('img, iframe').length;
269			if (total == 0){
270				callback();
271				return;
272			}
273			var count = 0;
274			var checkIfAllLoaded = function(){
275				if(++count == total) callback();
276			};
277			selector.find('img, iframe').each(function(){
278				var el = $(this);
279				if(el.is('img')){
280					// Use temp image instead of adding timestamp to prevent loading additional image:
281					var img = new Image(),
282						loaded = false;
283
284					$(img).on('load', function (){
285						if (loaded) return;
286						loaded = true;
287						setTimeout(checkIfAllLoaded, 0);
288					});
289
290					img.src = el.attr('src');
291
292					// Check if image has width, that means it is loaded already.
293					// This is because some browsers will not trigger load event if it's from cache.
294					setTimeout(function (){
295						if (img.width && !loaded){
296							loaded = true;
297							setTimeout(checkIfAllLoaded, 0);
298						}
299					}, 0);
300					return;
301				}
302				el.on('load', function(){
303					setTimeout(checkIfAllLoaded, 0);
304				});
305			});
306		};
307
308		/**
309		 * Start the slider
310		 */
311		var start = function(){
312			// if infinite loop, prepare additional slides
313			if(slider.settings.infiniteLoop && slider.settings.mode != 'fade' && !slider.settings.ticker){
314				var slice = slider.settings.mode == 'vertical' ? slider.settings.minSlides : slider.settings.maxSlides;
315				var sliceAppend = slider.children.slice(0, slice).clone().addClass('bx-clone');
316				var slicePrepend = slider.children.slice(-slice).clone().addClass('bx-clone');
317				el.append(sliceAppend).prepend(slicePrepend);
318			}
319			// remove the loading DOM element
320			slider.loader.remove();
321			// set the left / top position of "el"
322			setSlidePosition();
323			// if "vertical" mode, always use adaptiveHeight to prevent odd behavior
324			if (slider.settings.mode == 'vertical') slider.settings.adaptiveHeight = true;
325			// set the viewport height
326			slider.viewport.height(getViewportHeight());
327			// make sure everything is positioned just right (same as a window resize)
328			el.redrawSlider();
329			// onSliderLoad callback
330			slider.settings.onSliderLoad(slider.active.index);
331			// slider has been fully initialized
332			slider.initialized = true;
333			// bind the resize call to the window
334			if (slider.settings.responsive) $(window).bind('resize', resizeWindow);
335			// if auto is true, start the show
336			if (slider.settings.auto && slider.settings.autoStart && slider.children.length > 1) initAuto();
337			// if ticker is true, start the ticker
338			if (slider.settings.ticker) initTicker();
339			// if pager is requested, make the appropriate pager link active
340			if (slider.settings.pager) updatePagerActive(slider.settings.startSlide);
341			// check for any updates to the controls (like hideControlOnEnd updates)
342			if (slider.settings.controls) updateDirectionControls();
343			// if touchEnabled is true, setup the touch events
344			if (slider.settings.touchEnabled && !slider.settings.ticker) initTouch();
345		};
346
347		/**
348		 * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value
349		 */
350		var getViewportHeight = function(){
351			var height = 0;
352			// first determine which children (slides) should be used in our height calculation
353			var children = $();
354			// if mode is not "vertical" and adaptiveHeight is false, include all children
355			if(slider.settings.mode != 'vertical' && !slider.settings.adaptiveHeight){
356				children = slider.children;
357			}else{
358				// if not carousel, return the single active child
359				if(!slider.carousel){
360					children = slider.children.eq(slider.active.index);
361				// if carousel, return a slice of children
362				}else{
363					// get the individual slide index
364					var currentIndex = slider.settings.moveSlides == 1 ? slider.active.index : slider.active.index * getMoveBy();
365					// add the current slide to the children
366					children = slider.children.eq(currentIndex);
367					// cycle through the remaining "showing" slides
368					for (i = 1; i <= slider.settings.maxSlides - 1; i++){
369						// if looped back to the start
370						if(currentIndex + i >= slider.children.length){
371							children = children.add(slider.children.eq(i - 1));
372						}else{
373							children = children.add(slider.children.eq(currentIndex + i));
374						}
375					}
376				}
377			}
378			// if "vertical" mode, calculate the sum of the heights of the children
379			if(slider.settings.mode == 'vertical'){
380				children.each(function(index) {
381				  height += $(this).outerHeight();
382				});
383				// add user-supplied margins
384				if(slider.settings.slideMargin > 0){
385					height += slider.settings.slideMargin * (slider.settings.minSlides - 1);
386				}
387			// if not "vertical" mode, calculate the max height of the children
388			}else{
389				height = Math.max.apply(Math, children.map(function(){
390					return $(this).outerHeight(false);
391				}).get());
392			}
393			return height;
394		};
395
396		/**
397		 * Returns the calculated width to be used for the outer wrapper / viewport
398		 */
399		var getViewportMaxWidth = function(){
400			var width = '100%';
401			if(slider.settings.slideWidth > 0){
402				if(slider.settings.mode == 'horizontal'){
403					width = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin);
404				}else{
405					width = slider.settings.slideWidth;
406				}
407			}
408			return width;
409		};
410
411		/**
412		 * Returns the calculated width to be applied to each slide
413		 */
414		var getSlideWidth = function(){
415			// start with any user-supplied slide width
416			var newElWidth = slider.settings.slideWidth;
417			// get the current viewport width
418			var wrapWidth = slider.viewport.width();
419			// if slide width was not supplied, or is larger than the viewport use the viewport width
420			if(slider.settings.slideWidth == 0 ||
421				(slider.settings.slideWidth > wrapWidth && !slider.carousel) ||
422				slider.settings.mode == 'vertical'){
423				newElWidth = wrapWidth;
424			// if carousel, use the thresholds to determine the width
425			}else if(slider.settings.maxSlides > 1 && slider.settings.mode == 'horizontal'){
426				if(wrapWidth > slider.maxThreshold){
427					// newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.maxSlides - 1))) / slider.settings.maxSlides;
428				}else if(wrapWidth < slider.minThreshold){
429					newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.minSlides - 1))) / slider.settings.minSlides;
430				}
431			}
432			return newElWidth;
433		};
434
435		/**
436		 * Returns the number of slides currently visible in the viewport (includes partially visible slides)
437		 */
438		var getNumberSlidesShowing = function(){
439			var slidesShowing = 1;
440			if(slider.settings.mode == 'horizontal' && slider.settings.slideWidth > 0){
441				// if viewport is smaller than minThreshold, return minSlides
442				if(slider.viewport.width() < slider.minThreshold){
443					slidesShowing = slider.settings.minSlides;
444				// if viewport is larger than minThreshold, return maxSlides
445				}else if(slider.viewport.width() > slider.maxThreshold){
446					slidesShowing = slider.settings.maxSlides;
447				// if viewport is between min / max thresholds, divide viewport width by first child width
448				}else{
449					var childWidth = slider.children.first().width();
450					slidesShowing = Math.floor(slider.viewport.width() / childWidth);
451				}
452			// if "vertical" mode, slides showing will always be minSlides
453			}else if(slider.settings.mode == 'vertical'){
454				slidesShowing = slider.settings.minSlides;
455			}
456			return slidesShowing;
457		};
458
459		/**
460		 * Returns the number of pages (one full viewport of slides is one "page")
461		 */
462		var getPagerQty = function(){
463			var pagerQty = 0;
464			// if moveSlides is specified by the user
465			if(slider.settings.moveSlides > 0){
466				if(slider.settings.infiniteLoop){
467					pagerQty = slider.children.length / getMoveBy();
468				}else{
469					// use a while loop to determine pages
470					var breakPoint = 0;
471					var counter = 0;
472					// when breakpoint goes above children length, counter is the number of pages
473					while (breakPoint < slider.children.length){
474						++pagerQty;
475						breakPoint = counter + getNumberSlidesShowing();
476						counter += slider.settings.moveSlides <= getNumberSlidesShowing() ? slider.settings.moveSlides : getNumberSlidesShowing();
477					}
478				}
479			// if moveSlides is 0 (auto) divide children length by sides showing, then round up
480			}else{
481				pagerQty = Math.ceil(slider.children.length / getNumberSlidesShowing());
482			}
483			return pagerQty;
484		};
485
486		/**
487		 * Returns the number of indivual slides by which to shift the slider
488		 */
489		var getMoveBy = function(){
490			// if moveSlides was set by the user and moveSlides is less than number of slides showing
491			if(slider.settings.moveSlides > 0 && slider.settings.moveSlides <= getNumberSlidesShowing()){
492				return slider.settings.moveSlides;
493			}
494			// if moveSlides is 0 (auto)
495			return getNumberSlidesShowing();
496		};
497
498		/**
499		 * Sets the slider's (el) left or top position
500		 */
501		var setSlidePosition = function(){
502			// if last slide, not infinite loop, and number of children is larger than specified maxSlides
503			if(slider.children.length > slider.settings.maxSlides && slider.active.last && !slider.settings.infiniteLoop){
504				if (slider.settings.mode == 'horizontal'){
505					// get the last child's position
506					var lastChild = slider.children.last();
507					var position = lastChild.position();
508					// set the left position
509					setPositionProperty(-(position.left - (slider.viewport.width() - lastChild.width())), 'reset', 0);
510				}else if(slider.settings.mode == 'vertical'){
511					// get the last showing index's position
512					var lastShowingIndex = slider.children.length - slider.settings.minSlides;
513					var position = slider.children.eq(lastShowingIndex).position();
514					// set the top position
515					setPositionProperty(-position.top, 'reset', 0);
516				}
517			// if not last slide
518			}else{
519				// get the position of the first showing slide
520				var position = slider.children.eq(slider.active.index * getMoveBy()).position();
521				// check for last slide
522				if (slider.active.index == getPagerQty() - 1) slider.active.last = true;
523				// set the repective position
524				if (position != undefined){
525					if (slider.settings.mode == 'horizontal') setPositionProperty(-position.left, 'reset', 0);
526					else if (slider.settings.mode == 'vertical') setPositionProperty(-position.top, 'reset', 0);
527				}
528			}
529		};
530
531		/**
532		 * Sets the el's animating property position (which in turn will sometimes animate el).
533		 * If using CSS, sets the transform property. If not using CSS, sets the top / left property.
534		 *
535		 * @param value (int)
536		 *  - the animating property's value
537		 *
538		 * @param type (string) 'slider', 'reset', 'ticker'
539		 *  - the type of instance for which the function is being
540		 *
541		 * @param duration (int)
542		 *  - the amount of time (in ms) the transition should occupy
543		 *
544		 * @param params (array) optional
545		 *  - an optional parameter containing any variables that need to be passed in
546		 */
547		var setPositionProperty = function(value, type, duration, params){
548			// use CSS transform
549			if(slider.usingCSS){
550				// determine the translate3d value
551				var propValue = slider.settings.mode == 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)';
552				// add the CSS transition-duration
553				el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's');
554				if(type == 'slide'){
555					// set the property value
556					el.css(slider.animProp, propValue);
557					// bind a callback method - executes when CSS transition completes
558					el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){
559						// unbind the callback
560						el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd');
561						updateAfterSlideTransition();
562					});
563				}else if(type == 'reset'){
564					el.css(slider.animProp, propValue);
565				}else if(type == 'ticker'){
566					// make the transition use 'linear'
567					el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear');
568					el.css(slider.animProp, propValue);
569					// bind a callback method - executes when CSS transition completes
570					el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){
571						// unbind the callback
572						el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd');
573						// reset the position
574						setPositionProperty(params['resetValue'], 'reset', 0);
575						// start the loop again
576						tickerLoop();
577					});
578				}
579			// use JS animate
580			}else{
581				var animateObj = {};
582				animateObj[slider.animProp] = value;
583				if(type == 'slide'){
584					el.animate(animateObj, duration, slider.settings.easing, function(){
585						updateAfterSlideTransition();
586					});
587				}else if(type == 'reset'){
588					el.css(slider.animProp, value)
589				}else if(type == 'ticker'){
590					el.animate(animateObj, speed, 'linear', function(){
591						setPositionProperty(params['resetValue'], 'reset', 0);
592						// run the recursive loop after animation
593						tickerLoop();
594					});
595				}
596			}
597		};
598
599		/**
600		 * Populates the pager with proper amount of pages
601		 */
602		var populatePager = function(){
603			var pagerHtml = '';
604			var pagerQty = getPagerQty();
605            if(pagerQty <= 1) return;
606			// loop through each pager item
607			for(var i=0; i < pagerQty; i++){
608				var linkContent = '';
609				// if a buildPager function is supplied, use it to get pager link value, else use index + 1
610				if(slider.settings.buildPager && $.isFunction(slider.settings.buildPager)){
611					linkContent = slider.settings.buildPager(i);
612					slider.pagerEl.addClass('bx-custom-pager');
613				}else{
614					linkContent = i + 1;
615					slider.pagerEl.addClass('bx-default-pager');
616				}
617				// var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1;
618				// add the markup to the string
619				pagerHtml += '<div class="bx-pager-item"><a href="" data-slide-index="' + i + '" class="bx-pager-link">' + linkContent + '</a></div>';
620			};
621			// populate the pager element with pager links
622			slider.pagerEl.html(pagerHtml);
623		};
624
625		/**
626		 * Appends the pager to the controls element
627		 */
628		var appendPager = function(){
629			if(!slider.settings.pagerCustom){
630				// create the pager DOM element
631				slider.pagerEl = $('<div class="bx-pager" />');
632				// if a pager selector was supplied, populate it with the pager
633				if(slider.settings.pagerSelector){
634					$(slider.settings.pagerSelector).html(slider.pagerEl);
635				// if no pager selector was supplied, add it after the wrapper
636				}else{
637					slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl);
638				}
639				// populate the pager
640				populatePager();
641			}else{
642				slider.pagerEl = $(slider.settings.pagerCustom);
643			}
644			// assign the pager click binding
645			slider.pagerEl.delegate('a', 'click', clickPagerBind);
646		};
647
648		/**
649		 * Appends prev / next controls to the controls element
650		 */
651		var appendControls = function(){
652			slider.controls.next = $('<a class="bx-next" href="">' + slider.settings.nextText + '</a>');
653			slider.controls.prev = $('<a class="bx-prev" href="">' + slider.settings.prevText + '</a>');
654			// bind click actions to the controls
655			slider.controls.next.bind('click', clickNextBind);
656			slider.controls.prev.bind('click', clickPrevBind);
657			// if nextSlector was supplied, populate it
658			if(slider.settings.nextSelector){
659				$(slider.settings.nextSelector).append(slider.controls.next);
660			}
661			// if prevSlector was supplied, populate it
662			if(slider.settings.prevSelector){
663				$(slider.settings.prevSelector).append(slider.controls.prev);
664			}
665			// if no custom selectors were supplied
666			if(!slider.settings.nextSelector && !slider.settings.prevSelector){
667				// add the controls to the DOM
668				slider.controls.directionEl = $('<div class="bx-controls-direction" />');
669				// add the control elements to the directionEl
670				slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next);
671				// slider.viewport.append(slider.controls.directionEl);
672				slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl);
673			}
674		};
675
676		/**
677		 * Appends start / stop auto controls to the controls element
678		 */
679		var appendControlsAuto = function(){
680			slider.controls.start = $('<div class="bx-controls-auto-item"><a class="bx-start" href="">' + slider.settings.startText + '</a></div>');
681			slider.controls.stop = $('<div class="bx-controls-auto-item"><a class="bx-stop" href="">' + slider.settings.stopText + '</a></div>');
682			// add the controls to the DOM
683			slider.controls.autoEl = $('<div class="bx-controls-auto" />');
684			// bind click actions to the controls
685			slider.controls.autoEl.delegate('.bx-start', 'click', clickStartBind);
686			slider.controls.autoEl.delegate('.bx-stop', 'click', clickStopBind);
687			// if autoControlsCombine, insert only the "start" control
688			if(slider.settings.autoControlsCombine){
689				slider.controls.autoEl.append(slider.controls.start);
690			// if autoControlsCombine is false, insert both controls
691			}else{
692				slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop);
693			}
694			// if auto controls selector was supplied, populate it with the controls
695			if(slider.settings.autoControlsSelector){
696				$(slider.settings.autoControlsSelector).html(slider.controls.autoEl);
697			// if auto controls selector was not supplied, add it after the wrapper
698			}else{
699				slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl);
700			}
701			// update the auto controls
702			updateAutoControls(slider.settings.autoStart ? 'stop' : 'start');
703		};
704
705		/**
706		 * Appends image captions to the DOM
707		 */
708		var appendCaptions = function(){
709			// cycle through each child
710			slider.children.each(function(index){
711				// get the image title attribute
712				var title = $(this).find('img:first').attr('title');
713				// append the caption
714				if (title != undefined && ('' + title).length) {
715                    $(this).append('<div class="bx-caption"><span>' + title + '</span></div>');
716                }
717			});
718		};
719
720		/**
721		 * Click next binding
722		 *
723		 * @param e (event)
724		 *  - DOM event object
725		 */
726		var clickNextBind = function(e){
727			// if auto show is running, stop it
728			if (slider.settings.auto) el.stopAuto();
729			el.goToNextSlide();
730			e.preventDefault();
731		};
732
733		/**
734		 * Click prev binding
735		 *
736		 * @param e (event)
737		 *  - DOM event object
738		 */
739		var clickPrevBind = function(e){
740			// if auto show is running, stop it
741			if (slider.settings.auto) el.stopAuto();
742			el.goToPrevSlide();
743			e.preventDefault();
744		};
745
746		/**
747		 * Click start binding
748		 *
749		 * @param e (event)
750		 *  - DOM event object
751		 */
752		var clickStartBind = function(e){
753			el.startAuto();
754			e.preventDefault();
755		};
756
757		/**
758		 * Click stop binding
759		 *
760		 * @param e (event)
761		 *  - DOM event object
762		 */
763		var clickStopBind = function(e){
764			el.stopAuto();
765			e.preventDefault();
766		};
767
768		/**
769		 * Click pager binding
770		 *
771		 * @param e (event)
772		 *  - DOM event object
773		 */
774		var clickPagerBind = function(e){
775			// if auto show is running, stop it
776			if (slider.settings.auto) el.stopAuto();
777			var pagerLink = $(e.currentTarget);
778			var pagerIndex = parseInt(pagerLink.attr('data-slide-index'));
779			// if clicked pager link is not active, continue with the goToSlide call
780			if(pagerIndex != slider.active.index) el.goToSlide(pagerIndex);
781			e.preventDefault();
782		};
783
784		/**
785		 * Updates the pager links with an active class
786		 *
787		 * @param slideIndex (int)
788		 *  - index of slide to make active
789		 */
790		var updatePagerActive = function(slideIndex){
791			// if "short" pager type
792			var len = slider.children.length; // nb of children
793			if(slider.settings.pagerType == 'short'){
794				if(slider.settings.maxSlides > 1) {
795					len = Math.ceil(slider.children.length/slider.settings.maxSlides);
796				}
797				slider.pagerEl.html( (slideIndex + 1) + slider.settings.pagerShortSeparator + len);
798				return;
799			}
800			// remove all pager active classes
801			slider.pagerEl.find('a').removeClass('active');
802			// apply the active class for all pagers
803			slider.pagerEl.each(function(i, el) { $(el).find('a').eq(slideIndex).addClass('active'); });
804		};
805
806		/**
807		 * Performs needed actions after a slide transition
808		 */
809		var updateAfterSlideTransition = function(){
810			// if infinte loop is true
811			if(slider.settings.infiniteLoop){
812				var position = '';
813				// first slide
814				if(slider.active.index == 0){
815					// set the new position
816					position = slider.children.eq(0).position();
817				// carousel, last slide
818				}else if(slider.active.index == getPagerQty() - 1 && slider.carousel){
819					position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position();
820				// last slide
821				}else if(slider.active.index == slider.children.length - 1){
822					position = slider.children.eq(slider.children.length - 1).position();
823				}
824				if (slider.settings.mode == 'horizontal') { setPositionProperty(-position.left, 'reset', 0);; }
825				else if (slider.settings.mode == 'vertical') { setPositionProperty(-position.top, 'reset', 0);; }
826			}
827			// declare that the transition is complete
828			slider.working = false;
829			// onSlideAfter callback
830			slider.settings.onSlideAfter(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index);
831		};
832
833		/**
834		 * Updates the auto controls state (either active, or combined switch)
835		 *
836		 * @param state (string) "start", "stop"
837		 *  - the new state of the auto show
838		 */
839		var updateAutoControls = function(state){
840			// if autoControlsCombine is true, replace the current control with the new state
841			if(slider.settings.autoControlsCombine){
842				slider.controls.autoEl.html(slider.controls[state]);
843			// if autoControlsCombine is false, apply the "active" class to the appropriate control
844			}else{
845				slider.controls.autoEl.find('a').removeClass('active');
846				slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active');
847			}
848		};
849
850		/**
851		 * Updates the direction controls (checks if either should be hidden)
852		 */
853		var updateDirectionControls = function(){
854			if(getPagerQty() == 1){
855				slider.controls.prev.addClass('disabled');
856				slider.controls.next.addClass('disabled');
857			}else if(!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd){
858				// if first slide
859				if (slider.active.index == 0){
860					slider.controls.prev.addClass('disabled');
861					slider.controls.next.removeClass('disabled');
862				// if last slide
863				}else if(slider.active.index == getPagerQty() - 1){
864					slider.controls.next.addClass('disabled');
865					slider.controls.prev.removeClass('disabled');
866				// if any slide in the middle
867				}else{
868					slider.controls.prev.removeClass('disabled');
869					slider.controls.next.removeClass('disabled');
870				}
871			}
872		};
873
874		/**
875		 * Initialzes the auto process
876		 */
877		var initAuto = function(){
878			// if autoDelay was supplied, launch the auto show using a setTimeout() call
879			if(slider.settings.autoDelay > 0){
880				var timeout = setTimeout(el.startAuto, slider.settings.autoDelay);
881			// if autoDelay was not supplied, start the auto show normally
882			}else{
883				el.startAuto();
884			}
885			// if autoHover is requested
886			if(slider.settings.autoHover){
887				// on el hover
888				el.hover(function(){
889					// if the auto show is currently playing (has an active interval)
890					if(slider.interval){
891						// stop the auto show and pass true agument which will prevent control update
892						el.stopAuto(true);
893						// create a new autoPaused value which will be used by the relative "mouseout" event
894						slider.autoPaused = true;
895					}
896				}, function(){
897					// if the autoPaused value was created be the prior "mouseover" event
898					if(slider.autoPaused){
899						// start the auto show and pass true agument which will prevent control update
900						el.startAuto(true);
901						// reset the autoPaused value
902						slider.autoPaused = null;
903					}
904				});
905			}
906		};
907
908		/**
909		 * Initialzes the ticker process
910		 */
911		var initTicker = function(){
912			var startPosition = 0;
913			// if autoDirection is "next", append a clone of the entire slider
914			if(slider.settings.autoDirection == 'next'){
915				el.append(slider.children.clone().addClass('bx-clone'));
916			// if autoDirection is "prev", prepend a clone of the entire slider, and set the left position
917			}else{
918				el.prepend(slider.children.clone().addClass('bx-clone'));
919				var position = slider.children.first().position();
920				startPosition = slider.settings.mode == 'horizontal' ? -position.left : -position.top;
921			}
922			setPositionProperty(startPosition, 'reset', 0);
923			// do not allow controls in ticker mode
924			slider.settings.pager = false;
925			slider.settings.controls = false;
926			slider.settings.autoControls = false;
927			// if autoHover is requested
928			if(slider.settings.tickerHover && !slider.usingCSS){
929				// on el hover
930				slider.viewport.hover(function(){
931					el.stop();
932				}, function(){
933					// calculate the total width of children (used to calculate the speed ratio)
934					var totalDimens = 0;
935					slider.children.each(function(index){
936					  totalDimens += slider.settings.mode == 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true);
937					});
938					// calculate the speed ratio (used to determine the new speed to finish the paused animation)
939					var ratio = slider.settings.speed / totalDimens;
940					// determine which property to use
941					var property = slider.settings.mode == 'horizontal' ? 'left' : 'top';
942					// calculate the new speed
943					var newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property)))));
944					tickerLoop(newSpeed);
945				});
946			}
947			// start the ticker loop
948			tickerLoop();
949		};
950
951		/**
952		 * Runs a continuous loop, news ticker-style
953		 */
954		var tickerLoop = function(resumeSpeed){
955			speed = resumeSpeed ? resumeSpeed : slider.settings.speed;
956			var position = {left: 0, top: 0};
957			var reset = {left: 0, top: 0};
958			// if "next" animate left position to last child, then reset left to 0
959			if(slider.settings.autoDirection == 'next'){
960				position = el.find('.bx-clone').first().position();
961			// if "prev" animate left position to 0, then reset left to first non-clone child
962			}else{
963				reset = slider.children.first().position();
964			}
965			var animateProperty = slider.settings.mode == 'horizontal' ? -position.left : -position.top;
966			var resetValue = slider.settings.mode == 'horizontal' ? -reset.left : -reset.top;
967			var params = {resetValue: resetValue};
968			setPositionProperty(animateProperty, 'ticker', speed, params);
969		};
970
971		/**
972		 * Initializes touch events
973		 */
974		var initTouch = function(){
975			// initialize object to contain all touch values
976			slider.touch = {
977				start: {x: 0, y: 0},
978				end: {x: 0, y: 0}
979			};
980			slider.viewport.bind('touchstart', onTouchStart);
981		};
982
983		/**
984		 * Event handler for "touchstart"
985		 *
986		 * @param e (event)
987		 *  - DOM event object
988		 */
989		var onTouchStart = function(e){
990			if(slider.working){
991				e.preventDefault();
992			}else{
993				// record the original position when touch starts
994				slider.touch.originalPos = el.position();
995				var orig = e.originalEvent;
996				// record the starting touch x, y coordinates
997				slider.touch.start.x = orig.changedTouches[0].pageX;
998				slider.touch.start.y = orig.changedTouches[0].pageY;
999				// bind a "touchmove" event to the viewport
1000				slider.viewport.bind('touchmove', onTouchMove);
1001				// bind a "touchend" event to the viewport
1002				slider.viewport.bind('touchend', onTouchEnd);
1003			}
1004		};
1005
1006		/**
1007		 * Event handler for "touchmove"
1008		 *
1009		 * @param e (event)
1010		 *  - DOM event object
1011		 */
1012		var onTouchMove = function(e){
1013			var orig = e.originalEvent;
1014			// if scrolling on y axis, do not prevent default
1015			var xMovement = Math.abs(orig.changedTouches[0].pageX - slider.touch.start.x);
1016			var yMovement = Math.abs(orig.changedTouches[0].pageY - slider.touch.start.y);
1017			// x axis swipe
1018			if((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX){
1019				e.preventDefault();
1020			// y axis swipe
1021			}else if((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY){
1022				e.preventDefault();
1023			}
1024			if(slider.settings.mode != 'fade' && slider.settings.oneToOneTouch){
1025				var value = 0;
1026				// if horizontal, drag along x axis
1027				if(slider.settings.mode == 'horizontal'){
1028					var change = orig.changedTouches[0].pageX - slider.touch.start.x;
1029					value = slider.touch.originalPos.left + change;
1030				// if vertical, drag along y axis
1031				}else{
1032					var change = orig.changedTouches[0].pageY - slider.touch.start.y;
1033					value = slider.touch.originalPos.top + change;
1034				}
1035				setPositionProperty(value, 'reset', 0);
1036			}
1037		};
1038
1039		/**
1040		 * Event handler for "touchend"
1041		 *
1042		 * @param e (event)
1043		 *  - DOM event object
1044		 */
1045		var onTouchEnd = function(e){
1046			slider.viewport.unbind('touchmove', onTouchMove);
1047			var orig = e.originalEvent;
1048			var value = 0;
1049			// record end x, y positions
1050			slider.touch.end.x = orig.changedTouches[0].pageX;
1051			slider.touch.end.y = orig.changedTouches[0].pageY;
1052			// if fade mode, check if absolute x distance clears the threshold
1053			if(slider.settings.mode == 'fade'){
1054				var distance = Math.abs(slider.touch.start.x - slider.touch.end.x);
1055				if(distance >= slider.settings.swipeThreshold){
1056					slider.touch.start.x > slider.touch.end.x ? el.goToNextSlide() : el.goToPrevSlide();
1057					el.stopAuto();
1058				}
1059			// not fade mode
1060			}else{
1061				var distance = 0;
1062				// calculate distance and el's animate property
1063				if(slider.settings.mode == 'horizontal'){
1064					distance = slider.touch.end.x - slider.touch.start.x;
1065					value = slider.touch.originalPos.left;
1066				}else{
1067					distance = slider.touch.end.y - slider.touch.start.y;
1068					value = slider.touch.originalPos.top;
1069				}
1070				// if not infinite loop and first / last slide, do not attempt a slide transition
1071				if(!slider.settings.infiniteLoop && ((slider.active.index == 0 && distance > 0) || (slider.active.last && distance < 0))){
1072					setPositionProperty(value, 'reset', 200);
1073				}else{
1074					// check if distance clears threshold
1075					if(Math.abs(distance) >= slider.settings.swipeThreshold){
1076						distance < 0 ? el.goToNextSlide() : el.goToPrevSlide();
1077						el.stopAuto();
1078					}else{
1079						// el.animate(property, 200);
1080						setPositionProperty(value, 'reset', 200);
1081					}
1082				}
1083			}
1084			slider.viewport.unbind('touchend', onTouchEnd);
1085		};
1086
1087		/**
1088		 * Window resize event callback
1089		 */
1090		var resizeWindow = function(e){
1091			// get the new window dimens (again, thank you IE)
1092			var windowWidthNew = $(window).width();
1093			var windowHeightNew = $(window).height();
1094			// make sure that it is a true window resize
1095			// *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements
1096			// are resized. Can you just die already?*
1097			if(windowWidth != windowWidthNew || windowHeight != windowHeightNew){
1098				// set the new window dimens
1099				windowWidth = windowWidthNew;
1100				windowHeight = windowHeightNew;
1101				// update all dynamic elements
1102				el.redrawSlider();
1103			}
1104		};
1105
1106		/**
1107		 * ===================================================================================
1108		 * = PUBLIC FUNCTIONS
1109		 * ===================================================================================
1110		 */
1111
1112		/**
1113		 * Performs slide transition to the specified slide
1114		 *
1115		 * @param slideIndex (int)
1116		 *  - the destination slide's index (zero-based)
1117		 *
1118		 * @param direction (string)
1119		 *  - INTERNAL USE ONLY - the direction of travel ("prev" / "next")
1120		 */
1121		el.goToSlide = function(slideIndex, direction){
1122			// if plugin is currently in motion, ignore request
1123			if(slider.working || slider.active.index == slideIndex) return;
1124			// declare that plugin is in motion
1125			slider.working = true;
1126			// store the old index
1127			slider.oldIndex = slider.active.index;
1128			// if slideIndex is less than zero, set active index to last child (this happens during infinite loop)
1129			if(slideIndex < 0){
1130				slider.active.index = getPagerQty() - 1;
1131			// if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop)
1132			}else if(slideIndex >= getPagerQty()){
1133				slider.active.index = 0;
1134			// set active index to requested slide
1135			}else{
1136				slider.active.index = slideIndex;
1137			}
1138			// onSlideBefore, onSlideNext, onSlidePrev callbacks
1139			slider.settings.onSlideBefore(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index);
1140			if(direction == 'next'){
1141				slider.settings.onSlideNext(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index);
1142			}else if(direction == 'prev'){
1143				slider.settings.onSlidePrev(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index);
1144			}
1145			// check if last slide
1146			slider.active.last = slider.active.index >= getPagerQty() - 1;
1147			// update the pager with active class
1148			if(slider.settings.pager) updatePagerActive(slider.active.index);
1149			// // check for direction control update
1150			if(slider.settings.controls) updateDirectionControls();
1151			// if slider is set to mode: "fade"
1152			if(slider.settings.mode == 'fade'){
1153				// if adaptiveHeight is true and next height is different from current height, animate to the new height
1154				if(slider.settings.adaptiveHeight && slider.viewport.height() != getViewportHeight()){
1155					slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed);
1156				}
1157				// fade out the visible child and reset its z-index value
1158				slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0});
1159				// fade in the newly requested slide
1160				slider.children.eq(slider.active.index).css('zIndex', 51).fadeIn(slider.settings.speed, function(){
1161					$(this).css('zIndex', 50);
1162					updateAfterSlideTransition();
1163				});
1164			// slider mode is not "fade"
1165			}else{
1166				// if adaptiveHeight is true and next height is different from current height, animate to the new height
1167				if(slider.settings.adaptiveHeight && slider.viewport.height() != getViewportHeight()){
1168					slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed);
1169				}
1170				var moveBy = 0;
1171				var position = {left: 0, top: 0};
1172				// if carousel and not infinite loop
1173				if(!slider.settings.infiniteLoop && slider.carousel && slider.active.last){
1174					if(slider.settings.mode == 'horizontal'){
1175						// get the last child position
1176						var lastChild = slider.children.eq(slider.children.length - 1);
1177						position = lastChild.position();
1178						// calculate the position of the last slide
1179						moveBy = slider.viewport.width() - lastChild.outerWidth();
1180					}else{
1181						// get last showing index position
1182						var lastShowingIndex = slider.children.length - slider.settings.minSlides;
1183						position = slider.children.eq(lastShowingIndex).position();
1184					}
1185					// horizontal carousel, going previous while on first slide (infiniteLoop mode)
1186				}else if(slider.carousel && slider.active.last && direction == 'prev'){
1187					// get the last child position
1188					var eq = slider.settings.moveSlides == 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides);
1189					var lastChild = el.children('.bx-clone').eq(eq);
1190					position = lastChild.position();
1191				// if infinite loop and "Next" is clicked on the last slide
1192				}else if(direction == 'next' && slider.active.index == 0){
1193					// get the last clone position
1194					position = el.find('> .bx-clone').eq(slider.settings.maxSlides).position();
1195					slider.active.last = false;
1196				// normal non-zero requests
1197				}else if(slideIndex >= 0){
1198					var requestEl = slideIndex * getMoveBy();
1199					position = slider.children.eq(requestEl).position();
1200				}
1201
1202				/* If the position doesn't exist
1203				 * (e.g. if you destroy the slider on a next click),
1204				 * it doesn't throw an error.
1205				 */
1206				if ("undefined" !== typeof(position)) {
1207					var value = slider.settings.mode == 'horizontal' ? -(position.left - moveBy) : -position.top;
1208					// plugin values to be animated
1209					setPositionProperty(value, 'slide', slider.settings.speed);
1210				}
1211			}
1212		};
1213
1214		/**
1215		 * Transitions to the next slide in the show
1216		 */
1217		el.goToNextSlide = function(){
1218			// if infiniteLoop is false and last page is showing, disregard call
1219			if (!slider.settings.infiniteLoop && slider.active.last) return;
1220			var pagerIndex = parseInt(slider.active.index) + 1;
1221			el.goToSlide(pagerIndex, 'next');
1222		};
1223
1224		/**
1225		 * Transitions to the prev slide in the show
1226		 */
1227		el.goToPrevSlide = function(){
1228			// if infiniteLoop is false and last page is showing, disregard call
1229			if (!slider.settings.infiniteLoop && slider.active.index == 0) return;
1230			var pagerIndex = parseInt(slider.active.index) - 1;
1231			el.goToSlide(pagerIndex, 'prev');
1232		};
1233
1234		/**
1235		 * Starts the auto show
1236		 *
1237		 * @param preventControlUpdate (boolean)
1238		 *  - if true, auto controls state will not be updated
1239		 */
1240		el.startAuto = function(preventControlUpdate){
1241			// if an interval already exists, disregard call
1242			if(slider.interval) return;
1243			// create an interval
1244			slider.interval = setInterval(function(){
1245				slider.settings.autoDirection == 'next' ? el.goToNextSlide() : el.goToPrevSlide();
1246			}, slider.settings.pause);
1247			// if auto controls are displayed and preventControlUpdate is not true
1248			if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('stop');
1249		};
1250
1251		/**
1252		 * Stops the auto show
1253		 *
1254		 * @param preventControlUpdate (boolean)
1255		 *  - if true, auto controls state will not be updated
1256		 */
1257		el.stopAuto = function(preventControlUpdate){
1258			// if no interval exists, disregard call
1259			if(!slider.interval) return;
1260			// clear the interval
1261			clearInterval(slider.interval);
1262			slider.interval = null;
1263			// if auto controls are displayed and preventControlUpdate is not true
1264			if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('start');
1265		};
1266
1267		/**
1268		 * Returns current slide index (zero-based)
1269		 */
1270		el.getCurrentSlide = function(){
1271			return slider.active.index;
1272		};
1273
1274		/**
1275		 * Returns number of slides in show
1276		 */
1277		el.getSlideCount = function(){
1278			return slider.children.length;
1279		};
1280
1281		/**
1282		 * Update all dynamic slider elements
1283		 */
1284		el.redrawSlider = function(){
1285			// resize all children in ratio to new screen size
1286			slider.children.add(el.find('.bx-clone')).outerWidth(getSlideWidth());
1287			// adjust the height
1288			slider.viewport.css('height', getViewportHeight());
1289			// update the slide position
1290			if(!slider.settings.ticker) setSlidePosition();
1291			// if active.last was true before the screen resize, we want
1292			// to keep it last no matter what screen size we end on
1293			if (slider.active.last) slider.active.index = getPagerQty() - 1;
1294			// if the active index (page) no longer exists due to the resize, simply set the index as last
1295			if (slider.active.index >= getPagerQty()) slider.active.last = true;
1296			// if a pager is being displayed and a custom pager is not being used, update it
1297			if(slider.settings.pager && !slider.settings.pagerCustom){
1298				populatePager();
1299				updatePagerActive(slider.active.index);
1300			}
1301		};
1302
1303		/**
1304		 * Destroy the current instance of the slider (revert everything back to original state)
1305		 */
1306		el.destroySlider = function(){
1307			// don't do anything if slider has already been destroyed
1308			if(!slider.initialized) return;
1309			slider.initialized = false;
1310			$('.bx-clone', this).remove();
1311			slider.children.each(function() {
1312				$(this).data("origStyle") != undefined ? $(this).attr("style", $(this).data("origStyle")) : $(this).removeAttr('style');
1313			});
1314			$(this).data("origStyle") != undefined ? this.attr("style", $(this).data("origStyle")) : $(this).removeAttr('style');
1315			$(this).unwrap().unwrap();
1316			if(slider.controls.el) slider.controls.el.remove();
1317			if(slider.controls.next) slider.controls.next.remove();
1318			if(slider.controls.prev) slider.controls.prev.remove();
1319			if(slider.pagerEl) slider.pagerEl.remove();
1320			$('.bx-caption', this).remove();
1321			if(slider.controls.autoEl) slider.controls.autoEl.remove();
1322			clearInterval(slider.interval);
1323			if(slider.settings.responsive) $(window).unbind('resize', resizeWindow);
1324		};
1325
1326		/**
1327		 * Reload the slider (revert all DOM changes, and re-initialize)
1328		 */
1329		el.reloadSlider = function(settings){
1330			if (settings != undefined) options = settings;
1331			el.destroySlider();
1332			init();
1333		};
1334
1335		init();
1336
1337		// returns the current jQuery object
1338		return this;
1339	}
1340
1341})(jQuery);