LINKEDIN = 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 linkedIn button and attach a callback function
    * @param {Object} container
    * @param {Function} linkedInCallback
    * @method _renderLinkedInButton
    * @return {Function} 
    */
    var _renderLinkedInButton = function(container,  linkedInCallback){
        var po = document.createElement('script'); 
        po.setAttribute('type','IN/share');
        po.setAttribute('data-onsuccess', 'linkedInShareCallback');
        container.appendChild(po); 
    }


    /**
    * Render the linkedIn login button
    * @param {Object} container_
    * @method renderLinkedInButton
    * @return {Function} 
    */
    var _renderLoginLink = function(container){
/*<script type="in/Login">
Hello, <?js= firstName ?> <?js= lastName ?>.
</script>*/
        var scriptEl = document.createElement('script');
        scriptEl.setAttribute('type', 'in/Login');
        container.appendChild(scriptEl);
    }

    /**
    * Gets the stored linkedIn user
    * @method _getLinkedInProfile
    * @return {Function} 
    */
    var _getLinkedInProfile = function(){
        /*
        {"_total":1,"values":[{"_key":"~","firstName":"","headline":"","id":"","lastName":""}]}
        */
        return $('linkedInProfileContainer')?YAHOO.lang.JSON.parse($('linkedInProfileContainer').value):'';
    }

    return{

    /**
    * Render the linkedIn button and attach a callback function
    * @param {Object} container
    * @param {Function} linkedInCallback
    * @method renderLinkedInButton
    * @return {Function} 
    */
        renderLinkedInButton : function(container, linkedInCallback){
	    return function(e){
                _renderLinkedInButton(container,  linkedInCallback);
	    }
	},

    /**
    * Render the linkedIn login button
    * @param {Object} container
    * @method renderLoginlink
    * @return {Function} 
    */
        renderLoginlink : function(container){
            return function(e){
		_renderLoginLink(container)
	    }
	},

    /**
    * Get linkedIn user when linkedIn libraries are loaded
    * @method onLinkedInLoad
    * @return {Function} 
    */
        onLinkedInLoad : function(){
	    return function(e){
                IN.API.Profile("me")
                .result(function(result) { 
		    var linkedInProfileContainer = $input({'id':'linkedInProfileContainer','type':'hidden', 'value': JSON.stringify(result)});
                    document.body.appendChild(linkedInProfileContainer);
                } )
	    }
	},

    /**
    * Gets the stored linkedIn user
    * @method getLinkedInProfile
    * @return {Function} 
    */
        getLinkedInProfile : function(){
	    return function(e){
		return _getLinkedInProfile();
	    }
	}
    };

}();









