There are (at least) two ways to access a document data source from within a custom control:
1) use the 'currentDocument' object. This should be all you need if there is only one document datasource in use on your xpage. If there is more than one document data source on your page, it will find the 'closest' document, by walking back up the control tree. If you need to control which doc datasource you really need to work with, use method 2.
2) You can pass the document datasource as a property of the custom control. You create a property with the type com.ibm.xsp.model.ModelDataSource (type it in, it doesn't show up as a choice), then pass your datasource as the value of that property where you instantiate your custom control. Then you access that datasource through the compositeData object in your custom control. In any javascript computation, I find is useful to define a local variable and cast it as a NotesXspDocument to get the advantages of type-ahead in the editor:
var doc:NotesXspDocument = compositeData.datasourceProperty;
Rich