/**
 * Script:	Qutter
 * Author:	Quentin T
 * URL:		http://toki-woki.net
*/
var drawing, line, tg, startPoint;
function onMouseDown(e) {
	drawing=false;
	var sel=document.selectedItems;
	if (sel.length!=1) return;
	tg=sel[0];
	startPoint=e.point;
	line=new Path();
	drawing=true;
}
function onMouseDrag(e) {
	if (!drawing) return;
	line.remove();
	line=new Path();
	line.moveTo(startPoint);
	line.lineTo(e.point);
}
function onMouseUp(e) {
	if (!drawing) return;
	endPoint=e.point;
	tg.selected=false;
	line.scale(10, line.bounds.center);
	//
	var circle=new Path.Circle(tg.bounds.center, Math.sqrt(tg.bounds.width*tg.bounds.height));
	circle.style.fillColor=null;
	var g=Pathfinder.divide([line, circle]);
	//
	for (var i=0; g.children.length>0; i++) {
		var art=g.children[0];
		art.strokeColor=null;
		art.fillColor=null;
		art.parent.parent.appendChild(art);
		var gr=new Group([art, tg.clone()]);
		gr.clipped = true;
	}
	tg.remove();
	line.remove();
	document.deselectAll();
}
