(function(window) {
    
var r;

function RotatePlane(fixedX, fixedY, splitX, splitY, width, height, rows, cols) {
    this.initialize(fixedX, fixedY, splitX, splitY, width, height, rows, cols);
}

r = RotatePlane.prototype = new Bitmap();
r.Bitmap_initialize = r.initialize;

r.initialize = function(row, col) {
    this.Bitmap_initialize();
    this.ROW = row;
    this.COL = col;
    this.FIXED_X = Math.floor(Slideshow.BLOCK_WIDTH * this.COL + Slideshow.SPACER_X / 2);
    this.FIXED_Y = Math.floor(Slideshow.BLOCK_HEIGHT * this.ROW + Slideshow.SPACER_Y / 2);
    this.SPLIT_X = Math.floor((Slideshow.BLOCK_WIDTH * this.COL) + ((Slideshow.SPACER_X / Slideshow.NUM_COLS) * this.COL));
    this.SPLIT_Y = Math.floor((Slideshow.BLOCK_HEIGHT * this.ROW) + ((Slideshow.SPACER_Y / Slideshow.NUM_ROWS) * this.ROW));
    this.HIDE_X = this.SPLIT_X + (Slideshow.BLOCK_WIDTH / 2);
    this.x = this.HIDE_X;
    this.y = this.SPLIT_Y;
    this.scaleX = 0;
    this.skewX = .25;
}

r.draw = function(ctx, ignoreCache) {
    ctx.drawImage(this.image, this.COL * Slideshow.BLOCK_WIDTH, this.ROW * Slideshow.BLOCK_HEIGHT, Slideshow.BLOCK_WIDTH, Slideshow.BLOCK_HEIGHT, 0, 0, Slideshow.BLOCK_WIDTH, Slideshow.BLOCK_HEIGHT);
    return true;
}

r.slide = function(image, m, fast) {
    
    var multiplier, random, time;
    
    multiplier = (m == undefined) ? 10 : m;
    random = Math.random() * multiplier;
    time = multiplier - random;

    Tween.get(this)
         .to({ scaleX: 1, skewX: 0, x: this.SPLIT_X, y: this.SPLIT_Y}, multiplier * 75)
         .to({ scaleX: 0, skewX: .25, x: this.HIDE_X, y: this.SPLIT_Y }, multiplier * 25 + random * 50)
         .call(this.setImage, [image])
         .to({ scaleX: 1, skewX: 0, x: this.SPLIT_X, y: this.SPLIT_Y }, multiplier * 25 + random * 50)
         .wait(time * 100)
         .to({ scaelX: 1, skewX: 0, x: this.FIXED_X, y: this.FIXED_Y }, multiplier * 75);
}

r.setImage = function(image) {
    if(image != undefined) {
        this.image = image;
    }
}

window.RotatePlane = RotatePlane;
}(window));
