SITE = {
	$win : $(window),
	init : function init() {
		this.menuDeroulant();
		this.boiteModale('.espace-perso');
	},
	menuDeroulant : function menuDeroulant() {
		var $el = $('ul > li', $('.navbar'));
		$el.hover(function() {
			$(this).addClass('hover');
			$('> ul', $(this)).slideDown();
		}, function() {
			$(this).removeClass('hover');
			$('ul', $(this)).hide();
		});
	},
	diaporamaPhoto : function diaporamaPhoto(el) {
		var options = {
			animationSpeed : 'slow',
			sens : 'left'
		};
		var $diapo = $(el);
		var count = $('ul li', $diapo).size();
		var widthLi = $('ul li:first', $diapo).width();
		var widthUl = widthLi * count;
		var mouseover = false;
		var index = 0;
		$('ul', $diapo).width(widthUl);
		var  moveDiapo = function() {
			index = $('.view', $diapo).index();
			if (options.sens === 'left') {
				index = index+1;
				if(index >= count - 1){
					options.sens = 'right';
				};
			} else {
				index -= 1;
				if(index <= 0){
					options.sens = 'left';
				};
			};
			$('.view', $diapo).removeClass('view');
			$('ul li:eq('+ index +')', $diapo).addClass('view');
			$('ul', $diapo).animate({ 'left' : -(widthLi * index) }, options.animationSpeed, 'easeOutCubic');
		};
		$('.prev', $diapo).live('click', function() {
			if(index > 0) {
				options.sens = 'right';
				moveDiapo();
			};
			return false;
		});
		$('.next', $diapo).live('click', function() {
			if(index < count - 1) {
				options.sens = 'left';
				moveDiapo();
			};
			return false;
		});
	},
	diaporamaFocus : function diaporamaFocus(el) {
		var options = {
			auto : true,
			delay : 15,
			paused : false,
			animationSpeed : 'slow',
			sens : 'left'
		};
		var $diapo = $(el);
		var count = $('ul li', $diapo).size();
		var widthLi = $('ul li:first', $diapo).width();
		var widthUl = widthLi * count;
		var timer;
		var index = 0;
		$('ul li:first', $diapo).addClass('view');
		for (var i=1; i <= count; i++) {
			$('.selecteur', $diapo).append('<a href="#">'+i+'</a>');
		};
		$('.selecteur', $diapo).children(':first').addClass('select');
		$('ul', $diapo).width(widthUl);
		$('.selecteur a').click(function(){
			index = $(this).index();
			if (options.sens === 'left') {
				if(index >= count - 1){
					options.sens = 'right';
				};
			} else {
				if(index <= 0){
					options.sens = 'left';
				};
			};
			$('.selecteur .select', $diapo).removeClass('select');
			$('.view', $diapo).removeClass('view');
			$('ul li:eq('+ index +')', $diapo).addClass('view');
			$('.selecteur a:eq('+ index +')', $diapo).addClass('select');
			$('ul', $diapo).animate({ 'left' : -(widthLi * index) }, options.animationSpeed, 'easeOutCubic');

		});
		var  moveDiapo = function() {
			index = $('.view', $diapo).index();
			if (options.sens === 'left') {
				index = index+1;
				if(index >= count - 1){
					options.sens = 'right';
				};
			} else {
				index -= 1;
				if(index <= 0){
					options.sens = 'left';
				};
			};
			$('.selecteur .select', $diapo).removeClass('select');
			$('.view', $diapo).removeClass('view');
			$('ul li:eq('+ index +')', $diapo).addClass('view');
			$('.selecteur a:eq('+ index +')', $diapo).addClass('select');
			$('ul', $diapo).animate({ 'left' : -(widthLi * index) }, options.animationSpeed, 'easeOutCubic');
		};
		var activeDiapo = function(e){
			options.paused = e;
			if(options.auto && !options.paused) {
				timer = setInterval(function(){
					moveDiapo();
				}, options.delay*1000);
			} else {
				clearInterval(timer);
			};
		};
		activeDiapo(options.paused);
		$($diapo).hover(function(){
			activeDiapo(true);
		}, function(){
			activeDiapo(false);
		});
	},
	diaporamaPromo : function diaporamaPromo(el) {
		var options = {
			animationSpeed : 'slow',
			sens : 'left'
		};
		var $diapo = $(el);
		$('ul li:first', $diapo).addClass('view');
		var count = $('ul li', $diapo).size();
		var widthLi = 226;
		var widthUl = widthLi * count;
		var mouseover = false;
		var index = 0;
		$('ul', $diapo).width(widthUl);
		var  moveDiapo = function() {
			index = $('.view', $diapo).index();
			if (options.sens === 'left') {
				index = index+1;
				if(index >= count - 4){
					options.sens = 'right';
				};
			} else {
				index -= 1;
				if(index <= 0){
					options.sens = 'left';
				};
			};
			$('.view', $diapo).removeClass('view');
			$('ul li:eq('+ index +')', $diapo).addClass('view');
			$('ul', $diapo).animate({ 'left' : -(widthLi * index) + 20 }, options.animationSpeed, 'easeOutCubic');
		};
		$('.prev', $diapo).click(function() {
			if(index > 0) {
				options.sens = 'right';
				moveDiapo();
			};
			return false;
		});
		$('.next', $diapo).click(function() {
			if(index < count - 4) {
				options.sens = 'left';
				moveDiapo();
			};
			return false;
		});
	},
	listOddColor : function listOddColor() {
		var $el = $('.list:odd', $('.lists'));
		$el.addClass('color3');
		$('small, table, .description', $el).addClass('color2');
		$('.liens a', $el).addClass('bgColor3');
	},
	heightListLiens : function heightListLiens() {
		var $el = $('.list');
		$el.each(function(e) {
			var $this = $('.liens a', $(this));
			var size = $this.size();
			if (size===1) {
				$this.height((114/2)+5).css('paddingTop',(114/2)-5);
			} else {
				$this.height((114/4)+5).css('paddingTop',(114/4)-5);
				$('.liens a:eq(0)', $(this)).css('marginBottom','2px');
			}
		});
	},
	onglets : function detailTableau() {
		var $onglet1 = $('.onglet1 table');
		var $onglet4 = $('.onglet4 div:odd');
		$('tr:odd td', $onglet1).addClass('color7');
		$('tr td:first-child', $onglet1).css('textAlign','left');
		$('tr :last-child', $onglet1).css('border','none');
		$($onglet4).addClass('color7');
	},
	actionOnglets : function actionOnglets(opt) {
		var $el = $('.onglets');
		$('.'+$('.select', $el).attr('href').slice(1)+'', $el).show();
		$('.barOnglets a', $el).click(function() {
			var cl = $(this).attr('href').slice(1);
			var select = $('.select', $el).attr('href').slice(1);
			$('.select', $el).removeClass('select');
			$(this).addClass('select');
			$('.'+select+'', $el).fadeOut(200, function() {
				$('.'+cl+'', $el).fadeIn(200, function() {
					if ($(this).hasClass('onglet3')) {
						if (opt) {
							var googleOptions = opt;
							$('.gmap3').gmap3(googleOptions[0],googleOptions[1],googleOptions[2]);
						};
					};
				});
			});
		});
	},
	actionOnglets2 : function actionOnglets2() {
		var $el = $('.onglets_2');
		$('.'+$('.select', $el).attr('href').slice(1)+'', $el).show();
		$('.barOnglets a', $el).click(function() {
			var cl = $(this).attr('href').slice(1);
			var select = $('.select', $el).attr('href').slice(1);
			$('.select', $el).removeClass('select');
			$(this).addClass('select');
			$('.'+select+'', $el).fadeOut(200, function() {
				$('.'+cl+'', $el).fadeIn(200);
			});
		});
	},
	boiteModale : function boiteModale(el) {
		var $el = $(el);
		$el.click(function(){
			$('.bm-bg, .bm-window').fadeIn('slow', function(){
				
			});
			return false;
		});
	}
}

$(function(){
	SITE.init();
});
