function videos() {
	var instance;

	var $elemento;
	var imagens;
	var id;
	var width;
	var height;
	var autoPlay;
	var totalItens;
	var corFundoAtivo;
	var corFundoInativo;
	var modoExib;
	var tipo;
	var videoLink;
	var videoImagem;
	var youtubeBase;
	var videoFlashVars;
	var videoBase;
	
	this.inicializar = function (elemento, _id, _width, _height, _autoPlay, _totalItens, _corFundoAtivo, _corFundoInativo, _modoExib, _tipo, _videoLink, _videoImagem, _elementoEvento) {
		var $capa;
		
		this.$elemento = $(elemento);
		this.id = _id;
		this.width = _width;
		this.height = _height;
		this.autoPlay = _autoPlay;
		this.totalItens = _totalItens;
		this.corFundoAtivo = _corFundoAtivo;
		this.corFundoInativo = _corFundoInativo;
		this.modoExib = _modoExib;
		this.tipo = _tipo;
		this.videoLink = _videoLink;
		this.videoImagem = _videoImagem;
		this.instance = this;

		$capa = $('.thumbnail.capa a', this.$elemento);

		if (_elementoEvento == undefined) {
			this.instance.preparaCarrossel();
			this.instance.preparaEventos();
		} else {
			this.instance.preparaEventos(_elementoEvento);
		}
		if ($capa.length && this.modoExib == 2) $capa.trigger('click');
	}

	this.preparaEventos = function (_elementoEvento) {
		var $player;
		var $links;
		var href;
		var instance;

		if (this.tipo == 1) {
			if (_elementoEvento == undefined)
				$links = $('.thumbnail a', this.$elemento);
			else
				$links = $(_elementoEvento);
			
			$links.click({
				instance: this.instance
			}, function (event) {
				event.preventDefault();
				var $this = $(this);
				var indice = parseInt($this.attr('rel'));
				href = decodeURI($this.attr('href'));
				instance = event.data.instance;

				if (instance.modoExib == 1) {
					$player = $('<div id="player-' + instance.id + '"></div>');
					instance.rodarVideo($player, href, instance.imagens[indice - 1], instance, true);
				} else {
					$player = $('#player-' + instance.id);
					instance.rodarVideo($player, href, instance.imagens[indice - 1], instance, false);
				}				
			});
		} else {
			instance = this.instance;
			href = this.videoLink;
			$player = $('#player-' + this.id);
			instance.rodarVideo($player, href, this.videoImagem, instance);
		}
	}

	this.rodarVideo = function ($player, href, imagem, instance, lightbox) {
		var isYoutubeVideo = /^(http:\/\/www.youtube.com)\/watch\?v=(\w+)/i.exec(href);
		var isYoutubeChan = /^(http:\/\/www.youtube.com)\/(.+)\/u\/([0-9]+)\/(.+)/i.exec(href);
		var cloned;
		if (isYoutubeVideo || isYoutubeChan) {
			var videoID;

			if (isYoutubeChan)
				videoID = isYoutubeChan[4];
			else
				videoID = isYoutubeVideo[2];
				
			var youtubeUrl = 'http://www.youtube.com/embed/' + videoID;
			cloned = instance.youtubeBase;
			cloned = cloned.replace(/###YOUTUBE_URL###/g, youtubeUrl);
			
			if (lightbox) {
				$.lightbox($player,{
					width: instance.width,
					height: instance.height,
					modal: true,
					onOpen: function() {
						$player.replaceWith(cloned);
					}
				});
			} else {
				
				$player.replaceWith(cloned);
			}	
		} else {			
			if (!DetectMobileQuick()) {
				cloned = instance.videoFlashVars;
				cloned.videoPath = href;
				cloned.imagePath = imagem;

				if (lightbox) {
					$.lightbox($player,{
						width: instance.width,
						height: instance.height,
						modal: true,
						onOpen: function() {
							instance.rodarFlash(instance, cloned);
						}
					});
				} else {
					instance.rodarFlash(instance, cloned);
				}
			} else {
				cloned = instance.videoBase;
				cloned = cloned.replace(/###POSTER###/g, imagem);
				cloned = cloned.replace(/###VIDEO_URL###/g, href);
				
				if (lightbox) {
					$.lightbox($player,{
						width: instance.width,
						height: instance.height,
						modal: true,
						onOpen: function() {
							$player.replaceWith(cloned);
						}
					});
				} else {
					$player.replaceWith(cloned);
				}
			}
		}
	}
	
	this.rodarFlash = function(instance, cloned) {
		swfobject.embedSWF('/lib/videoPlayer/videoPlayer.swf', 'player-' + instance.id, instance.width, instance.height, '9.0.0', 'expressInstall.swf', cloned, {allowfullscreen: 'true', wmode: 'transparent'},{});
	}

	this.preparaCarrossel = function () {
		var $carrossel = $('.carrossel', this.$elemento);
		var $thumbs = $('.thumbnails', $carrossel);
		var $thumb = $('.thumbnail:eq(0)', $thumbs);
		var $next = $('.next', this.$elemento);
		var $prev = $('.prev', this.$elemento);
		var desconto = 0;
		var numItens;

		numItens = parseInt((this.$elemento.width() - ($next.outerWidth(true) + $prev.outerWidth(true))) / $thumb.outerWidth(true));
		
		if (numItens > this.totalItens) numItens = this.totalItens;

		if (this.totalItens * $thumb.outerWidth(true) > this.$elemento.width()) {
			$thumbs.jCarouselLite({
				visible: numItens,
				scroll: numItens,
				wrap: 'circular',
				btnNext: $next,
				btnPrev: $prev
			});
			desconto = $next.outerWidth(true) + $prev.outerWidth(true);
				
		} else {
			var $allThumbs = $('.thumbnail', $thumbs);
			$next.remove();
			$prev.remove();
		}

		$carrossel.css('width', ($thumbs.outerWidth(true) + desconto) + 'px');
		$prev.css('height', $thumbs.outerHeight(true) + 'px');
		$next.css('height', $thumbs.outerHeight(true) + 'px');
	};
}

