/* Image rotation function */
Function rotate (o, p ){
Var img = document. getElementById (o );
If (! Img |! P) return false;
Var n = img. getAttribute ('step ');
If (n = null) n = 0;
If (p = 'right '){
(N = 3 )? N = 0: n ++;
}
Else if (p = "left "){
(N = 0 )? N = 3: n --;
}
Img. setAttribute ('step', n );
If (document. all ){
Img. style. filter = "progid: DXImageTransform. Microsoft. BasicImage (rotation =" + n + ")";
Switch (n ){
Case 0:
Img. parentNode. style. height = img. height;
Break;
Case 1:
Img. parentNode. style. height = img. width;
Break;
Case 2:
Img. parentNode. style. height = img. height;
Break;
Case 3:
Img. parentNode. style. height = img. width;
Break;
}
}
Else {
Var c = document. getElementById ('canvas _ '+ o );
If (c = null ){
Img. style. visibility = 'hiden ';
Img. style. position = 'absolute ';
C = document. createElement ('canvas ');
C. setAttribute ('id', 'canvas _ '+ o );
Img. parentNode. appendChild (c );
}
Var canvasContext = c. getContext ('2d ');
CanvasContext. save ();
Switch (n ){
Default:
Case 0:
C. setAttribute ('width', img. width );
C. setAttribute ('height', img. height );
CanvasContext. rotate (0 * Math. PI/180 );
CanvasContext. drawImage (img, 0, 0 );
Break;
Case 1:
C. setAttribute ('width', img. height );
C. setAttribute ('height', img. width );
CanvasContext. rotate (90 * Math. PI/180 );
CanvasContext. drawImage (img, 0,-img. height );
Break;
Case 2:
C. setAttribute ('width', img. width );
C. setAttribute ('height', img. height );
CanvasContext. rotate (180 * Math. PI/180 );
CanvasContext. drawImage (img,-img. width,-img. height );
Break;
Case 3:
C. setAttribute ('width', img. height );
C. setAttribute ('height', img. width );
CanvasContext. rotate (270 * Math. PI/180 );
CanvasContext. drawImage (img,-img. width, 0 );
Break;
}
CanvasContext. restore ();
}
}