slider = new Array();
big = new Array();
big["width"] = 283;
big["height"] = 120;
big["height2"] = big["height"] + 28;
small = new Array();
small["width"] = 243;
small["height"] = 104;
small["height2"] = small["height"] + 28;
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');
		var ttl = a.children('.imtitle');
		
		switch(d) {
			case 0:					
				img.animate({width: big["width"], height: big["height"]});
				a.addClass('zindex10');
				a.removeClass('zindex0');
				a.animate({opacity: 1.0, width: big["width"], height: big["height2"],top: '-10px'}, function () { ttl.css({'font-size': font["big"]+'px'});a.removeClass('zindex0');a.addClass('zindex10')});
			break;
			case 1:
				ttl.css({'font-size': font["small"]+'px'});
				if (slider[i] == 1) {
					slider[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"]}, function () { ttl.fadeTo(500, 1);});
				a.addClass('zindex0');
				a.removeClass('zindex10');
				a.animate({opacity: 0.8, width: small["width"], height: small["height2"], top: '0px'}, function () {a.addClass('zindex0');a.removeClass('zindex10')});


			break;
			default:				
				if (slider[i] != 1) {
					slider[i] = 1;
					a.hide('fast');
				}
			break;
		}
	});

}
function actual_change(diff) {
	
	max = $('#slider ul li').size();
	if (actual + diff > 0 && actual + diff < max) {
		actual = actual + diff;
		return true;
	} 
		
	return false;
};

function directlink() {
	$('#directlink').attr('href', location.href.replace(location.search, '') + '?show=' + actual);
}


$(document).ready(function(){

	if($('#slider').is("div")) {
		for(i=0;i<$('#slider ul li').length; i++) {
			$($('#slider ul li')[i]).children().children().empty();
			alink = $($('#slider ul li')[i]).children().clone();
			$($('#slider ul li')[i]).empty();
			$($('#slider ul li')[i]).append(alink.html());
			$($('#slider ul li')[i]).children().append('<img src="images/slider/slider_' + $($('#slider ul li')[i]).attr('class') + '.jpg" width="283" height="120" />');								
		}
		
	}

	
	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');
	max = $('#slider ul li').size();
	i = (tab_elts["show"]) ? parseInt(tab_elts["show"]) : 0;
	
	var startItem = 1;
	if(Math.ceil(max/2) == max/2) {
		startItem = max/2;
	} else {
		startItem = (max/2)-0.5;
	}
	
	actual = (!isNaN(i) && i > 0 && i < max) ? i : startItem;
	
	$('#slider ul li').each( function(i) {			
		d = Math.abs(actual - i);
		var a = $(this);
		var img = a.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'});
				a.addClass('zindex10');
				a.css({opacity: 1.0,top: '-10px', height: big["height2"]+'px'});				
			break;
			case 1:
				img.css({width: small["width"]+'px', height: small["height"]+'px'});
				a.addClass('zindex0');
				a.css({opacity: 0.8, 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();			
		}		
		if(actual == 1) {
			actual = $('#slider ul li').size()-1 ;		    
		}
			
		return false;
	});
	
	$('#butright').click( function () {
		if (actual_change(+1)) {				
			equilibrate();			
		}				
		if(actual == $('#slider ul li').size()-1) {
			$.each($('#slider ul li'), function() {
		      var liClone = $(this).clone();		      	     		      
		      $('#slider ul').append(liClone);
		    });		    
		}
				
		return false;		
		
	});

});
