slider = new Array();
big = new Array();
big["width"] = 200;
big["height"] = 130;
big["height2"] = big["height"] + 35;
small = new Array();
small["width"] = 100;
small["height"] = 65;
small["height2"] = small["height"] + 35;
font = new Array();
font["big"] = 16;
font["small"] = 12;
timer = -1;

function equilibrate() {
	$('#slider 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["height2"]});
				showtext(a.attr('id').substr(5));
			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["height2"]});
			break;
			default:
				if (slider[i] != 1) {
					slider[i] = 1;	
				}
				a.hide('fast');
				a.css({width: small["width"], height: small["height"]});
			break;
		}
	});
}
function actual_change(diff) {
	if (actual + diff > 0 && actual + diff < max) {
		actual = actual + diff;
		$("#scroll").slider('option', 'value', (actual-1)*$("#scroll").slider('option', 'step'));
		return true;		
	}
	return false;
};

function actual_change_to_element(diff) {
	if ( diff > 0 &&  diff < max) {
		actual = diff;
		equilibrate();
		return true;
	}
	if(diff == 0)
	{
		actual = 1;
		equilibrate();
		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]);
	}

	$('#slider ul').css('overflow', 'hidden');
	$('#slider ul').prepend('<li class="empty"><a><img src="img/logo_blank.gif" alt="" /></a></li>');
	max = $('#slider ul li').size();

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

	$('#slider ul li .slider-text').appendTo("#slider-texts");
	$('#slider 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["height2"]+'px'});
				showtext(a.attr('id').substr(5));
			break;
			case 1:
				img.css({width: small["width"]+'px', height: small["height"]+'px'});
				a.css({width: small["width"]+'px', height: small["height2"]+'px'});
			break;
			default:
				a.css({display: 'none', width: '0px', height: '0px'});
			break;
		}
	});
	$('#butleft').click( function () {
		if (actual_change(-1)) {
			equilibrate();		
			return false;
		}

		return false;
	});
	$('#butright').click( function () {
		if (actual_change(+1))
		{
			equilibrate();
			return false;
		}

		return false;
	});
});

function showtext(id) {
	$('#slider-texts .slider-text').each( function (i) {
		if ($(this).css('display') != 'none')
			$(this).hide();
	});
	$('#slider-texts #slider-text'+id).fadeIn('slow');
}


	