// PAs oublier de définir le chemin avec RVA.path = '{path=""}'
RVA = {
	$win : $(window),
	root : '#page',
    init : function init() {
		this.popup('/templates/inc/data_mentions_credits.html', true);
	},
	diaporama : function diaporama() {
		var timer;
		var play = true;
		var current = 1;
		var last = function() {
			var s = 1;
			clearTimeout(timer);
			$('a', '#navigation-diapo').unbind('click', last_first);
			$('li:last','#slider ul').fadeOut(500*s,function(){
				var item = $(this).clone();
				$(this).remove();
				item.prependTo('#slider ul').show();
				$('a', '#navigation-diapo').bind('click', last_first);
				timer = setInterval(last, 5000);
				current += 1;
				if(current>$('li', '#slider').length) current = 1;
				$('#numbers').children('.current').text(current);
			});
		}
		var first = function() {
			var s = 1;
			clearTimeout(timer);
			$('a', '#navigation-diapo').unbind('click', last_first);
			var item = $('#slider li:first').hide().clone();
			$('#slider li:first').remove();
			item.appendTo('#slider ul').fadeIn(500*s, function(){
				$('a', '#navigation-diapo').bind('click', last_first);
				if(play)timer = setInterval(last, 5000);
				current -= 1;
				if(current<=0) current = $('li', '#slider').length;
				$('#numbers').children('.current').text(current);
			});
		}
		var last_first = function(){
			if ($(this).hasClass('prev')) {
				first(); 
			};
			if ($(this).hasClass('pause')) {
				/*if (play) {
					clearTimeout(timer);
					play = false;
				} else {
					timer = setInterval(last, 5000, 1);
					play = true;
				};*/
				return true;
			};
			if ($(this).hasClass('next')) {
				last();
			};
			return false;
		}
		$('#numbers').children('.current').text(current);
		$('#numbers').children('.total').text($('li', '#slider').length);
		$('#prev, #next', '#navigation-diapo').bind('click', function(){ return false; });
		$('a', '#navigation-diapo').bind('click', last_first);
		timer = setInterval(last, 5000);
		$('img', '#slider').load(function(){
			$(this).css('visibility','visible');
		});
	},
	popup : function popup(url, bool) {
	  var newurl = url;
	  function showMyWindow(url2) {
	    var myurl = url2;
	    $('body').prepend('<div id="background"></div>')
				.prepend('<div id="box"></div>')
			$('#background').css({
				display:'block',
				position:'fixed',
				top:0,
				left:0,
				width:'100%',
				height:'100%',
				zIndex:1000,
				backgroundColor:'black',
				opacity:.8,
				filter : 'alpha(opacity=50)'
			});
			$('#box').css({
				display:'block',
				position:'absolute',
				top:'100px',
				left:'50%',
				marginLeft:'-224px',
				width:'400px',
				zIndex:1001,
				backgroundColor:'white',
				border:'4px solid #202020',
				padding:'10px 20px 10px 20px'
			});
			$('#box').prepend('<a href="#close" class="close">fermer</a>');
			$('#box .close').css({
				display:'block',
				position:'absolute',
				top:'5px',
				right:'5px',
				width:'20px',
				height:'20px',
				background:"white url('/templates/css/imgs/close.jpg') no-repeat 0 0",
				textIndent:'-1000000px'
			}).click(function(){
				$('#box, #background').remove();
			});
			$.get(
					myurl,
					function callback(data) {
						$('#box').append(data);
						$('#box h3').css({
							color:'#9c8c5e',
							padding:'10px 0 0 0'
						});
						$('#box p').css({
							font:'normal 10px/1.2em Arial, Sans-serif',
							textAlign:'justify'
						});
						$('#box a').css({
							font:'normal 10px/1.3em Arial, Sans-serif',
							color:'black',
							textDecoration:'none'
						});
					}
				);
	  }
	  if (bool) {
	    $('#mentionsCredits').click(function() {
  			showMyWindow(newurl);
  			return false;
  		});
	  } else {
	    	showMyWindow(newurl);
	  }
	}
};

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