//
// Function to Rotate a <DIV> element
//
// - Position of DIV must be absolute or relative
// - Uses center point of DIV as origin for tilt
//
// Expected browser compatibility: most browsers (including ie6, ie7 & ie8)
//
function rotateDiv( divElement, topPos, leftPos, height, width, angleDegrees )
{
var radAngle = Math.PI * angleDegrees / 180;
var spinAngle = radAngle;
if ( window.navigator.userAgent.indexOf ( 'MSIE ' ) <= 0 || typeof document.documentElement.style.opacity!='undefined' )
radAngle = -radAngle;
var sinAngle = parseFloat(parseFloat(Math.sin(radAngle)).toFixed(8));
var cosAngle = parseFloat(parseFloat(Math.cos(radAngle)).toFixed(8));
var m11 = cosAngle;
var m12 = -sinAngle;
var m21 = sinAngle;
var m22 = cosAngle;
if ( window.navigator.userAgent.indexOf ( 'MSIE ' ) <= 0 || typeof document.documentElement.style.opacity!='undefined' )
{
divElement.style.WebkitTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';
divElement.style.MozTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + 'px,' + 0 + 'px)';
divElement.style.msTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';
divElement.style.OTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';
divElement.style.transform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';
divElement.style.top = topPos + 'px';
divElement.style.left = leftPos + 'px';
return;
}
var sinSpinAngle = -parseFloat(parseFloat(Math.sin(-spinAngle)).toFixed(8));
var cosSpinAngle = parseFloat(parseFloat(Math.cos(-spinAngle)).toFixed(8));
var sinAnglePerp = parseFloat(parseFloat(Math.sin(radAngle-Math.PI)).toFixed(8));
var cosAnglePerp = parseFloat(parseFloat(Math.cos(radAngle-Math.PI)).toFixed(8));
var halfHeight = height/2;
var halfWidth = width/2;
var radius = Math.sqrt(halfHeight*halfHeight + halfWidth*halfWidth);
var ulx = leftPos + halfWidth - radius*cosSpinAngle + sinAnglePerp*halfHeight;
var uly = topPos + halfHeight - radius*sinSpinAngle + cosAnglePerp*halfHeight;
var urx = radius*cosSpinAngle + leftPos + halfWidth + sinAnglePerp*halfHeight;
var ury = radius*sinSpinAngle + topPos + halfHeight + cosAnglePerp*halfHeight;
var lrx = radius*cosSpinAngle + leftPos + halfWidth - sinAnglePerp*halfHeight;
var lry = radius*sinSpinAngle + topPos + halfHeight - cosAnglePerp*halfHeight;
var llx = leftPos + halfWidth - radius*cosSpinAngle - sinAnglePerp*halfHeight;
var lly = topPos + halfHeight - radius*sinSpinAngle - cosAnglePerp*halfHeight;
divElement.style.filter = "filter: progid:DXImageTransform.Microsoft.Matrix( M11="+m11+", M12="+m12+", M21="+m21+", M22="+m22+", sizingMethod='auto expand' );";
var spinTop = Math.min( uly, ury, lry, lly );
var spinRight = Math.max( ulx, urx, lrx, llx );
var spinBottom = Math.max( uly, ury, lry, lly );
var spinLeft = Math.min( ulx, urx, lrx, llx );
divElement.style.top = spinTop + 'px';
divElement.style.right = spinRight + 'px';
divElement.style.bottom = spinBottom + 'px';
divElement.style.left = spinLeft + 'px';
}