$(document).ready(
	function () {
		$('a.delete_button').bind('click', toggleContent);
		$('div.groupItem').bind('mouseover',effetModuleOn);
		$('div.groupItem').bind('mouseout',effetModuleOff);
		$('a.change_color').bind('click',showCouleur);
		$('a.edit_button').bind('click',showEdit);
		$('div.groupWrapper').Sortable(
			{
				accept: 'groupItem',
				helperclass: 'sortHelper',
				activeclass : 'sortableactive',
				hoverclass : 'sortablehover',
				handle: 'div.itemHeader',
				tolerance: 'pointer',
				
				onChange : function(ser)
				{
					save();
				},
				onStart : function()
				{
					$.iAutoscroller.start(this, document.getElementsByTagName('body'));
				},
				onStop : function()
				{
					$.iAutoscroller.stop();
				}
			}
		);
	}
);
var toggleContent = function(e)
{
	var targetContent = $(this.parentNode.parentNode);
		targetContent.addClass("delete");
		targetContent.slideUp(300);
		save();
	return false;
};

var effetModuleOn = function(e)
{
	var targetContent = $('div.itemHeader a', this);
	var targetContentHead = $('div.itemHeader', this);
	if (targetContentHead.is(".headerBleu")) {
		targetContent.css('color','#FFFFFF');
	} else {
		targetContent.css('color','#000000');
	}
	return false;
};

var effetModuleOff = function(e)
{
	var targetContent = $('div.itemHeader a', this);
		targetContent.css('color','#AAAAAA');
	return false;
};

var showCouleur = function(e)
{
	var targetContentCouleur = $('div.zone_color', this.parentNode.parentNode);
	var targetContentEdit = $('div.zone_edit', this.parentNode.parentNode);
	targetContentEdit.hide();
	if (targetContentCouleur.css('display') == 'none') {
		targetContentCouleur.slideDown(300);
	} else {
		targetContentCouleur.slideUp(300);
	}

	return false;
};

var showEdit = function(e)
{
	var targetContentEdit = $('div.zone_edit', this.parentNode.parentNode);
	var targetContentCouleur = $('div.zone_color', this.parentNode.parentNode);
	targetContentCouleur.hide();
	if (targetContentEdit.css('display') == 'none') {
		targetContentEdit.slideDown(300);
	} else {
		targetContentEdit.slideUp(300);
	}

	return false;
};


function changeColor2(bloc, color) {
	
  var targetContent = $('div:eq(0)',bloc.parentNode.parentNode);
  for(var i = 0; i < 10; i++) {
    if(targetContent.is(".itemHeader color"+i)) {
      targetContent.removeClass("color"+i);
    }
  }
  if(targetContent.is(".itemHeader")) {
   targetContent.addClass(color);
  }
save();
}
