function convDegreeToRadian(degrees) {
	return (degrees * Math.PI) / 180 ;
}

function rotateCanvas(currCanvas, currCanvasID, degrees) {
		// Figure out the stuff for plotting the temporary canvas
	var sH = $("#"+currCanvasID).get(0).height ;
	var sW = $("#"+currCanvasID).get(0).width ;
	var diagonal = Math.sqrt((sW * sW) + (sH * sH)) ;
	var halfDiag = diagonal / 2 ;
	
		// Append the temp canvas
	$("#container").append('<canvas id="tempCanvas" width="'+diagonal+'" height="'+diagonal+'"></canvas>') ;
	var tempCanvas = $("#tempCanvas").get(0).getContext("2d") ;
	
		// Move to the centre of the canvas
	tempCanvas.translate(halfDiag, halfDiag) ;
		
		// Rotate the canvas
	var rotation = convDegreeToRadian(degrees) ;
	tempCanvas.rotate(rotation) ;
		
		// Draw the source image onto the temp canvas
	tempCanvas.drawImage($("#"+currCanvasID).get(0), 0 - (sW / 2), 0 - (sH / 2)) ;
	
		// Get the new dimensions of the rotated image for the bounding box
	var dDegrees = Math.abs(degrees) ;
	if (dDegrees >= 90) {
		dDegrees = 180 - dDegrees ;
	}
	
	var dRotation = convDegreeToRadian(dDegrees)
	
	var dW = (sW * Math.cos(dRotation)) + (sH * Math.sin(dRotation)) ;
	var dH = (sW * Math.sin(dRotation)) + (sH * Math.cos(dRotation)) ;

		// Clear out the old canvas, resize it and put our new stuff onto it
	currCanvas.clearRect(0, 0, $("#"+currCanvasID).get(0).width, $("#"+currCanvasID).get(0).height) ;
	$("#"+currCanvasID).get(0).width = dW ;
	$("#"+currCanvasID).get(0).height = dH ;
	currCanvas.drawImage($("#tempCanvas").get(0), ((diagonal - dW) / 2), ((diagonal - dH) / 2), dW, dH, 0, 0, dW, dH) ;
	
		// When finished, remove the canvas
	$("#tempCanvas").remove() ;
}

function addPaperclip() {
	canvas.drawImage($("#paperclip").get(0), 160, 3) ;
}

function addDropshadow() {
	$("#container").append('<canvas id="tempCanvas" width="'+$("#drawingCanvas").width()+'" height="'+$("#drawingCanvas").height()+'"></canvas>') ;
	var tempCanvas = $("#tempCanvas").get(0).getContext("2d") ;	
	tempCanvas.drawImage($("#drawingCanvas").get(0), 0, 0) ;
	
	$("#drawingCanvas").get(0).height = 230 ;
	canvas.drawImage($("#tempCanvas").get(0), 0, 0) ;
	
	$("#tempCanvas").remove() ;

	canvas.drawImage($("#dropshadow").get(0), 4, 64) ;
}