


function registerDroppableProductComparisonBox(elemID)
{
	Droppables.add(elemID, {accept:'productimage', onDrop:phoneDroppedOnComparisonContainer, onHover:phoneHoveredOnComparisonContainer } );
}

function registerAllDraggableProducts()
{
	allDraggables = new Array(0);
	for (var j = 0; j < phoneList.mobilePhones.length; j++)
	{
		allDraggables[allDraggables.length] = new Draggable('productimage_' + j,{ revert:true, endeffect:endDragEffect , starteffect:startDragEffect, reverteffect:revertDragEffect, onEnd:removeDropToAddMessages });
	}
}

function startDragEffect(draggedElement) 
{
	var phoneIndex = draggedElement.id.split("_")[1];

	draggedElement._opacity = Element.getOpacity(draggedElement);
	Draggable._dragging[draggedElement] = true;
	new Effect.Opacity(draggedElement, {duration:0.2, from:draggedElement._opacity, to:0.7}); 
	
	//Replace dragged image with another image (to emulate the effect of ghosting:true, which is unfortunately buggy in IE)
		$("productimagewrap_" + phoneIndex).setStyle( {backgroundImage: "url(" + draggedElement.src + ")", backgroundRepeat: "no-repeat"} );
}

function endDragEffect(draggedElement)
{
	var phoneIndex = draggedElement.id.split("_")[1];

	$(draggedElement.id).setOpacity(1);
	Draggable._dragging[draggedElement] = false;

	//Remove the image added by startDragEffect (emulates the effect of ghosting:true, which is unfortunately buggy in IE)
		//$("productimagewrap_" + phoneIndex).setStyle( {backgroundImage: "none" } );
}

function revertDragEffect(elementToRevert, topOffset, leftOffset)
{
	new Effect.Move(elementToRevert, { x: -leftOffset, y: -topOffset, duration: 0,
		queue: {scope:'_draggable', position:'end'}
	});
}

function registerAllDroppableContainers()
{
	for (var i = 0; i < comparisonContainers.containers.length; i++)
	{
		registerDroppableProductComparisonBox(comparisonContainers.containers[i].elementID);
	}
}

function destroyAllDraggableProducts()
{
	if (allDraggables != null)
	{
		for (var j = 0; j < allDraggables.length; j++)
		{
			allDraggables[j].destroy();
		}
	}
}

function removeFromComparison(elementID)
{
	var compContainer = comparisonContainers.getContainerByElementID(elementID);
	compContainer.currentProduct = null;
	renderComparisonSelectionElements();

	saveComparisonSelections();
}

function removeDropToAddMessages()
{
	/*
	REMOVED - could not hook up properly on the onmouseout event (scriptacolus only have a onHover event, not the opposite)
	for (var i = 0; i < comparisonContainers.containers.length; i++)
	{
		if (comparisonContainers.containers[i].currentProduct == null)
		{
			document.getElementById(comparisonContainers.containers[i].elementID).innerHTML = "";
		}
	}
	*/
}