// START: Save/Share A/B Testing
function init_save_share() {
	var ss_recipes = new Array("default","sidebar","inline_small","inline_big","bottom","strip");
	var ss_ids = new Array("saveArticle","saveshare-sidebar","saveshare-inline_small-wrapper","saveshare-inline_big-wrapper","saveshare-bottom-wrapper","saveshare-strip-wrapper");

	if ( typeof saveshare_recipe == "undefined" ) {
		saveshare_recipe = 'default';
	}

	var ss_css_output = '<style>\n';
	for (var i=0;i<ss_recipes.length;i++) {
		var recipe = ss_recipes[i];
		var id = ss_ids[i];
		if (recipe == saveshare_recipe)
			ss_css_output += '#'+id+' {display:block;}\n';
		else
			ss_css_output += '#'+id+' {display:none;}\n';
	}
	ss_css_output += '</style>\n';

	document.write(ss_css_output);
}
function place_badges_at_bottom(){
	if ( typeof saveshare_recipe == "undefined" ) {
		saveshare_recipe = 'default';
	}

	// Note, this must be called before the inline ad is placed at the bottom of the page
	inlineAdClearance = getInlineAdClearance(saveshare_recipe);

	hideContent('digg');
	hideContent('facebook');

	$('wp-badge-1').insert( $('wp-diggthis').setStyle({display:'block'})  );
	$('wp-badge-2').insert( $('wp-fbshare').setStyle({display:'block',paddingLeft:'10px'})   );
	$('wp-badge-3').insert( $('wp-tweetmeme').setStyle({display:'block'}) );

	move_bank_of_icons(saveshare_recipe);

	insert_google_buzz();
	// remove_fb_share();
}
function remove_fb_share(){
	if ( typeof NETWORK_NEWS_ON != 'undefined' && NETWORK_NEWS_ON ) {
		$('wp-badge-2').hide(); // fb share
		$('saveshare-bottom').setStyle({width:'75%'});
		$w('wp-badge-0 wp-badge-1 wp-badge-2 wp-badge-3').each(function(id){
			if ( $(id) ) {
				$(id).setStyle({width:'16%'});
			}
		});
	}
}
function insert_google_buzz(){
	if ( typeof GOOGLEBUZZ_ON != 'undefined' && GOOGLEBUZZ_ON ) {
		// insert wp-googlebuzz
		$('wp-diggthis').insert({before:'<span id="wp-googlebuzz" style="display:none;"></span>'});

		// set some props
		var google_buzz = {
			"link":'', // to be constructed
			"script":'<sc'+'ript type="text/javascript" src="http://www.google.com/buzz/api/button.js"></sc'+'ript>',
			"attributes":{
				"title":'Post to Google Buzz',
				"class":'google-buzz-button',
				"href":'http://www.google.com/buzz/post',
				"data-button-style":'normal-count'
			}
		};

		if ( typeof wp_article != 'undefined' && wp_article.path ) {
			google_buzz.attributes['data-url'] = wp_article.path;
			// google_buzz.attributes['data-message'] = wp_article.headline;
			if ( typeof Prototype != 'undefined' ) {
				var els = $$('link[rel="image_src"]');
				if (els.length) {
					google_buzz.attributes['data-imageurl'] = els.detect(function(e){return e}).readAttribute('href');
				}
			}
		}

		google_buzz['link'] += '<a';
		for (var att in google_buzz.attributes) {
			google_buzz['link'] += ' '+att+'="'+google_buzz.attributes[att]+'"';
		}
		google_buzz['link'] += '></a>';

		// output actual code
		$('wp-googlebuzz').insert(google_buzz['link']);
		document.write(google_buzz['script']);

		// insert wp-badge-0
		var gb_code = '<div id="wp-badge-0" class="column badge"></div>';
		$('saveshare-bottom').setStyle({width:'95%'});
		$('saveshare-bottom').childElements().first().insert( {before:gb_code} );

		// set widths for google, digg, facebook, twitter
		$w('wp-badge-0 wp-badge-1 wp-badge-2 wp-badge-3').each(function(id){
			if ( $(id) ) {
				// $(id).setStyle({width:'16%',zIndex:100000,float:'left'});
				$(id).setStyle({width:'16%'}); // tweetmeme off as of 2010/07/29
				// $(id).setStyle({width:'12%'});
			}
		});

		// move code
		$('wp-badge-0').insert( $('wp-googlebuzz').setStyle({display:'block'})  );
	}
}
function finish_save_share() {
	// document.observe('dom:loaded',function() {
	var ss_recipes = new Array("default","sidebar","inline_small","inline_big","bottom","strip");
	var ss_ids = new Array("saveArticle","saveshare-sidebar","saveshare-inline_small-wrapper","saveshare-inline_big-wrapper","saveshare-bottom-wrapper","saveshare-strip-wrapper");

		var p=null; var c=null; var s=null;

		if ( typeof saveshare_recipe == "undefined" ) {
			saveshare_recipe = 'default';
		}

		// Note, this must be called before the inline ad is placed at the bottom of the page
		inlineAdClearance = getInlineAdClearance(saveshare_recipe);

		// for large icons
		if ( saveshare_recipe.match(/^(inline|bottom)/) ) {
			hideContent('digg');
			hideContent('facebook');

			p = document.getElementById('wp-diggthis-'+saveshare_recipe) ;
			c = document.getElementById('wp-diggthis') ;
			c.style.display = 'block';
			s = document.getElementById('wp-diggthis-'+saveshare_recipe+'-placeholder') ;
			insertContentAfterSibling(p,c,s);
/*
			p = document.getElementById('wp-facebook-'+saveshare_recipe) ;
			c = document.getElementById('wp-facebook') ;
			c.style.display = 'block';
			s = document.getElementById('wp-facebook-'+saveshare_recipe+'-placeholder') ;
			insertContentAfterSibling(p,c,s);
*/
			$('wp-facebook-'+saveshare_recipe).insert({
				bottom: new Element('div',{
					id:'wp-facebook-share',
					align:'center'
				})
			});
			$('wp-facebook-share')
				.setStyle({
					margin:'0 auto'
				})
				.insert({
					top: new Element('a',{
						name:'fb_share',
						type:'box_count',
						share_url:wp_article.path+'?referrer=facebook'
					})
				})
				.insert({
					bottom: new Element('script',{
						src:'http://www.facebook.com/connect.php/js/FB.SharePro/',
						type:'text/javascript'
					})
				})
			;

		}

		// for inline ad
		if ( saveshare_recipe.match(/^inline/) ) {
			var saveshare_clearance = getSaveShareClearance(saveshare_recipe);
			var inlineSaveShareParent = document.getElementById('body_after_content_column') ;
			var inlineSaveShareSibling = getAvailableTagInContainer('p','body_after_content_column','content_column_table',saveshare_clearance);
			if ( inlineSaveShareSibling ) {
				if ( saveshare_recipe.match(/^inline_small/) ) {
					var inlineSaveShareSmall = document.getElementById('saveshare-inline_small-wrapper') ;
					insertContentAfterSibling(document.getElementById('body_after_content_column'),inlineSaveShareSmall,inlineSaveShareSibling );
				} else if ( saveshare_recipe.match(/^inline_big/) ) {
					var inlineSaveShareBig = document.getElementById('saveshare-inline_big-wrapper')
					insertContentAfterSibling(document.getElementById('body_after_content_column'),inlineSaveShareBig,inlineSaveShareSibling );
				}
				if (typeof otto!='undefined'){
					mboxFactoryDefault.addOnLoad(function(){
						otto.mboxUpdate('wp_saveshare_update','inline_ss=yes')
					});
				}
			} else {
				document.getElementById('saveshare-'+saveshare_recipe+'-wrapper').style.display = 'none';
				if (typeof otto!='undefined'){
				mboxFactoryDefault.addOnLoad(function(){
						otto.mboxUpdate('wp_saveshare_update','inline_ss=no')
					});
				}
			}
		}

		// for resetting text
		if ( saveshare_recipe.match(/^(strip)/) ) {
			var services = new Array('digg','facebook','reddit','newsvine','myspace','delicious','newstrust','stumble','furl','google','rojo','yahoo');
			var service_icons = new Array('digg.gif','facebook.gif','reddit.gif','icon_newsvine.gif','myspace.gif','delicious.gif','icon_newstrust.gif','icon_stumble_upon.gif','furl.gif','google.gif','rojo.gif','yahoo.gif');
			for (var i=0; i<services.length; i++) {
				resetLinkTextWithImage(services[i],service_icons[i]);
			}
		}

		// for moving bank of icons
		if ( saveshare_recipe.match(/^(sidebar|inline_big|bottom|strip)/) ) {
			move_bank_of_icons(saveshare_recipe);
		}
	// });
}
function move_bank_of_icons(saveshare_recipe){
	p = document.getElementById('bookmark-'+saveshare_recipe) ;
	c = document.getElementById('bookmark-content') ;
	s = document.getElementById('bookmark-'+saveshare_recipe+'-placeholder') ;
	insertContentAfterSibling(p,c,s);
}
function getSaveShareClearance(recipe){
	var clearance = 0 ;

	if ( recipe.match(/^inline/) ) {
		if ( typeof COMMENTS_ACTIVE == 'boolean' && COMMENTS_ACTIVE )
			clearance += 75 ;
		else
			clearance += 50 ;
	}

	return clearance;
}
function getInlineAdClearance(recipe){
	var clearance = 200 ;
	clearance += getSaveShareClearance(recipe);

	if ( recipe.match(/^inline/) ) {
		clearance += 30 + document.getElementById('saveshare-'+recipe+'-wrapper').offsetHeight ;
	}

	return clearance;
}
function changebg2(id){
	if ( typeof saveshare_recipe != 'undefined' && saveshare_recipe.match(/^(sidebar|inline_big|bottom|strip)/) ) {
		document.getElementById(id).style.background = '#FFF';
	} else {
		document.getElementById(id).style.background = '#EEE';
	}
}
function resetbg2(id){
	if ( typeof saveshare_recipe != 'undefined' && saveshare_recipe.match(/^(sidebar|inline_big|bottom|strip)/) ) {
		document.getElementById(id).style.background = '#FFF';
	} else {
		document.getElementById(id).style.background = '#EEE';
	}
}
function resetLinkTextWithImage(id,icon) {
	if ( document.getElementById(id+'-link') ) {
		icon = '<img src="http://media3.washingtonpost.com/wp-srv/bookmarking/'+icon+'" border="0">';
		document.getElementById(id+'-link').innerHTML = icon;
	}
}
function saveExpando3(type) {
	var saveArticle = document.getElementById("saveArticle");
	var shareExpando = document.getElementById("shareExpandBox");
	var saveSign = document.getElementById("saveSign");

	if (type == "show") {
		saveArticle.className = "saveDevelopBorder";
		document.saveIcon.src = "http://www.washingtonpost.com/wp-srv/article/images/icon_save_grey.gif";
		saveSign.innerHTML = String.fromCharCode(187);
	} else {
		saveArticle.className = "saveDevelop";
		document.saveIcon.src = "http://www.washingtonpost.com/wp-srv/article/images/icon_save.gif";
		saveSign.innerHTML = "+";
	}
}
// END: Save/Share A/B Testing
