$(document).ready(function(){
	var version=0;
	if (navigator.appVersion.indexOf("MSIE")!=-1){
	temp=navigator.appVersion.split("MSIE");
	version=parseFloat(temp[1]);

	}

	var N=4;	//Nombre d'images
	var imgwidth=316;
	var imgheight=220;	//largeur de chaque image
	var liwidth=316;
	var limin=240;
	var imgmin=240;
	var imgminh=167;
	var current=2;
	$("#slideshow  ul").attr("width",N*imgwidth);
	var pos=400-(((imgwidth+20)*(current-1))+((imgwidth+20)/2));
	$("#slideshow  ul").attr("left",pos);
	reduit("#panel_1");
	reduit("#panel_3");
	reduit("#panel_4");
		$("#goright").click(function(){
			if(pos==400-((imgwidth+20)/2)){}
			else{pos=pos+(imgwidth+20);
			$("#slideshow ul")
				.stop()
				.animate({
					"left": pos
				}, function() {
				});
			reduit("#panel_"+current);
			$("#panel_"+current).attr("class","off");
			current--;
			grossit("#panel_"+current);
			$("#panel_"+current).attr("class","on");
			}
		});
		$("#goleft").click(function(){
			if(pos==(400+((imgwidth+20)/2))-((imgwidth+20)*N)){}
			else{pos=pos-(imgwidth+20);
			$("#slideshow ul")
				.stop()
				.animate({
					"left": pos
				}, function() {
				});
			reduit("#panel_"+current);
			$("#panel_"+current).attr("class","off");
			current++;
			grossit("#panel_"+current);
			$("#panel_"+current).attr("class","on");
			}
		});
		
	function reduit(element) {
		if (version>=6 && version<7){
		$(element)
			.find("span")
			.animate({ "width": imgmin, "height": imgminh })
		    .end()
		}else{
		$(element)
			.find("img")
			.animate({ "width": imgmin, "height": imgminh })
		    .end()
		}
	};
	
	function grossit(element) {
	if (version>=6 && version<7){
			$(element)
			.find("span")
			.animate({ "width": imgwidth, "height": imgheight })
		    .end()
		}else{
		$(element)
			.find("img")
			.animate({ "width": imgwidth, "height": imgheight })
		    .end()
		}
	}
	$(window).keydown(function(event){
	  switch (event.keyCode) {
			case 13: //enter
				$("#goright").click();
				break;
			case 32: //space
				$("#goright").click();
				break;
	    case 37: //left arrow
				$("#goleft").click();
				break;
			case 39: //right arrow
				$("#goright").click();
				break;
	  }
	});	
	});	