slider = new Array();
big = new Array();
big["width"] = 218;
big["height"] = 300;
big["height2"] = big["height"];
small = new Array();
small["width"] = 218;
small["height"] = 300;
small["height2"] = small["height"];
font = new Array();
font["big"] = 16;
font["small"] = 12;
timer = -1;
var image = 0;

function equilibrate(mov) 
{

	var start = (4*actual);
	var k = 0;
	var loop_till = (start+4);
	for( var i=0;i<max;  i++ ) 
	{
		var a = $('#image'+i);
		var img = a.children('a').children('img');
		var ttl = a.children('.imtitle');
		if((i>=start) && (i<loop_till))
		{
			img.attr("src",images[i]);
			img.animate({width: small["width"], height: small["height"]}, function () { ttl.fadeTo(1000, 1); });
			a.animate({width: small["width"], height: small["height2"]});
			if(((i+4) < (max-1)) && (images[i+4]))
			{
				//alert(images[i+4]);
				MM_preloadImages(images[i+4]);
			}
			if(((max-i) > 0) && (images[max-i]))
			{
				//alert(images[max-i]);
				MM_preloadImages(images[max-i]);
			}	
		}
		else
		{
			a.css({display: 'none', width: '0px', height: '0px'});
		}
	}
	return false;
}
/*function actual_change(diff) {
	if ((actual + diff > -1) && (actual + diff < max-1)) 
	{
		actual = actual + diff;
	//	alert(actual);
		return true;
	}
	else
	{

		return false;
	}
};*/
/*function directlink() {
	$('#directlink').attr('href', location.href.replace(location.search, '') + '?show=' + actual);
}*/
$(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><a><img src="../images/vide.png" alt="" /></a></li>');
//	$('#slider ul').prepend('<li><a><img src="../images/vide.png" alt="" /></a></li>');
	max = $('#slider ul li').size();
//	alert(max);
	i = (tab_elts["show"]) ? parseInt(tab_elts["show"]) : 0;
	//actual = (!isNaN(i) && i > 0 && i < max) ? i : 1;
	actual = 0;
	actual_length = Math.floor(max/4);


	$('#slider ul li').each( function(i) {
		d = Math.abs(i);
		var a = $(this);
		var img = a.children('a').children('img');
		var ttl = a.children('.imtitle');
		switch(d) {
			case 2:
				img.attr("src",images[d]);
				img.css({width: big["width"]+'px', height: big["height"]+'px'});
				a.css({width: big["width"]+'px', height: big["height2"]+'px'});
				if(images[d+4])
				{
					MM_preloadImages(images[d+4]);
				}
				if(images[max-3])
				{
					MM_preloadImages(images[max-3]);
				}
			
			//	parent.objImage2.src=parent.images[d+4];
				image=image+1;
			break;
			case 1:
				img.attr("src",images[d]);				
				img.css({width: small["width"]+'px', height: small["height"]+'px'});
				a.css({width: small["width"]+'px', height: small["height2"]+'px'});
				if(images[d+4])
				{
					MM_preloadImages(images[d+4]);
				}
				if(images[max-2])
				{
					MM_preloadImages(images[max-2]);
				}
				
			//	parent.objImage1.src=parent.images[d+4];
				image=image+1;
			break;
			case 3:
				img.attr("src",images[d]);
				img.css({width: small["width"]+'px', height: small["height"]+'px'});
				a.css({width: small["width"]+'px', height: small["height2"]+'px'});
				if(images[d+4])
				{
					MM_preloadImages(images[d+4]);
				}
				if(images[max-4])
				{
					MM_preloadImages(images[max-4]);
				}
				image=image+1;
			break;
			case 0:
				img.attr("src",images[d]);
				img.css({width: small["width"]+'px', height: small["height"]+'px'});
				a.css({width: small["width"]+'px', height: small["height2"]+'px'});
				if(images[d+4])
				{
					MM_preloadImages(images[d+4]);
				}
				if(images[max-1])
				{
					MM_preloadImages(images[max-1]);
				}
				//parent.objImage0.src=parent.images[d+4];
				image=image+1;
			break;
			default:
				a.css({display: 'none', width: '0px', height: '0px'});
			break;
		}
	});
	$('#butleft').click( function () 
	{
		if (typeof ClickTaleExec == "function")
		{
		ClickTaleExec("$('#butleft').click");
			//alert("Mouse click Called");
		}
		
		if(max > 4)
		{
			actual = actual - 1;
			if(actual < 0)
			{
				actual = actual_length;
			}

			equilibrate(-1);
		}
		return false;
	});
	$('#butright').click( function () 
	{
		if (typeof ClickTaleExec == "function")
		{
		ClickTaleExec("$('#butright').click");
			//alert("Mouse click Called");
		}

		if(max > 4)
		{
			actual = actual+1;
			if(actual > actual_length)
			{
				actual = 0;
			}
		
			equilibrate(+1);
		}
		return false;
	});
	$('#playpause').click( function () {
		var a = $('#playpause').children('img').attr('src');
		var a = a.split("/");
		if (a[a.length - 1] == 'pause.png') {
			//timer_stop();
		}
		else {
			next();
			timer = window.setInterval("next()", 2200);
			$('#playpause').children('img').attr('src', '../images/pause.png');
		}

		return false;
	});
	$('#slider ul li a').click( function () {
		timer_stop();
	});
/*
	$('#slider').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 timer_stop() {
/*	var a = $('#playpause').children('img').attr('src');
	var a = a.split("/");
	if (a[a.length - 1] == 'pause.png') {
		$('#playpause').children('img').attr('src', '../images/playred.png');
		window.clearInterval(timer);
	}
	alert("sgdshgds");*/
	return false;
}
function next() {
	if (actual_change(+1))
		equilibrate();
}
function rotate() {

	//alert(max + ' ' + actual + ' ' + (max - actual));
/*	if(max-actual == 3)
	{
		var a = $('#slider ul li:first').add();
			$('#slider ul').append(a);
	}*/
//alert("diff-->"+(max-actual));
/*if (actual > max / 2) {
	var a = $('#slider ul li:first').remove();
			$('#slider ul').append(a);
//	alert(actual);
	/*	var a = $('#slider ul li').eq(0);
		$('#slider ul').append(a);
		actual = actual + 1;
		//actual=-1;
	}*/
/*	if(diff == actual)
	{
		var a = $('#slider ul li:last').remove();
			$('#slider ul').prepend(a);
			actual = actual-1;
	}*/
	/*if(max-actual == 2)
	{
		var a = $('#slider ul li:first').remove();
			$('#slider ul').append(a);
	}*/



	/*	if (diff < 0) {
			var a = $('#slider ul li:last').remove();
			$('#slider ul').prepend(a);
		}
		else {
			var a = $('#slider ul li:first').remove();
			$('#slider ul').append(a);
		}*/

}
function showtext(id) {
	$('#texts .text').each( function (i) {
		if ($(this).css('display') != 'none')
			//$(this).fadeOut('fast');
			$(this).hide();
	});
	$('#texts #text'+id).slideDown('slow');
}