YAHOO.namespace("gaia.app.Gim");
(function() {

    var Cookie = YAHOO.util.Cookie;


    YAHOO.gaia.app.Gim.GlobalLauncher = function() {

        this._cookies = null;
        this._gUserId = null;

    };


    YAHOO.gaia.app.Gim.GlobalLauncher.prototype.init = function(settings) {
        

        this._gUserId = settings.gUserId;
        this._gUrl = "/gim";
        this._cookies = {
            blstartconvo : (settings.blfocus || 'blstartconvo'),
            blopen : (settings.blopen || 'blopen')
        };


        this._cStartConvoId =  this._gUserId + '_' + this._cookies.blstartconvo;
        this._cOpenId = this._gUserId + '_' + this._cookies.blopen;
        
        
        
    };

    YAHOO.gaia.app.Gim.GlobalLauncher.prototype.launchUser = function(userId,useAimId,focus) {
        var blCookie = Cookie.get(this._cOpenId,{path:"/",domain:document.domain});

        if(blCookie != 'true') {
            var w = window.open(this._gUrl, "buddylist", "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=600,height=480,resizable");
            w.focus();
        }
        else {
            focus="true";
        }
  
        var now = new Date();
        if(typeof(useAimId) == 'undefined')
            useAimId = false;
        if(typeof(focus) == 'undefined')
            focus = true;

        var items = {gUserId:userId,timestamp:now,useAimId:useAimId,focus:focus};
        now.setSeconds(now.getSeconds() + 5);
        Cookie.setSubs(this._cStartConvoId,items,{path:"/",domain:document.domain});
        
    };

})();
