if (typeof(vnp_badge)=='undefined') {

vnp_badge = function() {
return {


badges: new Array(),
badgeid: 0,
DEBUG: false,
//S.Z: log msg.
log: function(msg) {
  if (this.DEBUG) {
	if (window.console && console.log)
		console.log(msg);
	else
		alert(msg);
  }
},

//S.Z: clear.
init: function() {
 if ( this.DEBUG ) {
	this.log('in init');
 }
 this.insertBadgeCSS(); // insertBadgeCSS will check and avoid duplicate inclusion of the css for each badge.
 if (arguments.callee.done) return;
 arguments.callee.done = true;
 if ( this.DEBUG ) {
	this.log('  adding LoadEvent Handler');
 }
 this.addLoadEvent(this.onload); 
},
insertBadgeCSS: function(badgeid) {
/*	var bcss =  document.getElementById('delicious-blogbadge-css');
	if (!bcss) {*/
	if ( badgeid == undefined )
		for ( badgeid in this.badges ) {
			this.insertBadgeCSS(badgeid);
	}
	else if ( ! this.badges[badgeid].cssincluded ) {
			bcss = this.el('link', {
				'id': 'vnp_badge_css_' + badgeid,
				'type': 'text/css',
				'rel': 'stylesheet',
				'href': this.badges[badgeid].csshref
			}, []);
			document.getElementsByTagName('head')[0].appendChild(bcss);
			this.badges[badgeid].cssincluded = true;
	}
/*	}
	bcss = null;*/
},

writeBadge: function(badgeid) {
 document.writeln('<div class="' + this.badges[badgeid].divclass + '" id="' + this.badges[badgeid].divid +'"></div>');
 if ( this.DEBUG ) {
	this.log('writing badge: ' + badgeid );
	this.log('  divid: ' + this.badges[badgeid].divid );
 }
},

bind: function(func) {
 var obj = this;
 return function() { return func.apply(obj, arguments) };
},

forEach: function(list, fn) {
 fn = this.bind(fn);
 for (var i=0; i<list.length; i++) fn(list[i]);
 },

filter: function(fn, list) {
 var rv = [];
 fn = this.bind(fn);
 for (var i=0; i<list.length; i++)
 if (fn(list[i])) rv[rv.length] = list[i];
 return rv;
 },

map: function(fn, list) {
 var rv = [];
 fn = this.bind(fn);
 for (var i=0; i<list.length; i++) rv[rv.length] = fn(list[i]);
 return rv;
 },


// See: http://dean.edwards.name/weblog/2006/06/again/
addLoadEvent: function(func) {
 var init = this.bind(func);

 // for Mozilla and Opera browsers
 if (document.addEventListener) {
 	document.addEventListener("DOMContentLoaded", init, false);
 }

 // for Internet Explorer (using conditional comments)
 /*@cc_on @*/
 /*@if (@_win32)
 document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
 var script = document.getElementById("__ie_onload");
 script.onreadystatechange = function() {
 if (this.readyState == "complete") {
 init(); // call the onload handler
 }
 };
 /*@end @*/

 // for WebKit browsers
 if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(
		function() {
			if (/loaded|complete/.test(document.readyState)) {
				clearInterval(_timer);
				init(); // call the onload handler
			}
		},
		10);
 }

 // for anyone else not covered above.
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
 	window.onload = init;
 } 
 else {
	window.onload = function() {
		if (oldonload) {
			oldonload();
		}
		init();
 	}
 }
},

replaceChildNodes: function(parent, nodes) {
 if ( this.DEBUG ){
	this.log('replaceChildNodes: ' + parent + ', ' + nodes);
// 	this.log(this.arguments);
 }
 while (parent.firstChild)
	parent.removeChild(parent.firstChild);
 return this.appendChildNodes(parent, nodes);
},

appendChildNodes: function(parent, nodes) {
 if (!nodes || !nodes.length) return;
 for (var i=0; i<nodes.length; i++) {
	var node = nodes[i];
	if (!node) continue;
	if (node.nodeType)
		parent.appendChild(node);
	else if ( (typeof(node) == 'object') && node.length)
		this.appendChildNodes(parent, node);
	else 
		parent.appendChild(document.createTextNode(''+node));
 }
},


// S.Z: Description: create a new element and return it.
/**
 * Params: 
 * 		name 	- string, tag name of the new element
 * 		attrs	- Array of attributes to set ( attribute_name => attribute_value ) 
 *		nodes	- [ObjectCollection] of nodes to append to the new tag.
*/
 el: function(name, attrs, nodes) {
	var elem = document.createElement(name);
	if (attrs) for (k in attrs) {
		var v = attrs[k];
			if (k.substring(0, 2) == "on") {
				if (typeof(v) == "string") {
					v = new Function(v);
				}
			elem[k] = v;
			}
			else if ( k == "style" ){
				elem.setAttribute(k,v);
				/*@cc_on @*/
				/*@if (@_win32)
					elem.style.setAttribute('cssText',v);
				/*@end @*/
			}
			else {
				elem.setAttribute(k, v);
			}
			switch(k) {
			// MSIE seems to want this.
				case 'class': elem.className = v; break;
			}
	}
	if (nodes) this.appendChildNodes(elem, nodes);
	return elem;
 },

EOF:null,
onload: function() {
if ( arguments.callee.done )
	return;
arguments.callee.done = true;
	if ( this.DEBUG ) { 
		this.log( "onload :");
		this.log( "  badges length: " + this.badges.length ) ;
	}
	for ( badgeid in this.badges ) {
		if ( isNaN(parseInt(badgeid)) )
			continue;
		var div = document.getElementById(this.badges[badgeid].divid );
		if ( this.DEBUG ){
			this.log( 'rendering: badge ' + badgeid);
			this.log(div);
		}
		var badge_el = this.badges[badgeid].render ();
		if ( this.DEBUG ) {
			this.log('  done rendering');
			this.log(badge_el);
		}
		this.replaceChildNodes( div, badge_el);
	}
},
 addBadge: function ( func, csshref, divclass, divid ) {
	var id =  ( divid ? divid : 'vnp_badge_' + this.badgeid );
	if ( this.DEBUG ) {
		this.log('adding Badge: ' + this.badgeid );
		this.log(' CALLER: ' + arguments.caller );
		this.log('  divid    : ' + id ) ;
		this.log('  csshref  : ' + csshref);
		this.log('  divclass : ' + divclass);
	}
	var badge = this.constructBadge(func,csshref,divclass,id);
	this.badges[this.badgeid] = badge;
	this.badgeid ++;
	return ( badge.id );
 },

 constructBadge: function ( func, csshref, divclass, divid ){
	return {
		id: this.badgeid,
		render: this.bind(func),

		csshref: csshref,
		divclass: divclass,
		divid: divid,
		cssincluded: false
	};
 }

 };
 
}();

}


// Next calls should be made by the inheriting file:

// vnp_badge.setRenderMethod( function () {
//  var el = this.bind(this.el);
//  return [
// 	el( 'div', {'class': 'testdiv', 'text-align' : 'center'}, [ el('span',{},'shady1') , el('span',{},'shady2') ] ) 
//  ];
// 
//  }
// );
// 
// vnp_badge.init();
// 
// vnp_badge.writeBadge();
function addbadge2() {
if ( arguments.callee.done )
	return;
arguments.callee.done = true;

var id = vnp_badge.addBadge( function () {
 var el = this.bind(this.el);
 return [ 
			el('span', { 'style' : 'color : #660000; '}, ['squares sold: '] ),
			el('span', {}, ['1901']),
			el('br', {}, []),
			el('span', { 'style' : 'color : #660000'} , ['squares left: ']),
			el('span', {}, ['8099'])
 ];

 },
 'library/badges.css', 
 'vnp_badge_2',
 ''
);

vnp_badge.init();

vnp_badge.writeBadge(id);
}
addbadge2();