/*-----SLIDESHOW-----*/
/*
$(document).ready(function() {
    $('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
});
*/

var current_position = 0;
var tmp_size = new Array();

$(document).ready(function()
{
    var string_effect = myEffect;
    var _startingSlide = 0;
    if(random == true) {
        _startingSlide = Math.floor(Math.random() * timeout.length);
        current_position = _startingSlide;
        
        var j = _startingSlide;
        string_effect = string_effect+'';
        var array_effect = string_effect.split(',');
        while(j > 0)
        {
            array_effect.push(array_effect.shift());
            j--;
        }
        string_effect = array_effect.join(',');
    }
   
    //$('.slideshow img').load(function(){
        //var id_image = $(this).attr('class').split('_');
         var id_image = $('.slideshow .img_'+current_position).attr('class').split('_');
        
        tmp_size[parseInt(id_image[1])] = new Array();
        tmp_size[parseInt(id_image[1])]['width'] = $('.slideshow .img_'+current_position).width();
        tmp_size[parseInt(id_image[1])]['height'] = $('.slideshow .img_'+current_position).height();
    //});
    
    //$('.slideshow .img_'+current_position).load(function(){
        $('.slideshow').cycle({
                    fx: string_effect+'',
                    randomizeEffects: 0,
                    autostop: 1,
                    startingSlide: _startingSlide,
                    height: 220,
                    width: 782,
                    autostopCount: 1
        });
        nextTransition(timeout[current_position]);
        initializeAnimation();
    //});
    
});

function nextTransition(tim) {
    hideContent();
    showContent();
    window.setTimeout("goNext()", tim);
}
function goNext()
{
    current_position=(current_position+1)%timeout.length;
    $('.slideshow img').stop();
    initializeAnimationReset();
    $('.slideshow').cycle('next');
    window.setTimeout("initializeAnimation()", 1000);

    nextTransition(timeout[current_position]);
}
function hideContent() {
    $('.slideshow_text div').hide();
    $('.slideshow_lien div').hide();
}
function showContent() {
    $('.slideshow_text div.text_'+current_position).show();
    $('.slideshow_lien div.lien_'+current_position).show();
}

/*-----ANIMATION-----*/
function initializeAnimation()
{
    var time_out = parseInt(animationTimeout[current_position]);
    if(animationTimeout[current_position] != '') {
        $('.slideshow .img_'+current_position).animate(
            {
                width:(tmp_size[current_position]['width']*parseInt(animationEndScale[current_position]))/100+'px',
                height:(tmp_size[current_position]['height']*parseInt(animationEndScale[current_position]))/100+'px',
                left:(parseInt(animationEndX[current_position]))+'px',
                top:(parseInt(animationEndY[current_position]))+'px'
            }, time_out
        );
    }
}
function initializeAnimationReset()
{
    var time_out = parseInt(animationTimeout[current_position]);
    if(animationTimeout[current_position] != '') {
        $('.slideshow .img_'+current_position).css(
            {
                width:(tmp_size[current_position]['width']*parseInt(animationStartScale[current_position]))/100+'px',
                height:(tmp_size[current_position]['height']*parseInt(animationStartScale[current_position]))/100+'px',
                left:(parseInt(animationStartX[current_position]))+'px',
                top:(parseInt(animationStartY[current_position]))+'px'
            });
    }
}

/* FORM CONTACT */
function changeSubject(optValue)
{
	var myIndex = parseInt(optValue);
	
	if(myIndex > 0)
	{
		if(myIndex == 2)
		{
			$('#contener_form_aide1').css("display", "block");
			$('#contener_form_aide2').css("display", "none");
			$('#contener_form_contact').css("display", "none");
		}
		else if(myIndex == 3)
		{
			$('#contener_form_aide2').css("display", "block");
			$('#contener_form_contact').css("display", "none");
			$('#contener_form_aide1').css("display", "none");
		}
		else
		{
			$('#contener_form_contact').css("display", "block");
			$('#contener_form_aide1').css("display", "none");
			$('#contener_form_aide2').css("display", "none");
		}
	}
	else
	{
		$('#contener_form_contact').css("display", "none");
		$('#contener_form_aide').css("display", "none");
	}
}
