/**
 * @section		: Global JavaScript functions
 * @project		: Bespaarinstallateur v2
 * @author		: Joris van Summeren <joris@e-sites.nl>
 * @since		: 06-10-2011
 */

/**
 * Cache both window and document object for use later on
 */
var win = window,
	doc = win.document;

/**
 * Global wrapper around `console.log` (when available)
 *
 * @method log
 * @param {Any} Values to log
 */
win.log = function () {
	if ( this.console ) {
		console.log.apply(console, arguments);
	}
};

/**
 * Handles external links based on rel="external"
 *
 * @author Boye Oomens <boye@e-sites.nl>
 * @param none
 * @return {Boolean}
 */
function setExtLinks() {
	this.target = '_blank';
}

/**
 * Helper function as alias for getElementById, mainly used to see if a certain DOM element exists
 *
 * @author Boye Oomens <boye@e-sites.nl>
 * @param {String} id - id selector without the hash character
 * @return {Boolean}
 */
function isset(id) {
	return !!doc.getElementById(id);
}

/**
 * Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
 * but retaining the use of a document fragment to minimise the number of times objects are
 * written to the DOM. Also, better handling of scripts without supplied ids.
 *
 * @author Joris van Summeren <joris@e-sites.nl>
 */
(function (doc, script) {
    var js,
        fjs = doc.getElementsByTagName(script)[0],
        frag = doc.createDocumentFragment(),
        add = function(url, id) {
            if (doc.getElementById(id)) {
            	return;
            }

            js = doc.createElement(script);
            js.src = url;
            js.id = id || null;
            frag.appendChild(js);
        };

	add('//platform.twitter.com/widgets.js');
	fjs.parentNode.insertBefore(frag, fjs);
}(document, 'script'));
