slider = new Array();
big = new Array();
big["width"] = 250;
big["height"] = 150;
small = new Array();
small["width"] = 150;
small["height"] = 105;

function equilibrate() {
	$('#carousel ul li').each(function(i) {
		d = Math.abs(actual - i);
		var a = $(this);
		var img = a.children('a').children('img');
		switch(d) {
			case 0:
				img.animate({width:big["width"], height:big["height"]});
				a.animate({width:big["width"], height:big["height"]});
			break;
			case 1:
				if (slider[i] == 1) {
					slider[i] = 0;
					a.css({display:'inline', width:'0px', height:'0px'});
					img.css({width:'0px', height:'0px'});
				}
				img.animate({width:small["width"], height:small["height"]});
				a.animate({width:small["width"], height:small["height"]});
			break;
			default:
				if (slider[i] != 1) {
					slider[i] = 1;
					a.hide('fast');
				}
			break;
		}
	});
}

function actual_change(diff) {
	if (actual + diff > 0 && actual + diff < max) {
		actual = actual + diff;
		return true;
	}
	return false;
};

$(document).ready(function(){
	var requete = location.search.substring(1);
	var tab_paires = requete.split("&");
	var tab_elts = new Array();
	for (var i = 0; i < tab_paires.length; i++) {
		temp = tab_paires[i].split("=");
		tab_elts[temp[0]] = unescape(temp[1]);
	}

	$('#carousel ul').css('overflow', 'hidden');
	max = $('#carousel ul li').size();

	i = (tab_elts["show"]) ? parseInt(tab_elts["show"]) : 0;
	actual = (!isNaN(i) && i > 0 && i < max) ? i : 1;

	$('#carousel ul li').each( function(i) {
		d = Math.abs(actual - i);
		var a = $(this);
		var img = a.children('a').children('img');
		switch(d) {
			case 0:
				img.css({width:big["width"]+'px', height:big["height"]+'px'});
				a.css({height:big["height"]+'px'});
			break;
			case 1:
				img.css({width:small["width"]+'px', height:small["height"]+'px'});
				a.css({width:small["width"]+'px', height:small["height"]+'px'});
			break;
			default:
				a.css({display:'none', width:'0px', height:'0px'});
			break;
		}
	});
	$('#carousel .left_arrow').click( function () {
		if (actual_change(-1))
			equilibrate();
		return false;
	});
	$('#carousel .right_arrow').click( function () {
		if (actual_change(+1))
			equilibrate();
		return false;
	});
});
