/**
 * Matching games: cell
 * Serge Dolgov (C) 2002
 * studio.quazzle.com
 */

function QMatchCell_show(show) {
    document.images["mc_" + this.name].src =
        show && this.face && this.face.complete ? this.face.src : this.back.src;
    this.open = show;
}

function QMatchCell_doClick() {
    with (this) {
        if (face && face.complete && !open) {
            show(true);
            if (this.onClick) onClick(type);
        }
    }
    return false;
}

function QMatchCell_load(src, type) {
    if (this.open) this.show(false);
    this.type = type || 0;
    this.face = new Image(this.width, this.height);
    this.face.src = src;
}

function QMatchCell_swap(cell) {
    if (cell != this) {
        var obj = cell.face || null;
        cell.face = this.face;
        this.face = obj;
        obj = cell.type || 0;
        cell.type = this.type;
        this.type = obj;
    }
}

function QMatchCell(parent, name, width, height, back, src) {
    this.init(parent, name);
    this.width = width;
    this.height = height;
    this.back = back;  // backside image
    this.face = null;
    this.open = false;
    this.load = QMatchCell_load;
    this.show = QMatchCell_show;
    this.swap = QMatchCell_swap;
    this.doClick = QMatchCell_doClick;
    var out = '<a href="#" title="" onClick="return false" onMouseDown="return ' + this.name + '.doClick()" onMouseOver="window.top.status=\'\';return true">';
    out += '<img name="mc_' + this.name + '" src="' + (src || back.src) + '" border="0" width="' + width + '" height="' + height + '" alt=""></a>';
    document.write(out);
}
QMatchCell.prototype = new QControl();