GOOGLEPLUS = function(){

    /**
    * Shortcut for document.getElementById()
    * @param {id} id of html element to return
    * @method $
    * @return {Object} Html element with id id
    */
    var $ = function(id){
        return document.getElementById(id);
    }

    /**
    * Render the google plus button and attach a callback function
    * @param {Object} container
    * @param {Function} googlePlusLinkCallback
    * @method _renderGooglePlusButton
    * @return {Function} 
    */
    var _renderGooglePlusButton = function(container,  googlePlusLinkCallback){
	container.innerHTML+='<g:plusone size="small" annotation="none" callback="googlePlusLikeCallback"></g:plusone>';
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
        //YAHOO.util.Event.on('googleplus button', 'click', _getSignedInUser(googlePlusLinkCallback));
    }

    var getSignedInUserSuccess = function(getSignedInUserCallback){
	return function(o){
            var user = YAHOO.lang.JSON.parse(o.responseText);
            getSignedInUserCallback(user);
	}
    }

    var getSignedInUserFailure = function(){
	return function(o){
	}
    }
    
    var _getSignedInUser = function(getSignedInUserCallback){
	return function(e){
	    if(e){
		YAHOO.util.Event.stopEvent(e);
	    }
   	    var callback =
            {
  	        success: getSignedInUserSuccess(getSignedInUserCallback),
	        failure: getSignedInUserFailure()
            };  
    	    var cObj = YAHOO.util.Connect.asyncRequest('POST', '?run=getguser', callback);
	}
    }

    var handleLoginLinkClick = function(authUrl){
        return function(e){
            window.open(authUrl, "gWindow","width=800,height=400,left=150,top=100,scrollbar=no,resize=no");		    
	}
    }

    var renderLoginLinkSuccess = function(container){
	return function(o){
            var authUrl = o.responseText;
            if(authUrl.substr(0,4)=='http'){
               var link = $a({'href':'#', 'id':'googleConnectLink'}, 'Connect to Google Plus');
               container.appendChild(link);
               YAHOO.util.Event.on(link, 'click', handleLoginLinkClick(authUrl));
            }
	}
    }

    var renderLoginLinkFailure = function(){
	return function(o){
	}
    }

    var _renderLoginLink = function(container){
   	var callback =
        {
  	    success: renderLoginLinkSuccess(container),
	    failure: renderLoginLinkFailure()
        };  
    	var cObj = YAHOO.util.Connect.asyncRequest('POST', '?run=g_authenticate', callback);
    }

    return{

    /**
    * Render the google plus button and attach a callback function
    * @param {Object} container
    * @param {Function} googlePlusLinkCallback
    * @method renderGooglePlusButton
    * @return {Function} 
    */
        renderGooglePlusButton : function(container, googlePlusLinkCallback){
	    return function(e){
                _renderGooglePlusButton(container,  googlePlusLinkCallback);
	    }
	},

        renderLoginlink : function(container){
            return function(e){
		_renderLoginLink(container)
	    }
	},
        
	getSignedInUser : function(getSignedInUserCallback){
            return function(e){
        	_getSignedInUser(getSignedInUserCallback)(e);
	    }
        }

    };

}();









