/**
* Yffic lefourneau.com d'apres
* EasyDrag 1.4 - Drag & Drop jQuery Plug-in
*
* Thanks for the community that is helping the improvement
* of this little piece of code.
*
* For usage instructions please visit http://fromvega.com
*/


	// to track the current element being dragged
	var currentElement = null;
	var inter_on = false ;
	
	$.fn.initChangeCursor = function(url){
		baseURL=url;
		$("#interrupteur").mousedown(function(e){
			var inter = document.getElementById("interrupteur");
			if(inter_on) {
				$("body").css("cursor", "default");
				$("a").css("cursor", "hand");
				inter_on=false;
				inter.src="http://www.utopium-theatre.com/commun/interupteuroff.png" ;
				$("#curseurgeant").stopdrag();
			} else {
				$("body").css("cursor", "url('http://www.utopium-theatre.com/commun/curseur-vide.cur'),default");
				$("a").css("cursor", "url('http://www.utopium-theatre.com/commun/curseur-vide.cur'),hand");
				inter_on=true;
				inter.src="http://www.utopium-theatre.com/commun/interupteuron.png" ;
				// add drag and drop functionality to #box1
				$("#curseurgeant").easydrag(e);
			}
		});
		return true ;
	};


	// returns the mouse (cursor) current position
	$.getMousePosition = function(e){
		var posx = 0;
		var posy = 0;

		if (!e) var e = window.event;

		if (e.pageX || e.pageY) {
			posx = e.pageX ;
			posy = e.pageY ;
		}
		else if (e.clientX || e.clientY) {
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft ;
			posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop ;
		}

		return { 'x': posx, 'y': posy };
	};

	// updates the position of the current element being dragged
	$.updatePosition = function(e) {
		var pos = $.getMousePosition(e);

		$(currentElement).css("top",  pos.y + 1);
		$(currentElement).css("left", pos.x + 1);
	};

	// when the mouse is moved 
	$(document).mousemove(function(e){
		if(inter_on){
			// update the position and call the registered function
			$.updatePosition(e);

			return false;
		}
	});

	// set an element as draggable - allowBubbling enables/disables event bubbling
	$.fn.stopdrag = function(e){
		$(this).css("visibility", "hidden");
	}
	
	$.fn.easydrag = function(e){
		return this.each(function(){

			// if no id is defined assign a unique one
			if(undefined == this.id || !this.id.length) this.id = "easydrag"+(new Date().getTime());
			
			// set it as absolute positioned
			$(this).css("visibility", "visible");

			// set z-index
			$(this).css("z-index", "10000");
			largeur = this.firstChild.width;
			hauteur = this.firstChild.height;
			// update track variables
			currentElement = this;
	
			$.updatePosition(e);

			return true;
		});
	};

