function viewer (options) {


	var viewObject = (function () {

		var img = $('.home-img');
		var txtElem = $('.page-title');
		var txtClone = txtElem.clone();
		var initialTxt = txtElem.html();
		var initialSrc = img.attr('src');
		var src = 'src';
		var showLink = false;
		var text = 'Parce que le meilleurs est à venir';
		var carousel;

		var _titleTpl = function (index) {

			var result;

			if (options.def[index].linkUrl && options.def[index].linkTxt) {
				result = txtClone
				.find('h1')
					.text(options.def[index].txt)
				.end()
				.find('a')
					.show()
					.attr('href', options.def[index].linkUrl)
				.end()
				.find('span')
					.text(options.def[index].linkTxt)
				.end()
				.html();
			}
			else {
				result = txtClone
				.find('h1')
					.text(options.def[index].txt)
				.end()
				.find('a')
					.hide()
				.end()
				.html();
			}
			return result;
		}

		var _reset = function () {
			_createImage(options.def[0].src, _titleTpl(0));
			initCarousel();
		}

		var initCarousel = function () {
			var actualImg = 0;
			var imgNumber = options.def.length - 1;
			var goToNextPict = function () {
				actualImg = actualImg == imgNumber ? 0 : actualImg + 1;
				_createImage(options.def[actualImg].src, _titleTpl(actualImg));
			}
			carousel = window.setInterval(goToNextPict, 5000);
		}

		var stopCarousel = function () {
			window.clearInterval(carousel);
		}

		var _createImage = function (src, txt) {

			if ($(txt).length == 0) {
				txt = '<h1>'+txt+'</h1>'
			}
			$('.page-title').hide();
			var newImg = $('<img class="home-img"/>').insertBefore('.home-mask').hide();
			var newTxt = $('<div class="page-title">'+txt+'</div>').insertAfter(txtElem).hide();
			newImg.load(function(){
				txtElem.fadeOut(200, function(){
					newTxt.fadeIn(1000, function(){
						txtElem.remove();
						txtElem = newTxt;
					});
				});
				newImg.fadeIn(1000, function(){
					img.remove();
					img = newImg;
				});
			});
			newImg.attr('src', src);
		}

		var _setText = function (txt) {
			txtElem.fadeOut(1000);
			var newTxt = $('<h1>'+txt+'</h1>').insertAfter('h1');
		};

		return {
			'set' : function (src, txt) {
				_createImage(src, txt);
			},
			'reset' : function () {
				_reset();
			},
			'stopCarousel' : function () {
				stopCarousel();
			},
			'initCarousel' : function () {
				initCarousel();
			}
		}
		
	})();

	viewObject.initCarousel();

	$('.residences-carousel a').bind('mouseenter', function () {

		var jThis = $(this);
		var src = jThis.attr('data-img');
		var txt = jThis.attr('data-title');

		var changeBackground = function() {
			viewObject.set(src, txt);
		}

		var timeOut = window.setTimeout(changeBackground, 300);

		jThis.unbind('mouseleave').bind('mouseleave', function () {
			window.clearTimeout(timeOut);
		})
		

	});

	$('.residences-carousel').bind('mouseenter', function(e){
		viewObject.stopCarousel();
	})

	$('.residences-carousel').bind('mouseleave', function(e){
		if(e.relatedTarget) {
		viewObject.reset();
		}
	})






























/*
	var img = $('.home-img');
	var newImg = img.clone().insertBefore(img);
	var isFading = false;
	var actualSrc = img.attr('src');
	var nextSrc = img.attr('src');

	function updateImg() {
		if (nextSrc != actualSrc) {
			newImg.attr('src', nextSrc);
			actualSrc = nextSrc;
		}
	}


	$('.residences-carousel a').bind('mouseenter', function(){

		var jThis = $(this);
		nextSrc = jThis.attr('data-img');

		if (isFading == false) {
			updateImg()
		}

	});




	newImg.load(function(){
		isFading = true
		img.fadeOut(2000, function(){
			img.attr('src', actualSrc);
			isFading = false;
		});
	});



	img.load(function(){
		img.show();
		updateImg();
	})*/


}
