$(document).ready(function () {

	$('#tabCenter0').click(function(e) {
		if($("#tabCenter0").hasClass("tabOff0")) {
			$("#tabLeft0").removeClass("tabOn0");
			$("#tabCenter0").removeClass("tabOff0");
			$("#tabLeft0").addClass("tabOff0");
			$("#tabCenter0").addClass("tabOn0");
			$("#under_tab_0").css('backgroundImage','url(images/tab_under_2_cat_1.png)');
			$("#slider_0_a").css('display','none');
			$("#slider_0_b").css('display','block');
			$("#nav_0_a").css('display','none');
			$("#nav_0_b").css('display','block');
		}
	});

	$('#tabLeft0').click(function(e) {
		if($("#tabLeft0").hasClass("tabOff0")) {
			$("#tabLeft0").removeClass("tabOff0");
			$("#tabCenter0").removeClass("tabOn0");
			$("#tabLeft0").addClass("tabOn0");
			$("#tabCenter0").addClass("tabOff0");
			$("#under_tab_0").css('backgroundImage','url(images/tab_under_1_cat_1.png)');
			$("#slider_0_b").css('display','none');
			$("#slider_0_a").css('display','block');
			$("#nav_0_b").css('display','none');
			$("#nav_0_a").css('display','block');
		}
	});

	$('#tabCenter1').click(function(e) {
		if($("#tabCenter1").hasClass("tabOff1")) {
			$("#tabLeft1").removeClass("tabOn1");
			$("#tabCenter1").removeClass("tabOff1");
			$("#tabLeft1").addClass("tabOff1");
			$("#tabCenter1").addClass("tabOn1");
			$("#under_tab_1").css('backgroundImage','url(images/tab_under_2_cat_2.png)');
			$("#slider_1_a").css('display','none');
			$("#slider_1_b").css('display','block');
			$("#nav_1_a").css('display','none');
			$("#nav_1_b").css('display','block');
		}
	});

	$('#tabLeft1').click(function(e) {
		if($("#tabLeft1").hasClass("tabOff1")) {
			$("#tabLeft1").removeClass("tabOff1");
			$("#tabCenter1").removeClass("tabOn1");
			$("#tabLeft1").addClass("tabOn1");
			$("#tabCenter1").addClass("tabOff1");
			$("#under_tab_1").css('backgroundImage','url(images/tab_under_1_cat_2.png)');
			$("#slider_1_b").css('display','none');
			$("#slider_1_a").css('display','block');
			$("#nav_1_b").css('display','none');
			$("#nav_1_a").css('display','block');
		}
	});

	$('#tabCenter').click(function(e) {
		if($("#tabCenter").hasClass("tabOff1")) {
			$("#tabLeft").removeClass("tabOn1");
			$("#tabCenter").removeClass("tabOff1");
			$("#tabLeft").addClass("tabOff1");
			$("#tabCenter").addClass("tabOn1");
			$("#under_tab").css('backgroundImage','url(images/tab_under_big_2.png)');
			$("#slider_0_a").css('display','none');
			$("#slider_0_b").css('display','block');
			$("#nav_0_a").css('display','none');
			$("#nav_0_b").css('display','block');
		}
	});

	$('#tabLeft').click(function(e) {
		if($("#tabLeft").hasClass("tabOff1")) {
			$("#tabLeft").removeClass("tabOff1");
			$("#tabCenter").removeClass("tabOn1");
			$("#tabLeft").addClass("tabOn1");
			$("#tabCenter").addClass("tabOff1");
			$("#under_tab").css('backgroundImage','url(images/tab_under_big_1.png)');
			$("#slider_0_b").css('display','none');
			$("#slider_0_a").css('display','block');
			$("#nav_0_b").css('display','none');
			$("#nav_0_a").css('display','block');
		}
	});
	
	$('#moveLeft_0_a').click(function(e) {
		SliderMoveRight('0', 'a', 0);
	});
	$('#moveRight_0_a').click(function(e) {
		SliderMoveLeft('0', 'a', 0);
	});
	$('#moveLeft_0_b').click(function(e) {
		SliderMoveRight('0', 'b', 0);
	});
	$('#moveRight_0_b').click(function(e) {
		SliderMoveLeft('0', 'b', 0);
	});
	$('#moveLeft_1_a').click(function(e) {
		SliderMoveRight('1', 'a', 0);
	});
	$('#moveRight_1_a').click(function(e) {
		SliderMoveLeft('1', 'a', 0);
	});
	$('#moveLeft_1_b').click(function(e) {
		SliderMoveRight('1', 'b', 0);
	});
	$('#moveRight_1_b').click(function(e) {
		SliderMoveLeft('1', 'b', 0);
	});
	$('#moveLeft_a').click(function(e) {
		SliderMoveRight('0', 'a', 1);
	});
	$('#moveRight_a').click(function(e) {
		SliderMoveLeft('0', 'a', 1);
	});
	$('#moveLeft_b').click(function(e) {
		SliderMoveRight('0', 'b', 1);
	});
	$('#moveRight_b').click(function(e) {
		SliderMoveLeft('0', 'b', 1);
	});

});

var deplacement = new Array(452,904);

function SliderMoveLeft(clas, pos, size) {
	if(this['pos'+clas+pos].value > 0) {
		this['pos'+clas+pos].value--;
		coordonnee = this['pos'+clas+pos].value * -(deplacement[size]);
		$('#slider_'+clas+'_'+pos).animate({"left": coordonnee}, "slow");
	}
	printNavSlider(clas, pos);
}
function SliderMoveRight(clas, pos, size) {
	var nbChild = $('#slider_'+clas+'_'+pos).children().size();
	if(size) {
		nbChild = Math.ceil(nbChild/2);	
	}
	if(this['pos'+clas+pos].value < nbChild-1) {
		this['pos'+clas+pos].value++;
		coordonnee = this['pos'+clas+pos].value * -(deplacement[size]);
		$('#slider_'+clas+'_'+pos).animate({"left": coordonnee}, "slow");
	}
	printNavSlider(clas, pos);
}
function printNavSlider(clas, pos) {
	var nbChild = $('#slider_'+clas+'_'+pos).children().size();
	var position = this['pos'+clas+pos].value;
	if(position == 0) {
		$('#flecheMoveRight_'+clas+'_'+pos).attr('src', 'images/elmt/fleches/arrowLeftOff.png');
		$('#flecheMoveRight_'+clas+'_'+pos).attr('alt', 'Déplacement impossible');
		$('#flecheMoveRight_'+clas+'_'+pos).css('cursor', '');
	} else {
		$('#flecheMoveRight_'+clas+'_'+pos).attr('src', 'images/elmt/fleches/arrowLeftOn.png');
		$('#flecheMoveRight_'+clas+'_'+pos).attr('alt', 'Capsules précédentes');
		$('#flecheMoveRight_'+clas+'_'+pos).css('cursor', 'pointer');
	}
	if(position == nbChild-1) {
		$('#flecheMoveLeft_'+clas+'_'+pos).attr('src', 'images/elmt/fleches/arrowRightOff.png');
		$('#flecheMoveLeft_'+clas+'_'+pos).attr('alt', 'Déplacement impossible');
		$('#flecheMoveLeft_'+clas+'_'+pos).css('cursor', '');
	} else {
		$('#flecheMoveLeft_'+clas+'_'+pos).attr('src', 'images/elmt/fleches/arrowRightOn.png');
		$('#flecheMoveLeft_'+clas+'_'+pos).attr('alt', 'Capsules suivantes');
		$('#flecheMoveLeft_'+clas+'_'+pos).css('cursor', 'pointer');
	}
}