js_months = new Array('Jan.','Feb.','March','April','May','June','July','Aug.','Sept.','Oct.','Nov.','Dec.') ;

function display_headlines(headlines)
{
	for ( var i=0; i<headlines.length; i++ )
	{
		var item = headlines[i] ;
		document.write("<a href="+item.url+">") ;
		document.write(item.headline) ;
		document.write("</a>") ;
		document.write("<br/>") ;
	}
}

function render_js_headlines(style,collection,maximum)
{
	if ( typeof style == "undefined" )
		style = "default" ;
	if ( typeof collection == "undefined" && typeof headlines == "object" )
		collection = headlines ;
	if ( typeof maximum == "undefined" )
		maximum = 5 ;
	if ( maximum > collection.length )
		maximum = collection.length ;

	var output = '' ;
	switch ( style )
	{
		case "realestate":
		{
			render_js_realestate() ;
			break ;
		}
		case "sidebar":
		{
			render_js_sidebar() ;
			break ;
		}
		case "strip_of_links":
		{
			render_js_sidebar() ;
			break ;
		}
		case "default" :
		{
			render_js_default() ;
			break ;
		} 
		case "entertainment" :
		{
			render_js_entertainment() ;
			break ;
		}
		case "columnist" :
		{
			render_js_columnist() ;
			break ;
		}
		case "columns" :
		{
			render_js_columns() ;
			break ;
		}
		case "kidspost" :
		{
			render_js_kidspost() ;
			break ;
		}
		case "plain_links" :
		{
			render_js_plain_links() ;
			break ;
		}
		case "plain_links_bullets" :
		{
			render_js_plain_links_bullets() ;
			break ;
		}
	}
	// document.write('<form><textarea>') ;
	document.write( output ) ;
	// document.write('</textarea></form>') ;
	function render_js_entertainment()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'">\n' ;
		output += '<ul style="list-style-image: url(http://media.washingtonpost.com/wp-adv/classifieds/realestate/redesign/images/black.gif)">\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
			output += '<li><span class="bullet_spacing">' ;
			output += '<a href="'+item.url+'">'+item.headline+'</a>' ;
			if ( item.source != '' || item.pubdate != '' )
			{
				output += '<span class="source">' ;
				output += ' <nobr><i>' ;
				if ( item.source != '' )
					output += item.source ;
				if ( item.source != '' && item.pubdate != '' )
					output += ', ' ;
				output += getDateTime(item.pubdate);
				output += '</i></nobr>' ;
				output += '</span>' ;
			}
			output += '</span></a>\n' ;
		}
		output += '</ul>\n' ;
		output += '</div>\n' ;
		output += '</div>\n' ;
	}
	function render_js_columns()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'">\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
			output += '<a href="'+item.url+'">'+item.headline+'</a> ' ;
			if ( item.source != '' || item.pubdate != '' )
			{
				output += '<span class="source">' ;
				output += ' <nobr>(' ;
				if ( item.source != '' )
					output += item.source ;
				if ( item.source != '' && item.pubdate != '' )
					output += ', ' ;
				output += getDateTime(item.pubdate, item.source);
				output += ')</nobr>' ;
				output += '</span>' ;
			}
			output += '</span></a><br/>\n' ;
		}
		output += '</div>\n' ;
		output += '</div>\n' ;
	}
	
	function render_js_kidspost()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'">\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
			output += '<div style="margin-bottom:6px;"><a href="'+item.url+'">'+item.headline+'</a> ' ;
			if ( item.source != '' || item.pubdate != '' )
			{
				output += '<span class="source">' ;
				output += ' <nobr>(' ;
				if ( item.source != '' )
					output += item.source ;
				if ( item.source != '' && item.pubdate != '' )
					output += ', ' ;
				output += getDateTime(item.pubdate, item.source);
				output += ')</nobr>' ;
				output += '</span>' ;
			}
			output += '</span></a></div>\n' ;
		}
		output += '</div>\n' ;
		output += '</div>\n' ;
	}
	
	function getDateTime(aDate, source) {
		if (aDate == '') { return ''; }
		var dateString = js_months[aDate.getMonth()] ;
		dateString += ' ' ;
		dateString += aDate.getDate() ;
		if (source != 'Post') {
			var hours = aDate.getHours() ;
			var ampm = "AM";
			if (hours >= 12) {
				ampm = "PM";
				hours = hours - 12;
			}
			if (hours == 0) { hours = 12; }
			var mins = aDate.getMinutes();
			if (mins < 10) { mins = "0"+mins; }
			dateString += '; ' + hours + ':' + mins + ' ' + ampm;
		}

		return dateString;
	}
	function render_js_sidebar()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'">\n' ;
		output += '<ul style="list-style-image: url(http://media.washingtonpost.com/wp-adv/classifieds/realestate/redesign/images/black.gif)">\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
			output += '<li><span class="bullet_spacing">' ;
			output += '<a href="'+item.url+'">'+item.headline+'</a>' ;
			if ( item.source != '' || item.pubdate != '' )
			{
				output += '<span class="source">' ;
				output += ' <nobr>(' ;
				if ( item.source != '' )
					output += item.source ;
				if ( item.source != '' && item.pubdate != '' )
					output += ', ' ;
				if ( item.pubdate != '' )
				{
					output += js_months[item.pubdate.getMonth()] ;
					output += ' ' ;
					output += item.pubdate.getDate() ;
					var hours = item.pubdate.getHours();
					var ampm = "AM";
					if (hours >= 12) {
						ampm = "PM";
						hours = hours - 12;
					}
					if (hours == 0) { hours = 12; }
					output += '; ' + hours + ':' + item.pubdate.getMinutes() + ' ' + ampm;
				}
				output += ')</nobr>' ;
				output += '</span>' ;
			}
			output += '</span></a>\n' ;
		}
		output += '</ul>\n' ;
		output += '</div>\n' ;
		output += '</div>\n' ;
	}

	function render_js_strip_of_links()
	{
		// alert(style) ;
	}
	
	function render_js_plain_links()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'">\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
				output += '<span>';
				output += '<a href="'+item.url+'">'+item.headline+'</a>' ;
				output += '</a></span><br />\n' ;
		}
		output += '</div>\n' ;
		output += '</div>\n' ;
	}
	
	function render_js_plain_links_bullets()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'"><ul>\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
				output += '<span>';
				output += '<li><a href="'+item.url+'">'+item.headline+'</a>' ;
				output += '</li></span>\n' ;
		}
		output += '</a></ul><div class="clearboth"></div></div>\n' ;
		output += '</div>\n' ;
	}
	
	function render_js_columnist()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'">\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
			var author = getAuthor(item.byline);
			if (author != '') {
				output += '<span>';
				output += '<b>'+getAuthor(item.byline)+': </b>' ;
				output += '<a href="'+item.url+'">'+item.headline+'</a>' ;
				output += '</a></span><br />\n' ;
			}
		}
		output += '</div>\n' ;
		output += '</div>\n' ;
	}
	function getAuthor(byline)
	{
		if (byline == '') return byline;
		var re = /^By /;
		return byline.replace(re,"");
	}
	function render_js_realestate()
	{
		output += '<div id="headlines_js">\n' ;
		output += '<div class="'+style+'">\n' ;
		output += '<ul style="list-style-image: url(http://media.washingtonpost.com/wp-adv/classifieds/realestate/redesign/images/black.gif)">\n' ;
		for (var i=0; i<maximum; i++ )
		{
			var item = collection[i] ;
			output += '<li><span class="bullet_spacing">' ;
			output += '<a href="'+item.url+'">'+item.headline+'</a>' ;
			if ( item.source != '' || item.pubdate != '' )
			{
				output += '<span class="source">' ;
				output += ' <nobr>(' ;
				if ( item.source != '' )
					output += item.source ;
				if ( item.source != '' && item.pubdate != '' )
					output += ', ' ;
				if ( item.pubdate != '' )
				{
					output += js_months[item.pubdate.getMonth()] ;
					output += ' ' ;
					output += item.pubdate.getDate() ;
				}
				output += ')</nobr>' ;
				output += '</span>' ;
			}
			output += '</span></a>\n' ;
		}
		output += '</ul>\n' ;
		output += '</div>\n' ;
		output += '</div>\n' ;
	}

	function render_js_default()
	{
		// alert(style) ;
	}

}
