var theSlider = new Array();
var big = new Array();
big["width"] = 410;
big["height"] = 307;
big["height2"] = big["height"] + 28;
var small = new Array();
small["width"] = 230;
small["height"] = 172;
small["height2"] = small["height"] + 21;
var font = new Array();
font["big"] = 16;
font["small"] = 12;
var timer = -1;

function equilibrate() {
	$('#slider ul li').each(function(i) {
		d = Math.abs(actual - i);
		var a = $(this);
		var img = a.children('p').children('a').children('img');
		var ttl = a.children('.imtitle');
		switch(d) {
			case 0:
				img.animate({width: big["width"], height: big["height"], opacity: '1'});
				a.animate({width: big["width"], height: big["height2"]}, function () { ttl.css({'font-size': font["big"]+'px'}); });
			break;
			case 1:
				ttl.css({'font-size': font["small"]+'px'});
				//if (a.css('display') == 'none') {
				if (theSlider[i] == 1) {
					theSlider[i] = 0;
					a.css({display: 'inline', width: '0px', height: '0px'});
					img.css({width: '0px', height: '0px'});
					ttl.css({opacity: '0'});
				}
				img.animate({width: small["width"], height: small["height"], opacity: '0.5'}, function () { ttl.fadeTo(500, 1); });
				a.animate({width: small["width"], height: small["height2"]});
			break;
			default:
				if (theSlider[i] != 1) {
					theSlider[i] = 1;
					a.hide('fast');
				}
			break;
		}
	});
	rotate();
}
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]);
	}

	$('#slider ul').css('overflow', 'hidden');
	$('#slider ul').prepend('<li></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').each( function(i) {
		d = Math.abs(actual - i);
		var a = $(this);
		var img = a.children('p').children('a').children('img');
		var ttl = a.children('.imtitle');
		switch(d) {
			case 0:
				ttl.css({'font-size': font["big"]+'px'});
				img.css({width: big["width"]+'px', height: big["height"]+'px', opacity: '1'});
				a.css({height: big["height2"]+'px'});
			break;
			case 1:
				img.css({width: small["width"]+'px', height: small["height"]+'px', opacity: '0.5'});
				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;
	});
	$('#butright').click( function () {
		if (actual_change(+1))
			equilibrate();
		return false;
	});
/*
	$('#theSlider').mousewheel(function(objEvent, intDelta){
		if (intDelta > 0) {
			if (actual_change(-1))
				equilibrate();
		}
		else if (intDelta < 0) {
			if (actual_change(+1))
				equilibrate();
		}
		return false;
	});
*/
	//timer = window.setInterval("next()", 3000);
});
function next() {
	if (actual_change(+1))
		equilibrate();
}
function rotate() {
	//alert(max + ' ' + actual + ' ' + (max - actual));
/*
	if (actual < (max / 2)) {
		var a = $('#theSlider ul li').eq(max-1).remove();
		$('#theSlider ul').prepend(a);
		actual = actual + 1;
	}
*/
/*
		if (diff < 0) {
			var a = $('#theSlider ul li:last').remove();
			$('#theSlider ul').prepend(a);
		}
		else {
			var a = $('#theSlider ul li:first').remove();
			$('#theSlider ul').append(a);
		}
*/
}
