$(function() {
	
  	$("a[rel]").overlay({

		expose: '#f1f1f1', 
		effect: 'apple',

		onBeforeLoad: function() {

			// grab wrapper element inside content
			var wrap = this.getContent().find(".contentWrap");

			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"));
		}

	});

    $("#changeText").live('click', function(){ 
      	 
        var url = $(this).attr("href"); 
 
        $("#content").load(url, {var1:Math.random()*99999}); 
                 
        //$('html,body').animate({scrollTop: 10}, 1000, 'swing'); 
                 
        return false; 
    }); 
    
	// ------------------------------------------------
	// Action lorsqu'on supprime une tāche (clic sur la poubelle)
	// ------------------------------------------------

		$('div.ulTimeline > ul > li')
		.livequery('click', function(ev) {
		
			//alert("clic1");
			var $item = $(this);
			var $target = $(ev.target);
			
			// ------------
			// suppression
			// ------------
			
			if ($target.is('div.poubelle > img')) {
				//alert($target.parent().attr("id"));
					
			$.ajax({
				   type: "POST",
				   url:  "aj_skill_removed_from_timeline.php",
				   data: "timeline="+$target.parent().attr("id"),
						   							
				  success: function(msg){
					$item.remove();   
				   }
				});			
			
			}
		});
		

	// ------------------------------------------------
	// Action lorsqu'on modifie une tāche (clic sur le dialogue)
	// ------------------------------------------------

		$('div.ulTimeline > ul > li')
		.livequery('click', function(ev) {

			
			var $item = $(this);
			var $target = $(ev.target);
					
			if ($target.is('div.dialogue > img')) {
				$('#dialog').dialog('open');
				$.ajax({
					   type: "POST",
					   url:  "aj_update_timeline_1.php",
					   data: "timeline="+$target.parent().attr("id"),
							   							
					  success: function(msg){
						var obj = (new Function("return " + msg))();
						//alert(obj.max);
						$('#dialog').dialog('open');
						$('#slider').slider('option', 'max', obj.max);								
						$('#slider').slider('option', 'value', obj.concentration);
						$('#amount').val(obj.concentration);
						$('#dialog').dialog('open');								
						
						$('#dialog').dialog('option', 'buttons', { "Ok": 
						function(){ 
						
						var $concentration = $('#amount').val();
						var id = $target.parent().attr("id");
						//alert($concentration);	
						$.ajax({
							   type: "POST",
							   url:  "aj_update_timeline_2.php",
							   data: "timeline="+id+"&concentration="+$concentration,
							   
							  success: function(msg){
								if(msg != 'failure')
								{
									$('#c_'+id).text(''+$concentration+'%');
								}							
							   }
							 });						
						
						$(this).dialog("close"); 
							
						} });								
						
					   }
					});		
			
			}
		});  

});
