// JavaScript Document
$(document).ready(function(){
	
	$("#car-mus").click(function(){
		//window.location='musee.php?v='+window.numMus;
	});
	$("#car-expo").click(function(){
		window.location='expo.php';
	});
	$("#car-activ").click(function(){
		window.location='activ.php';
	});
	$("#car-reali").click(function(){
		//window.location='cbm.php';
	});
});

function getPictNum(a){
    $.ajax({
	  url: '../fonctions/req.php?t=1&lg='+window.lg,
	  success: function(data) {
		
		if(a==2){ 
			$('#slideshow img:last').attr('src','../images/musee/'+data+'-h.jpg'); 
			$('#slideshow img:last').click(function(){ window.location='musee.php?v='+data}); 
		}
	    else{ 
		//window.numMus=data; 
			$('#slideshow img:first').attr('src','../images/musee/'+data+'-h.jpg'); 
			$('#slideshow img:first').click(function(){ window.location='musee.php?v='+data}); 
			
		}
	  }
	});
}
function getPictNum2(b){
    $.ajax({
	  url: '../fonctions/req.php?t=2&lg='+window.lg,
	  success: function(data) {
		if(b==2){ $('#slideshow2 img:last').attr('src','../images/activg/'+data+'-h.jpg'); }
	    else{ $('#slideshow2 img:first').attr('src','../images/activg/'+data+'-h.jpg'); }
	  }
	});
}
function getPictNum3(c){
    $.ajax({
	  url: '../fonctions/req.php?t=3&lg='+window.lg,
	  success: function(data) {
		if(c==2){ $('#slideshow3 img:last').attr('src','../images/activg/'+data+'-h.jpg'); }
	    else{ $('#slideshow3 img:first').attr('src','../images/activg/'+data+'-h.jpg'); }
	  }
	});
}
var a=1;
var b=1;
var c=1;
function slideSwitch() {
	var $active = $('#slideshow img.active');
    if ( $active.length == 0 ) $active = $('#slideshow img:last');
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');
    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
			lien=getPictNum(a);
			if(a==1){ a=2; }
			else{ a=1; }
        });
}

function slideSwitch2() {
    var $active = $('#slideshow2 img.active');

    if ( $active.length == 0 ) $active = $('#slideshow2 img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow2 img:first');
    
    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
			getPictNum2(b);
			if(b==1){ b=2; }
			else{ b=1; }
        });
}

function slideSwitch3() {
    var $active = $('#slideshow3 img.active');

    if ( $active.length == 0 ) $active = $('#slideshow3 img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow3 img:first');
    
    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
			getPictNum3(c);
			if(c==1){ c=2; }
			else{ c=1; }
        });
}
function slideSwitch4() {
    var $active = $('#slideshow4 a.active');

    if ( $active.length == 0 ) $active = $('#slideshow4 a:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow4 a:first');
    
    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 5000 );
	setInterval( "slideSwitch2()", 5000 );
	setInterval( "slideSwitch3()", 5000 );
	setInterval( "slideSwitch4()", 5000 );
});

