$(document).ready( function () {

	$('#label_admin').ready( function () {

		$('#label_admin').parent().children('form').slideUp( 'slow' );
		$('#label_admin').css( 'cursor', 'pointer' );

		$('#label_admin').live( "click", function ( e ) {

			if ( $('#label_admin').parent().children('form').css( 'display' ) == 'none' ) {

				$('#label_admin').parent().children('form').slideDown( 'slow' );

			}

			else {

				$('#label_admin').parent().children('form').slideUp( 'slow' );

			}

		} );

	} );

	$("#frm_allocineId").live( "keyup", function ( e ) {

		if ( e.which == 32 ) {

			$.ajax( {

				type: "POST",
				url: "jQuery.php",
				data: "adm="+ $(this).val(),
				success: function ( html ) {

					$("#frm_result").html( html ).fadeIn( 'slow' );

				}

			} );

			$.ajax( {

				type: "POST",
				url: "jQuery.php",
				data: "s="+ $(this).val(),
				success: function ( html ) {

					$("#rightcpsrstsrc ul").html( html ).fadeIn( 'slow' );

				}

			} );

		}

	} );

	$("#search").live( "keyup", function ( e ) {

		$.ajax( {

			type: "POST",
			url: "jQuery.php",
			data: "s="+ $(this).val(),
			success: function ( html ) {

				$("#rightcpsrstsrc ul").html( html ).fadeIn( 'slow' );

			}

		} );

	} );

	$("#rightcpsrstsrc ul li a").live( "click", function () {

		//console.log($(this).parent().attr( 'rel' ));

		if ( $(this).parent().attr( 'rel' ) > 0 ) {

			$.ajax( {

				type: "POST",
				url: "jQuery.php",
				data: "id="+ $(this).parent().attr( 'rel' ),
				success: function ( html ) {

					$('#page').animate( {

						width: "950px"

					}, 750 );

					$("#rightpage").html( html ).fadeIn( 'slow' );

				}

			} );

		}

	} );

	$("#frm_result a").live( "click", function () {

		$("#frm_allocineId").val( $(this).attr( 'rel' ) );

		return false;

	} );

	$("#rightcpsrstsrc ul li a").live( "mouseover", function () {

		$("#rightcpsrstsrc ul li a").removeClass( 'titreOn' );
		$(this).addClass( 'titreOn' );

		//console.log($(this).parent().attr( 'rel' ));

		if ( $(this).parent().attr( 'rel' ) > 0 ) {

			$.ajax( {

				type: "POST",
				url: "jQuery.php",
				data: "aff="+ $(this).parent().attr( 'rel' ),
				success: function ( html ) {

					$("#leftcpsrstsrc").html( html ).fadeIn( 'slow' );

				}

			} );

		}

	} );

	$('#form_divx .chk').live('click', function(){
		var id_allocine = $(this).attr('id_allocine');
		var chemin_ftp = $(this).attr('chemin_ftp');

		var thisel = $(this);

		$.post(
			'jQuery.php',
			{ 'id_allocine': id_allocine, 'chemin_ftp': chemin_ftp, 'action': 'add_queue' },
			function( data ) {
				thisel.parent('div').fadeOut('slow');
			}
		);

		return false;
	});

	$('.change_id').keyup(function () {
		var newVal = $(this).val();
		$(this).parent('div').find('.chk').attr( 'id_allocine', newVal );
	});

} );