﻿//ba Object
function beforeAfter() {
    this.w0 = 453;
    this.w1 = 240;
    this.h0 = 377;
    this.h1 = 200;
    this.sw = 15;
    this.sh = 12.5;
    this.w = this.w0;
    this.h = this.h0;
    this.shrinkrate = 100;
    this.lowerrate = 100;
    this.tf = 75;
    this.st = 10;
    this.top = 0;
    
    this.afterdiv = null;
    this.beforediv = null;
    this.aftertitle = null;
    this.beforetitle = null;
    this.afterimg = null;
    this.beforeimg = null;
    this.timeout = 0;    
    
    
}
var _ba = new beforeAfter();

function reset_animation() {
    clearTimeout(_ba.timeout);
    _ba = new beforeAfter();
    _ba.afterdiv = document.getElementById('ba_after');
    _ba.beforediv = document.getElementById('ba_before');
    _ba.afterimg = _ba.afterdiv.getElementsByTagName('img')[0];
    _ba.beforeimg = _ba.beforediv.getElementsByTagName('img')[0];
    _ba.aftertitle = _ba.afterdiv.getElementsByTagName('div')[0];
    _ba.beforetitle = _ba.beforediv.getElementsByTagName('div')[0];
    _ba.afterimg.style.width = _ba.w + "px";
    _ba.afterimg.style.height = _ba.h + "px";
    _ba.beforeimg.style.width = _ba.w + "px";
    _ba.beforeimg.style.height = _ba.h + "px";
    _ba.afterdiv.style.top = _ba.top + "px";
    _ba.beforediv.style.top = _ba.top + "px";
}

//ba Initialize
function ba_animate() {
    reset_animation();
    fadeIn("_ba.afterimg", 0, 100, 2, 100, "_ba.timeout", "ba_move_img()");
}

//ba Move Pictures to Final Location
function ba_move_img() {
    if ((_ba.w > _ba.w1) && (_ba.h > _ba.h1)) {
        _ba.w -= _ba.sw;
        _ba.h -= _ba.sh;
        _ba.afterimg.style.width = _ba.w + "px";
        _ba.afterimg.style.height = _ba.h + "px";
        _ba.beforeimg.style.width = _ba.w + "px";
        _ba.beforeimg.style.height = _ba.h + "px";
        _ba.timeout = setTimeout("ba_move_img()", _ba.shrinkrate);
    }
    else {
        clearTimeout(_ba.timeout);
        _ba.w = _ba.w0;
        _ba.h = _ba.h0;
        _ba.top = 0;
        _ba.timeout = setTimeout("ba_movedown_img()", _ba.lowerrate);
    }
}

function ba_movedown_img() {
    if (_ba.top < _ba.tf) {
        _ba.top += _ba.st;
        _ba.afterdiv.style.top = _ba.top + "px";
        _ba.beforediv.style.top = _ba.top + "px";
        _ba.timeout = setTimeout("ba_movedown_img()", _ba.lowerrate);
    }
    else {
        clearTimeout(_ba.timeout);
        _ba.top = _ba.tf;
        _ba.afterdiv.style.top = _ba.top + "px";
        _ba.beforediv.style.top = _ba.top + "px";
        _ba.aftertitle.style.display = "block";
        _ba.beforetitle.style.display = "block";
    }
}


//function ba_animate() {

//    var ia = document.getElementById('ba_after');
//    var ib = document.getElementById('ba_before');
//    var iaimg = ia.getElementsByTagName("img")[0];
//    var ibimg = ib.getElementsByTagName("img")[0];
//    
//    ba_fi_obj = ia;
//    ba_fade_in();
//    var w = ibimg.style.width.replace("px", "") * 1;
//    var h = ibimg.style.height.replace("px", "") * 1;

//    if (w > w1) {
//        ibimg.style.width = (w - sw) + "px";
//        ibimg.style.height = (h - sh) + "px";
//        ba_an_to = setTimeout("ba_animate()", 100);
//    }
//    else {
//        clearTimeout(ba_an_to);
//        iaimg.style.width = w1 + "px";
//        iaimg.style.height = h1 + "px";
//    }
//}




