slider = new Array();
big = new Array();
big["width"] = 222;
big["height"] = 230;
big["height2"] = big["height"];
small = new Array();
small["width"] = 222;
small["height"] = 230;
small["height2"] = small["height"];
font = new Array();
font["big"] = 12;
font["small"] = 12;
timer = -1;
is_animate_finished = true;

function equilibrate() {
    $('#butleft').css({ visibility: 'visible' });
    $('#butright').css({ visibility: 'visible' });
    if (actual == 1) {
        $('#butleft').css({ visibility: 'hidden' });
    }
    if (actual == max -1) {
        $('#butright').css({ visibility: 'hidden' });
    }
    
     //actual - last index that will be displayed
    $('#slider ul li').each(function(i) {
        is_animate_finished = false;
        d = Math.abs(actual - i);
        var a = $(this);
        var img = a.children('a').children('img');
        switch (d) {
            case 0:
                //middle image
                
                img.animate({ width: big["width"], height: big["height"] });
                a.animate({ width: big["width"], height: big["height2"] }, function() {
                    is_animate_finished = true;
                   
                }
                );
                
                break;
            case 1:
                //1 and 3-d images
                
                //if (a.css('display') == 'none') {
                if (slider[i] == 1) {
                    //last right slider that display when right click 
                    //or first img when click left
                    slider[i] = 0;
                    a.css({ display: 'inline', width: '0px', height: '0px' });
                    img.css({ width: '0px', height: '0px' });
                    
                }
                a.animate({ width: small["width"], height: small["height2"] }, function() { is_animate_finished = true; });
                img.animate({ width: small["width"], height: small["height"] }, function() {
                   
                    is_animate_finished = true;
                });
                break;
            default:
                if (slider[i] != 1) 
                {
                    slider[i] = 1;
                    a.hide();
                }
                break;
        }
    });
	directlink();
}
function actual_change(diff) {
	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() {
    $('#butleft').css({ visibility: 'hidden' });
    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>');
    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 .text').appendTo("#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:
                //ttl.css({'font-size': font["big"]+'px'});
                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 (is_animate_finished == true) {
            if (actual_change(-1))
                equilibrate();
            
        }
        return false;
    });
    $('#butright').click(function() 
    {
        if (is_animate_finished == true) 
        {
            if (actual_change(+1))
                equilibrate();
            //timer_stop();
        }
        return false;
    });
    
  

});

