/**
 * ...
 */

// updated: switched to document.write for output because of some unusual
// load behavior in IE

(function(){

	// username
	var display_name = " Cameron Barrett";

	// control values
	var max = Number( "" );
	var sectionmax = Number( "" );

	// attending
	
	var attending_future = null;
	
	// watching
	
	var watching_future = null;
	
	// speaking
	
	var speaking_future = null;
	
	// construct the content
	
	var i, o, img, section, obj, header, entry, entries, link, data, ct = 0;
	var parms = {}, sections = {};
	var content = document.createElement( "div" );
	content.className = "confabbBadgeList";

	var sections = { Speaking:speaking_future, Attending:attending_future, Watching:watching_future }; 

	for( section in sections )
	{
		if( sections[section] )
		{
			header = document.createElement( "span" );
			header.className = "confabbBadgeHeader";
			header.innerHTML = section;
			content.appendChild( header );
			
			entries = document.createElement( "ul" );
			entries.className = "confabbSectionHeader";
			
			for( i = 0; i< sections[section].length && (sectionmax == 0 || i < sectionmax) && ( max == 0 || ct < max ); i++ )
			{
				obj = sections[section][i];
				if( obj ) // weird IE behavior - is it my stray comma?
				{
					entry = document.createElement( "li" );
					entry.className = "confabbBadgeEntry";
					
					link = document.createElement( "a" );
					link.className = "confabbBadgeLink";
					link.href = obj.link;
					link.innerHTML = obj.name;
					entry.appendChild( link );
					
					data = document.createElement( "span" );
					data.className = "confabbBadgeInfo";
					data.innerHTML = obj.metadata;
					entry.appendChild( data );
					entries.appendChild( entry );
					
					ct++;
				}
			}
			
			content.appendChild( entries );
		}
	}

	// add to the page
	o = document.createElement( "div" );
	o.id = "confabbBadgeContent" ;
	
	// header
	header = document.createElement( "div" );
	header.className = "confabbBadgeTitle";
	header.innerHTML = " Cameron Barrett&rsquo;s Conferences";
	o.appendChild( header );
	
	// branding
	obj = document.createElement( "div" );
	obj.style.display = "block";
	obj.style.fontFamily = "lucida grande, verdana, arial";
	obj.style.fontWeight = "normal";
	obj.style.color = "#ccc";
	obj.style.fontSize = "9px";
	obj.style.textAlign = "right";
	obj.innerHTML = 'powered by <a href="http://www.confabb.com" target="_new" style="font-weight:bold; text-decoration:none; color:#666;">confabb</a>';
	content.appendChild( obj );
	o.appendChild( content );
	
	// paste in
	document.write( o.innerHTML );

})();

