var drop;
function init_drag_to_mh() {
	drop = $('mh_dropbox');
	var list_items = $$('#mh_dropbox li');
	$$('.draggable_to_mh').each(function(item){
	 
		item.addEvent('mousedown', function(e) {
			
			///*
			//e = new Event(e);//.stop();
	 		// output(this.className);
			var clone = this.clone()
				.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
				.setStyles({'opacity': 0.7, 'position': 'absolute', 'z-index': 400})
				.store('time_created', $time())
				.addEvent('emptydrop', function() {
					this.remove();
					drop.removeEvents();
				}).inject(document.body);
			
			// CHECKEN OF IE ALLEEN MAAR AANGEKLIKT IS, DAN NAAR LINK
			clone.store('og_left', clone.getStyle('left'));
			clone.store('og_top', clone.getStyle('top'));

			clone.addEvent('mouseup', function() {
				var cur_left = this.getStyle('left');
				var og_left = this.retrieve('og_left');
				var cur_top = this.getStyle('top');
				var og_top = this.retrieve('og_top');
				if((cur_left==og_left) && (cur_top==og_top)) {
					window.location = this.href;
				}
				/*
				output('OG-L: '+og_left+' | C-L: '+cur_left);
				output('OG-T: '+og_top+' | C-T: '+cur_top);
				output(this.href);
				*/
			});

			var drag = clone.makeDraggable({
			 
			    droppables: [drop],
			 	precalculate: true,
			    onDrop: function(element, droppable, event){
			        if (!droppable) {
			        	// CHECK OF DE GEWONE LINK MOET WORDEN GEVOLGD
			        	//output(' dropped on nothing | droppable = '+droppable+' dragged left = '+element.getStyle('left'));
			        	//output(' time created '+element.retrieve('time_created')+' |  cur time: '+ $time()+' | OG left: '+element.retrieve('og_left'));
			        	element.destroy();
			        	//console.log(element, ' dropped on nothing');
			        } else {
			        	//output(element+' dropped on '+droppable+' - event = '+event);
			        	//output('href = '+element.href);
			        	add_to_list(element);
			        	element.destroy();
				        droppable.setStyle('background-color', '#E5E5E5');
			        	//console.log(element, 'dropped on', droppable, 'event', event);
			        }
			    },
			    onEnter: function(element, droppable){
			        //output(element+' entered '+droppable);
			        droppable.setStyle('background-color', '#d8e200');
			    },
			    onLeave: function(element, droppable){
			        //output(element+' LEFT '+droppable);
			        droppable.setStyle('background-color', '#E5E5E5');
			    }
			 
			});
			drag.start(e); // start the event manual
			//*/
		});
	 
	});
	function add_to_list(element) {
		// ALLEEN DOEN ALS HIJ NIET AAN HET LOADEN IS
		if($('loading_added_to_mh')==null) {
			var product_id = element.rev;
			product_id = product_id.replace('product_id_', '');
			add_to_mh_items(product_id);
		}
	}
}
