/*
						This library is copyright protected, Ninebits © 2008

			--------------------------------------------------------------------------------------------------------------------
			None of the scripts, functions or any other elements on this site and this library
			may be copied, sold, decompiled or used in any other way than as a library
			to the intended Ninebits product.

			Unauthorised backup is prohibited, only one instance may reside at the server
			where the project is hosted. On request a new instance will be installed
			by Ninebits.
			--------------------------------------------------------------------------------------------------------------------
			Please visit us at http://www.ninebits.nl
			--------------------------------------------------------------------------------------------------------------------
			This library is W3C compliant, FF, IE, NS, OP. 01-12-2005 22:33 CET

			FF = gecko / Konqueror = khtml / Mozilla = gecko / Internet explorer = msie
			NS = gecko/netscape / Opera = opera

*/
	
	document.plugin = {};
	document.plugin.sociaallinken = {};

	/* Links opbouwen */
	function _nbsociaallink(lReeks, iAfmeting){
		var l = document.createElement('a');
		l.href = 'javascript:document.plugin.sociaallinken.go(\'' + lReeks[1] + '\');void(0);';
		l.title = lReeks[0];
		l.appendChild(_nbmaakicoon(lReeks[0], lReeks[2], iAfmeting));
		return l;
	}

	/* Alle links in een tabel zetten */
	function _nblinksopbouwen(lVerzameling, aPerregel, iAfmeting){
		var t = document.createElement('table');
		t.border = '0';
		var tb = document.createElement('tbody');
		var tr = document.createElement('tr');

		var j = 0;
		for (var i=0; i < lVerzameling.length; i++){
			var td = document.createElement('td');
			td.style.padding = '2px';
			td.appendChild(_nbsociaallink(lVerzameling[i], iAfmeting));
			tr.appendChild(td);
			j++;
			if (aPerregel == j){
				tb.appendChild(tr);
				var tr = document.createElement('tr');
				j = 0;
			}
		}
		for (var c=0; c < (aPerregel - j); c++){
			var td = document.createElement('td');
			tr.appendChild(td);
		}
		t.height = (parseInt(iAfmeting) * c);
		tb.appendChild(tr);

		t.appendChild(tb);
		return t;
	}

	/* Icoontje erbij zetten */
	function _nbmaakicoon(iTitel, iBron, iAfmeting){
		var maat = 16;
		if (typeof(iAfmeting) != 'undefined'){
			maat = parseInt(iAfmeting);
		}
		var icoon = document.createElement('img');
		icoon.src = 'beelden/' + iBron;
		icoon.alt = iTitel;
		icoon.width = maat;
		icoon.height = maat;
		icoon.style.width = maat + 'px';
		icoon.style.height = maat + 'px';
		icoon.border = 0;
		return icoon;
	}

	document.plugin.sociaallinken.go = function(fUrl){
		var titel = document.title.replace(/\s\s/g, '%20').replace(/\s/g, '%20').replace(/&nbsp;/, '%20');
		fUrl = fUrl.replace(/&url;/, document.location.href).replace(/&titel;/, titel);
		if (document.plugin.sociaallinken.target == 'blank'){
			window.open(fUrl);
		}
		else if (document.plugin.sociaallinken.target == 'self'){
			document.location.href = fUrl;
		}
		else{
			alert('De sociale links moeten een geldig doel krijgen (target).');
		}
	}

	// Initieren sociaallinken plugin
	// Arg[0] = div id waar de links naar toe moeten
	// Arg[1] = optioneel, aantal links per regel in de tabel
	// Arg[2] = optioneel, grote icoontjes
	// Arg[3] = optioneel, self/blank target
	document.plugin.sociaallinken.init = function(){

		if (typeof(arguments[0]) != 'undefined'){
			if (!document.getElementById(arguments[0])){
				alert('De sociale links moeten worden geplaatst in een bestaand element.');
				return false;
			}
			document.getElementById(arguments[0]).style.backgroundColor = '#fff';

			var links = new Array();
			links[0] = new Array('Internet Explorer favoriet', 'javascript:window.external.AddFavorite(\'&url;\',\'&titel;\')', 'ie.gif');
			links[1] = new Array('Firefox favoriet', 'javascript:addBookmark(\'&titel;\',\'&url;\')', 'firefox.gif');
			links[2] = new Array('Del icio us', 'http://del.icio.us/post?url=&url;&title=&titel;', 'delicious.gif');
			links[3] = new Array('Google', 'http://www.google.com/bookmarks/mark?op=edit&bkmk=&url;&title=&titel;', 'google.gif');
			links[4] = new Array('Facebook', 'http://www.facebook.com/sharer.php?u=&url;', 'facebook.gif');
			links[5] = new Array('Reddit', 'http://reddit.com/submit?url=&url;&title=&titel;', 'reddit.gif');
			links[6] = new Array('Stumble upon', 'http://www.stumbleupon.com/submit?url=&url;&title=&titel;', 'stumbleupon.gif');
			links[7] = new Array('Digg', 'http://digg.com/submit?phase=2&amp;url=&url;&title=&titel;', 'digg.gif');
			links[8] = new Array('Yahoo', 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=&url;&title=&titel;', 'yahoo.gif');
			links[9] = new Array('Microsoft Live', 'https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=&url;&title=&titel;', 'live.gif');

			var aantal = 6;
			if (typeof(arguments[1]) != 'undefined'){
				aantal = parseInt(arguments[1]);
			}
			var maat = 16;
			if (typeof(arguments[2]) != 'undefined'){
				maat = parseInt(arguments[2]);
			}
			document.plugin.sociaallinken.target = 'blank';
			if (typeof(arguments[3]) != 'undefined'){
				document.plugin.sociaallinken.target = arguments[3];
			}

			// Object beschikbaar maken voor AJAX etc.
			document.plugin.sociaallinken.object = _nblinksopbouwen(links, aantal, maat);

			document.getElementById(arguments[0]).appendChild(document.plugin.sociaallinken.object);
		}
		else{
			alert('De socialelinks plugin wordt aangeroepen zonder geldige argumenten.');
		}
		return true;
	}