(function ($) {	'use strict';	var methods = {		init: function (options) {			// Variables only accessible in init			var	$this = $(this),				data = {},				loadImgs = 0,				imagesAmount = 0;							// Settings shared across all methods			data.settings = {				height: 80,				popup: true,				images: [],				loaded_imgs: [],				default_speed: 1,				interval: 15			};						// Overwrite the default settings with the user options			$.extend(data.settings, options || {});						// Fix for IE8 and lower, which populates lists with an aditional item "function typeOf"			imagesAmount = typeof (data.settings.images[data.settings.images.length - 1]) === 'object' ? data.settings.images.length : data.settings.images.length - 1;						//setTimeout(function () { // Need to test the visual loading part			// Load all the images before starting the carousel			$(data.settings.images).each(function (i, item) {				var img = new Image(),						carousel = $this,						myData = data;								if (data.settings.images.hasOwnProperty(i)) {					$(img).load(function () {						loadImgs += 1;						myData.settings.loaded_imgs.push(this);						// Save the data so it can be used by every method						carousel.data('carousel', myData);						if (loadImgs === imagesAmount) {							// Fix for IE7&8 and caching. Jquery has not set the .data('extra') before all $(img) executed the load function							setTimeout(function () {								methods.postInit.apply($this);							}, 10);						}					}).error(function () {						loadImgs += 1;						if (loadImgs === imagesAmount) {							// Fix for IE7&8 and caching. Jquery has not set the .data('extra') before all $(img) executed the load function							setTimeout(function () {								methods.postInit.apply($this);							}, 10);						}					}).attr({"src": item.image, "alt": item.title}).data('extra', {'popup': item.popup, 'img_hover': item.img_hover, 'link': item.link });				}			});			$this.data('carousel', data);			//}, 100);						return this.each(function () {				var wrapper = $('<div class="carousel-wrapper"></div>').appendTo(this);				wrapper.html('<div class="carousel-loading">loading images</div>');			});		},		postInit: function () {			var data = $(this).data('carousel');						return this.each(function () {				var $this = $(this),					inner = $('<div class="carousel-inner"></div>'),					scroller1 = $('<div class="carousel-scroller" id="scroller-1"></div>'),					images = data.settings.loaded_imgs,					scroller_width = 0,					item = null,					i;								$('.carousel-wrapper', $this).append(inner);				inner.append(scroller1);									for (i in images) {					if (images.hasOwnProperty(i)) {						if (data.settings.popup && $(images[i]).data('extra').popup !== undefined) {							item = $('<a href="' + $(images[i]).data('extra').popup + '"></a>').addClass("carousel-item")								.attr({'rel': 'shadowbox', 'title': images[i].alt})								.html($(images[i]).clone())								.append('<div class="carousel-item-inner">')								.appendTo(scroller1);						} else {							item = $('<div>').addClass("carousel-item")								.html($(images[i]).clone().addClass('no-hover'))								.append('<div class="carousel-item-inner">')								.appendTo(scroller1);							if ($(images[i]).data('extra').img_hover) {								$(item).append('<img class="img-hover" src="' + $(images[i]).data('extra').img_hover + '" />');							}							if ($(images[i]).data('extra').link) {								item = $(item).wrapInner('<a href="' + $(images[i]).data('extra').link + '" />');							}						}						scroller_width += item.width();					}				}				data.scroller_width = scroller_width;								$('.carousel-inner').css('left', -data.scroller_width);				$('.carousel-wrapper, .carousel-scroller, .carousel-item, .carousel-item img').height(data.settings.height);				$('.carousel-item img').width('auto');				$('.carousel-loading', $this).remove();				$this.data('carousel', data);								if (scroller1.width() - scroller1.children().eq(0).children().width() > $('.carousel-wrapper').width()) {					inner.append(scroller1.clone().attr('id', 'scroller-2'));					$this.trigger('carousel-loaded');					methods.start.apply($this);				} else {					scroller1.css('margin-left', $('.carousel-wrapper').offset().left - $('.carousel-inner').offset().left);					$('.project-logos-wrapper .arrow').hide();					$this.trigger('carousel-loaded');				}			});		},		start: function () {			var $this = $(this),				data = $this.data('carousel');			return this.each(function () {				var	carousel_elem = this,					inner = $('.carousel-inner', this),					scroller1 = $('#scroller-1', this)[0],					speed = data.settings.default_speed,					inner_right = null,					inner_left = null;								inner_right = $(this).offset().left + inner.parent().width();				inner_left = $(this).offset().left;									// Adapt speed accourding to mouse position				inner.mousemove(function (e) {					var left = (e.pageX - ($(this).offset().left - $(this).position().left)),						width = $(carousel_elem).outerWidth();					speed = Math.round(((2 * left / width) - 1) * -2); // range [-2, -1, 0, 1, 2]				}).hover(function () {}, function () {					speed = data.settings.default_speed; // on hover out				});									scroller1.style.marginLeft = data.scroller_width + 'px';				data.ival = setInterval(function () {					if (speed !== 0) {						var ml = parseInt(scroller1.style.marginLeft, 10);						// The carousel-inner has exactly the data.scroller_width negative margin on the left side						// Therefore, if the ml is equal to the data.scroller_width, 						//there is enought length to shift the slider back to the start						if (ml >= data.scroller_width) {							scroller1.style.marginLeft = speed + 'px';						} else if (ml <= 0) {							scroller1.style.marginLeft = data.scroller_width + speed + 'px';						} else {							scroller1.style.marginLeft = ml + speed + 'px';						}					}				}, data.settings.interval);								$this.data('carousel', data);			});		},		stop: function () {			var data = $(this).data('carousel');			clearInterval(data.ival);			return this.each(function () {				$('.carousel-inner', this).mousemove(function () {});			});		}	};	$.fn.carousel = function (method) {		// Method calling logic		if (methods[method]) {			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));		} else if (typeof method === 'object' || !method) {			return methods.init.apply(this, arguments);		} else {			$.error('Method ' +  method + ' does not exist on jQuery.carousel');		}    	};}(jQuery));
