$(document).ready(function(){
	
	// On réinitialise les valeurs des inputs dans le formulaire de connexion au clic
	$('.input_connexion').click(function(){
		$(this).val('');
	});	
	$('#input_myrss').focus(function(){
		$('#myrss').attr('checked', true);
	});
	$('.title_message_input').click(function(){
		$(this).val('');
	});
	$('.input_search').click(function(){
		if($(this).val()=='Rechercher'){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val()=='' || $(this).val()==' '){
			$(this).val('Rechercher');
		}
	});
	

	/* Début menu barre haut */
	
	$('.header_bouton_menu').each(function(){
		var time = 250;
        var hideDelay = 30;
        var hideDelayTimer = null;

		var menu = $(this);
        var ss_menu = $('#ssmenu_'+$(this).attr('id'));
		
		$([ss_menu.get(0), menu.get(0)])
			.mouseover(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				ss_menu.show();
				
			})
			.mouseout(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
					ss_menu.hide();
                }, hideDelay);	
			});
		});
	
	/* Fin menu barre haut */
	
	
	/* Menu navigation */
	
	$('.item_menu').each(function(){
		var time = 250;
        var hideDelay = 30;
        var hideDelayTimer = null;

		var menu = $(this);
        var ss_menu = $('#ss_menu_'+$(this).attr('id'));
		
		$([ss_menu.get(0), menu.get(0)])
			.mouseover(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				ss_menu.show();
				
			})
			.mouseout(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
					ss_menu.hide();
                }, hideDelay);	
			});
		});
	
	/* Fin menu navigation */
	
	$(".corps_col_droite").sortable({ 
		connectWith: '.corps_col_droite',
		handle: '.sortable_item_head',
		items: '.sortable_item',
		helper: 'clone',
		opacity:'0.6',
		placeholder: 'sortable_item_helper',
		tolerance : 'pointer',
		update : function () { 
			if($("#etats").html()==1){
				$.ajax({
					url: './ajax/ajax_sort.php',
					type: 'get',
					data: 'col=gauche&'+$("#sort_gauche").sortable('serialize')
				});
				$.ajax({
					url: './ajax/ajax_sort.php',
					type: 'get',
					data: 'col=milieu&'+$("#sort_milieu").sortable('serialize')
				});
				$.ajax({
					url: './ajax/ajax_sort.php',
					type: 'get',
					data: 'col=droite&'+$("#sort_droite").sortable('serialize')
				});								
			}else{
				alert('Pour enregistrer vos paramètres, vous devez vous connecter...')
			}
		} 
	});
	
	$('.ctrlbox').click(function(){
		$('.header_message_box').toggle();
	});
	$('.ctrlbox_n').click(function(){
		$('.header_notification_box').toggle();
	});
	
	$("#actu_suivant").click(function(){
		$('.news_nav_p').show();
		$(this).css({'margin-left':'0'});
		$('.news_cont').html('').addClass('news_cont_load');
		$.ajax({
			url: './ajax/ajax_actu.php',
			type: 'get',
			data: 'type=suivant',
			success: function(data) {
			$('.news_cont').html(data);
		}});
	});
	$("#actu_precedent").click(function(){
		$('.news_cont').html('').addClass('news_cont_load');
		$.ajax({
			url: './ajax/ajax_actu.php',
			type: 'get',
			data: 'type=precedent',
			success: function(data) {
			$('.news_cont').html(data);
		}});
	});
	
	/**
	 * Enables/Disables text selection, saves selected text
	 *   
	 * @example jQuery('p').enableTextSelect(); / jQuery('#selectable-area').disableTextSelec();
	 * @cat plugin
	 * @type jQuery 
	 *
	 */
	jQuery.fn.disableTextSelect = function() {
	  return this.each(function() {
	    $(this).css({
	      'MozUserSelect' : 'none'
	    }).bind('selectstart', function() {
	      return false;
	    }).mousedown(function() {
	      return false;
	    });
	  });
	};

	jQuery.fn.enableTextSelect = function() {
	  return this.each(function() {
	    $(this).css({
	      'MozUserSelect':''
	    }).unbind('selectstart').mousedown(function() {
	      return true;
	    });
	  });
	};
		
	$('.col_article').disableTextSelect();
});
