var CopyCodeController;

(function() {
    var publicMembers = {
        clients: {},
        createZeroClipboard: function(id, noSwf){
            var version = deconcept.SWFObjectUtil.getPlayerVersion();
            if(noSwf){
                jq("#"+id).click(function(){
                   jq(this).select();
                });   
            } else {
                if (version.major >= 9) {
                    var elemId = 'clip' + id;
                    var cclient;
                    if (this.clients[id]){
                       cclient = this.clients[id];
                    } else {
                       cclient = new ZeroClipboard.Client();
                       this.clients[id] = cclient;
                    }
                    var cpText = jq("#"+id).val();
                    cclient.glue("copycode_"+id, "zeroclipboard_"+id, cpText);
                    cclient.addEventListener('onComplete', function(c, t){
                        jq("#"+id).val('Copied').css('backgroundColor','#FFFF66').fadeTo('normal', 0.4, function() {
                            jq(this).fadeTo('normal', 1, function() {
                                jq(this).css('backgroundColor','#FFFFFF').val(cpText);
                            });
                        });
                    });
                } else {
                    jq("#"+id).click(function(){
                       jq(this).select();
                    });   
                }
            }
        },
        hasClient: function(id){
            if(this.clients[id]){
                return true;
            }
            return false;
        }
    };
    var staticMembers = {};
    Controller.create("CopyCodeController",publicMembers,staticMembers);
})();

