/**
 * The RDFa Javascript template.
 *
 * Ben Adida - ben@mit.edu
 * 2006-03-21
 * 2006-05-22 moved to W3C
 *
 * licensed under GPL v2
 */


// EXPECTING __RDFA_BASE
if (typeof(__RDFA_BASE) == 'undefined')
   __RDFA_BASE = 'http://www.w3.org/2001/sw/BestPractices/HTML/rdfa-bookmarklet/';

var __RDFA_VERSION_SUBDIR = '2006-05-22/';

// configuration information
var RDFA = new Object();
RDFA.url = __RDFA_BASE + __RDFA_VERSION_SUBDIR + 'rdfa.js';

var N3_TEXT = "";

N3_ADD = function(el,triple) {
    N3_TEXT += triple.pretty() + ';\n';
}

// a function that is called on an element when a triple pertains to it
// with the element being the literal object
RDFA.CALLBACK_NEW_TRIPLE_WITH_LITERAL_OBJECT = function(el, triple) {
	N3_ADD(el,triple);
}

// a function that is called on an element when a triple pertains to it
// with the element being the clickable link for a URI object
RDFA.CALLBACK_NEW_TRIPLE_WITH_URI_OBJECT = function(el, triple) {
	N3_ADD(el,triple);
}

// a function that is called on an element when a triple pertains to it
// with the element being the subject of the assertions
RDFA.CALLBACK_NEW_TRIPLE_WITH_SUBJECT = function(el, triple) {
	N3_ADD(el,triple);
}

RDFA.CALLBACK_DONE_PARSING = function() {
    var n3_b64 = btoa(N3_TEXT);
    var n3_uri = 'data:text/rdf+n3;base64,' + n3_b64;
    
    document.location= n3_uri;
}

//
// Everything below is used only for loading the RDF/A javascript.
// You probably don't need to look at it.
//

// callback when the RDF/A parsing is done.
RDFA.CALLBACK_DONE_LOADING = function() {
    RDFA.parse();
}

RDFA.load = function()
{
    var s = document.createElement("script");
    s.type = 'text/javascript';
    s.src = RDFA.url;

    // add it to the document tree, load it up!
    document.getElementsByTagName('head')[0].appendChild(s);
}

RDFA.load();