/*
 * on-key event fix for FF on Korean input
 * fires 'keyup' event when contents of input form change
 * requires jQuery 1.2.x
 * example: var watchInput = keyFix(inputId);
 * author: Hoya, hoya@autoreflashstudios.net http://hoya.tistory.com
 */

if (typeof(autoreflash) == "undefined")
    _autoreflash = autoreflash = {};

if (typeof(_autoreflash.fix) == "undefined")
    _autoreflash.fix = {};
else
    alert("keyfix is already set!");

if(typeof(window.autoreflash.instances) == "undefined")
    window.autoreflash.instances = new Array();

_autoreflash.fix = function(targetId)
{
    // this fix is only for mozilla browsers
    if(jQuery.browser.mozilla == false)
        return false;

    var thisClass = this;
    this.keyEventCheck = null;
    this.db = null;
    this.targetId = targetId;
    window.autoreflash.instances[this.targetId] = this;

    var focusFunc = function()
    {
        if(!thisClass.keyEventCheck) thisClass.watchInput();
    };

    var blurFunc = function()
    {
        if(thisClass.keyEventCheck)
        {
            window.clearInterval(thisClass.keyEventCheck);
            thisClass.keyEventCheck = null;
        }
    };

    jQuery("#" + this.targetId).bind("focus", focusFunc);
    jQuery("#" + this.targetId).bind("blur", blurFunc);
};

_autoreflash.fix.prototype.watchInput = function()
{
    if(this.db != jQuery("#" + this.targetId).val())
    {
        // trigger event
        jQuery("#" + this.targetId).trigger('keyup');
    }
    this.db = jQuery("#" + this.targetId).val();

    if(this.keyEventCheck) window.clearInterval(this.keyEventCheck);
    this.keyEventCheck = window.setInterval("window.autoreflash.instances['" + this.targetId + "'].watchInput()", 100);
};

