// community scripts

/*function toggleMemberCenter(tab) {
	if(tab == 0) {
		$('account-content').style.display = 'block';
		$('email_tab').style.display = 'none';
		$('account_info_tab').className = 'here';
		$('newsletter_tab').className = '';
	} else {
		$('account_info').style.display = 'none';
		$('newsletter').style.display = 'block';
		$('account_info_tab').className = '';
		$('newsletter_tab').className = 'here';					
		}
}
*/


/* tabs for the account settings page */

//check the url for the newsletter link
var docpath = window.location.href;
//var isAccoutTab = docpath.indexOf("newsletterId=");
var this_content = "account-tab-content";
var this_tab = "account-tab";

if(docpath.indexOf("newsletterId=") != -1) {
	var this_content = "email-tab-content";
	var this_tab = "email-tab";
}
if(docpath.indexOf("wallpaper_tab") != -1) {
	var this_content = "wallpaper-tab-content";
	var this_tab = "wallpaper-tab";
}
if(docpath.indexOf("avatar_tab") != -1) {
	var this_content = "photo-tab-content";
	var this_tab = "photo-tab";
}
if(docpath.indexOf("bio_tab") != -1) {
	var this_content = "bio-tab-content";
	var this_tab = "bio-tab";
}


account_tabs = {
	current_info: this_content,
	old_tab: this_tab,	
	init: function() {
		if(!$("mc_tabs")) return false;
		var li = $("mc_tabs").getElementsByTagName("li");
		
		$("email-tab-content").hide();
		$("wallpaper-tab-content").hide();
		$("photo-tab-content").hide();
		$("bio-tab-content").hide();
		$("account-tab-content").hide();
		
		$(account_tabs.old_tab).addClassName("here");
		$(account_tabs.current_info).show();
		
		for(var i=0; i<li.length; i++) {
			li[i].onclick = function() { 
			account_tabs.toggler(this); 
			return false; 
			};
		}
	},
	toggler: function(obj) {
		var id = obj.getAttribute("id");
		var tab = id + "-content";
		//console.log(tab);
		if(account_tabs.old_tab != id) {
			$(tab).show();
			//obj.className = "here";
			$(obj).addClassName("here");
			$(account_tabs.current_info).hide();
			account_tabs.current_info = tab;
			$(account_tabs.old_tab).removeClassName("here");
			account_tabs.old_tab = id;
		}
	}
}

addLoadEvent(account_tabs.init);




// used on edit photo and wallpaper pages

function selectWallpapers() {

//apply to these ID's
var applyTo = $("wallpapers");
var wallpaperValue = document.getElementById("propID_wallpaper")
	if($(applyTo)) {
		var applyToImgs = applyTo.getElementsByTagName("img");
		
			for(j=0; j<applyToImgs.length; j++) {
				applyToImgs[j].onclick = function() {
				for(k=0; k<applyToImgs.length; k++) {
					applyToImgs[k].className = "";
				}
				this.className = "selected";
				wallpaperValue.value = this.name;
				//console.log(this.name);
				}
				//alert("hi there");
			}
		}
	}

addLoadEvent(selectWallpapers);


function selectIllustrations() {

//apply to these ID's
var applyTo = $("illustrations");
var avatarValue  = document.getElementById("propID_avatar");
var avatarChange = document.getElementById("avatar_change");

	if($(applyTo)) {
		var applyToImgs = applyTo.getElementsByTagName("img");
			for(j=0; j<applyToImgs.length; j++) {
				applyToImgs[j].onclick = function() {
				for(k=0; k<applyToImgs.length; k++) {
					applyToImgs[k].className = "none";
				}
				this.className = "selected";
				avatarValue.value = this.name;
				avatarChange.value = "y";
				//console.log(this.name);
				}
				//alert("hi");
			}
		}
	}

addLoadEvent(selectIllustrations);

function selectStar() {
	var getStars = $("rating_container");
	if($(getStars)){
		var applyToLis = getStars.getElementsByTagName("li");
		for(i=0; i<applyToLis.length; i++) {
		//console.log(applyToLis[i]);
			applyToLis[i].onclick = function() {
				for(k=0; k<applyToLis.length; k++) {
					console.log(applyToLis[k]);
					applyToLis[k].style.display = "none";
				}
				document.rateform.ratevalue = value;
				$(getStars).className = "turn-off";
				$("rating_saving").style.display = "block";
	   			processAction('ratephoto', 'rateform', 'rating_container', '');
				$(getStars).className = "turn-on";
				$("rating_saving").style.display = "none";
			}
		}
	}
}





/* modal delete legacy code */

function cf_modalBox(box, yesUrl) {
	
	//run overlay function
	globalOverlay();	

	getPageScroll(); 
	
	//remove existing modal code if it exists already
	if($('modal_win')) { document.body.removeChild($('modal_win')); }

	if(box == "deleteCollection") { 
    var myDiv = cf_modalDeleteCollection.replace('__SUCCESS_URL_PLACEHOLDER__', yesUrl);
	  new Insertion.After('modal_win_overlay', myDiv); 
	} 
		
	if(box == "reportContent") { 
    var myDiv = cf_modalReportContent.replace('__ACTION_URL_PLACEHOLDER__', yesUrl);
	  new Insertion.After('modal_win_overlay', myDiv); 
	} 	

	if(box == "deletePhoto") { 
    var myDiv = cf_modalDeletePhoto.replace('__SUCCESS_URL_PLACEHOLDER__', yesUrl);
	  new Insertion.After('modal_win_overlay', myDiv); 
	} 	

	if(box == "deleteComment") { 
    var myDiv = cf_modalDeleteComment.replace('__SUCCESS_URL_PLACEHOLDER__', yesUrl);
	  new Insertion.After('modal_win_overlay', myDiv); 
	} 	

	
	//center modal window (toggle visibility it while it centers)
	$('modal_win').style.visibility='hidden';
	modalWidth = $('modal_win').offsetWidth/2;
	screenCenter = (x/2-modalWidth)+'px';
	$('modal_win').style.left = screenCenter;
	$('modal_win').style.top = (yScroll + 150) + 'px';					
	$('modal_win').style.visibility='visible';

}	


/* delete collection item */
cf_modalDeleteCollection = '<div id="modal_win" class="modal_win_490"><div id="modal_win_outer"><div id="modal_win_inner">';
cf_modalDeleteCollection += '<p id="close_modal_win" onClick="closeModal()">CLOSE</p>';
cf_modalDeleteCollection += '<div id="delete_collection_item"><p>Are you sure you want to delete this item from your Collections?</p>';
cf_modalDeleteCollection += '<p id="delete_collection_item_submit">';
cf_modalDeleteCollection += '<form id="deleteItemForm" name="deleteItemForm" action="__SUCCESS_URL_PLACEHOLDER__" method="post">';
cf_modalDeleteCollection += '<input type="image" src="http://images.marthastewart.com/images/assets/module/registration/reg_yes.gif" alt="yes" onclick="document.report.commentId=report_comment_id" />&nbsp;';		
cf_modalDeleteCollection += '<input type="image" src="http://images.marthastewart.com/images/assets/module/registration/reg_no.gif" alt="no" onclick="parent.closeModal(); return false;"  />';
cf_modalDeleteCollection += '</form>';
cf_modalDeleteCollection += '</p>';
cf_modalDeleteCollection += '</div>';
cf_modalDeleteCollection += '</div></div></div>';

/* report content (profile public) */
cf_modalReportContent = '<div id="modal_win" class="modal_win_490"><div id="modal_win_outer"><div id="modal_win_inner">';
cf_modalReportContent += '<p id="close_modal_win" onClick="closeModal()">CLOSE</p>';
cf_modalReportContent += '<div id="report_content">';
cf_modalReportContent += '<h2>Report</h2>';
cf_modalReportContent += '<p>You are about to report something as inappropriate, and an alert will be sent to us. Please tell us why you find this inappropriate.</p>';
cf_modalReportContent += '<form name="reportProfileForm" id="reportProfileForm" action="__ACTION_URL_PLACEHOLDER__" method="post">';
cf_modalReportContent += '<textarea name="ratingDesc"></textarea>';
cf_modalReportContent += '<p id="report_content_submit">';
cf_modalReportContent += '<input type="image" src="http://images.marthastewart.com/images/assets/module/registration/reg_yes.gif" alt="yes" />&nbsp;';		
cf_modalReportContent += '<input type="image" src="http://images.marthastewart.com/images/assets/module/registration/reg_no.gif" alt="no" onclick="parent.closeModal(); return false;"  />';
cf_modalReportContent += '</p>';
cf_modalReportContent += '</form>'; 
cf_modalReportContent += '</div>';
cf_modalReportContent += '</div></div></div>';

/* delete photo */
cf_modalDeletePhoto = '<div id="modal_win" class="modal_win_490"><div id="modal_win_outer"><div id="modal_win_inner">';
cf_modalDeletePhoto += '<p id="close_modal_win" onClick="closeModal()">CLOSE</p>';
cf_modalDeletePhoto += '<div id="delete_collection_item"><p>Are you sure you want to delete this photo? (Your photo may still appear in the gallery for a few minutes after deletion)</p>';
cf_modalDeletePhoto += '<p id="delete_collection_item_submit">';
cf_modalDeletePhoto += '<form id="deleteItemForm" name="deleteItemForm" action="__SUCCESS_URL_PLACEHOLDER__" method="post">';
cf_modalDeletePhoto += '<input type="image" src="http://images.marthastewart.com/images/assets/module/registration/reg_yes.gif" alt="yes" onclick="document.report.commentId=report_comment_id" />&nbsp;';		
cf_modalDeletePhoto += '<input type="image" src="http://images.marthastewart.com/images/assets/module/registration/reg_no.gif" alt="no" onclick="parent.closeModal(); return false;"  />';
cf_modalDeletePhoto += '</form>';
cf_modalDeletePhoto += '</p>';
cf_modalDeletePhoto += '</div>';
cf_modalDeletePhoto += '</div></div></div>';

/* delete comment */
cf_modalDeleteComment = '<div id="modal_win" class="modal_win_490"><div id="modal_win_outer"><div id="modal_win_inner">';
cf_modalDeleteComment += '<p id="close_modal_win" onClick="closeModal()">CLOSE</p>';
cf_modalDeleteComment += '<div id="delete_collection_item"><p>Are you sure you want to delete this comment?</p>';
cf_modalDeleteComment += '<p id="delete_collection_item_submit">';
cf_modalDeleteComment += '<a href="__SUCCESS_URL_PLACEHOLDER__">';
cf_modalDeleteComment += '<img src="http://images.marthastewart.com/images/assets/module/registration/reg_yes.gif" alt="yes"/>';
cf_modalDeleteComment += '</a>';
cf_modalDeleteComment += '<input type="image" src="http://images.marthastewart.com/images/assets/module/registration/reg_no.gif" alt="no" onclick="parent.closeModal(); return false;"  />';
cf_modalDeleteComment += '</p>';
cf_modalDeleteComment += '</div>';
cf_modalDeleteComment += '</div></div></div>';




/* show and hide comment / attach report post onclicks */

comments = {
	init: function() {
	if(!$('conversation-container')) return false;
	var handlers = $('conversation-container').getElementsByTagName("a");
	for(var i=0; i<handlers.length; i++) {
		comments.rel = handlers[i].getAttribute("rel");
		switch(comments.rel) {
			case "add-comment-hdr":
			handlers[i].onclick = function() {
				$('add-comment-hdr').style.display = 'block';
				$('toggle-comment-hdr').className = 'active';
				trackAction('addcomment');
			}
			break;
			case "cancel-comment-hdr":
			handlers[i].onclick = function() {
				$('add-comment-hdr').style.display = 'none';
				$('toggle-comment-hdr').className = '';
			}
			break;
			case "add-comment-ftr":
			handlers[i].onclick = function() {
				$('add-comment-ftr').style.display = 'block';
				$('toggle-comment-ftr').className = 'active';
			}
			break;
			case "cancel-comment-ftr":
			handlers[i].onclick = function() {
				$('add-comment-ftr').style.display = 'none';
				$('toggle-comment-ftr').className = '';
				trackAction('addcomment');
			}
			break;
			case "report-comment":
			handlers[i].onclick = function() {
				report_comment_id = this.getAttribute("id");
				modalBox('report');
				return false;
			}
			break;
			case "delete-comment":
			handlers[i].onclick = function() {
				delete_comment_id = this.getAttribute("id");
				modalBox('deleteComment');
				return false;
			}
			break;
			}
		}
		if (typeof(engagement_toolbar) != 'undefined') {
			// TBD: check this id against rob's new definition
			// binding the add comment link on engagement toolbar to function that opens comment form
			$('btn_collect_comment').onclick = function() {
				$('add-comment-hdr').style.display = 'block';
				$('toggle-comment-hdr').className = 'active';
				trackAction('addcomment');
			}				  
		}
	}
}

addLoadEvent(comments.init);

checkMaxLength = {
	init: function() {
		if(!$('conversation-container')) return false;
		var x = document.getElementsByTagName('textarea');
		for (var i=0;i<x.length;i++) {
			if (x[i].getAttribute('maxlength')) {
				x[i].onkeyup = function() {
					checkMaxLength.monitor(this);
				}
			}
		}
	},
	monitor: function(e) {
	var maxLength = e.getAttribute('maxlength');
	var currentLength = e.value.length;
	var getId = e.getAttribute("id");
	if (currentLength > maxLength) {
		$(getId + '_maxlength_error').style.display = "block";
		if(getId == "collect-tags" || getId == "collect-notes") {
			$(getId + '_maxlength_error').innerHTML = "It's wondeful you have a lot to say, but you exceeded the " + maxLength + " character limit. Please trim then save.";
		} else {
			$(getId + '_maxlength_error').innerHTML = "Oops! You've exceeded " + maxLength + " character limit";
		}
		if ($$('#upload_photo_detail_submit input')[0]) {
			tmp = $$('#upload_photo_detail_submit input')[0];
			tmp.onclick = function() {
	 			return false;
			};
		}
	}
	if (currentLength < maxLength) {
		$(getId + '_maxlength_error').innerHTML = '';
		$(getId + '_maxlength_error').style.display = "none";
		if ($$('#upload_photo_detail_submit input')[0]) {
			tmp = $$('#upload_photo_detail_submit input')[0];
			tmp.onclick = function() {
	 			return true; 
			};
		}
		}
	},
	isMaxLengthOk: function(whichForm) {
		var getErrors = $(whichForm).getElementsByClassName("maxlength_error");
		for(var i=0; i<getErrors.length; i++) {
			if(getErrors[i].innerHTML != '') {
				return false;
			}
		}
		return true;
	}
}

addLoadEvent(checkMaxLength.init);

// collect/rate/print/email toolbar

collect = {
	current: 0,
	current_actiive: 0,
	init: function() {
		if(!$('collect-article')) return false;
		var handlers = $('collect-article').getElementsByTagName("a");
		for(var i=0; i<handlers.length; i++) {
			switch(handlers[i].getAttribute("rel")) {
				case "collect-labelnote":
				handlers[i].onclick = function() {
 					if (document.getElementsByTagName("body")[0].className == 'package') {
						updateCommunityToolsParams();
					}
					save();
				}
				break;
				case "collect-rate":
				handlers[i].onclick = function() {
					if (typeof(engagement_toolbar) == 'undefined') {
						collect.toggle(this,'collect-rate');
						trackAction('ratetab');
					} else {
						oneClickRecommend();
					}

				}
				break;
				case "cancel":
				handlers[i].onclick = function() {
					collect.close();
				}
				break;
				case "collect-sharebook":
					handlers[i].onclick = function() {
						if (typeof(engagement_toolbar) == 'undefined') {
							collect.toggle(this,'collect-sharebook');
							collect.current = 'collect-sharebook';
							collect.current_active = 'btn_collect_sharebook';
							if (typeof(FB.XFBML) != "undefined") {
								FB.XFBML.Host.parseDomTree();
								updatefbcopy();
							}
						}
					}
					break;
			}
		}
		collect.clearTxt();
	},
	toggle: function(which,el) {
		$(which).className = 'active';
		if(collect.current != 0 && collect.current_active != $(which).getAttribute("id")) {
			$(collect.current).style.display = 'none';
			$(collect.current_active).className = '';
		}
		if ($$('.project_meta').length > 0) {
			$$('.project_meta')[0].style.display = 'none';
		}
		$(el).style.display = 'block';
		collect.current = el;
		collect.current_active = $(which).getAttribute("id");
	},
	close: function() {
		$(collect.current).style.display = 'none';
		$(collect.current_active).className = '';
		if ($$('.project_meta').length > 0) {
			$$('.project_meta')[0].style.display = 'block';
		}

	},
	clearTxt: function() {
		var tagTxt = "Separate each tag with a comma. If this is a brownie recipe, you might type: chocolate, dessert, Sue's party";
		var noteTxt = "Leave yourself a reminder, a tweak, an idea, or anything else related to this item.";
		$('tags').onfocus = function() {
		if(this.value == tagTxt) { this.value = ''; }
		}
		$('note').onfocus = function() {
		if(this.value == noteTxt) { this.value = ''; }
		}
	}
}

addLoadEvent(collect.init);

// article ratings

ratings = {
	toggle: function() {
	if(typeof($('article_ratings_toggle')) != 'object'){ return false;}
	else {
		$('article_ratings_toggle').onclick = function() {
			Element.toggle('article_ratings_table');
			switch($('article_ratings_table').style.display) {
				case "":
				Element.update('article_ratings_toggle', '(Hide Ratings)');
				break;
				case "none":
				Element.update('article_ratings_toggle', '(See All)');
				}
			}
		}
	}
}

addLoadEvent(ratings.toggle);











// editor's inspiration module

editorInspiration = {
	update: function() {
		if(!$('profile_inspiration')) return false;
		// one pic
		//Element.update('profile_inspiration', "<div id='profile_inspiration_inner' class='one'><h1>Welcome to the Community Table</h1><p>We've added more ways for you to enjoy our site and interact with members. Now you can save, rate, and comment on recipes, articles, Good Things, and more. Take a tour of our new features and learn how to use them.<p><ul><li><a href='http://www.marthastewart.com/yourplace'><img src='http://images.marthastewart.com/images/content/pub/blueprint/2006/inside_job_s.jpg' alt='' /></a><br /><a href='http://www.marthastewart.com/yourplace'>Take the Tour</a></li></ul></div>");
		Element.update('profile_inspiration', "<div id='profile_inspiration_inner' class='one'><h1>Welcome to the Community Table</h1><p>We've added more ways for you to enjoy our site and interact with members. Now you can save, rate, and comment on recipes, articles, Good Things, and more. Take a tour of our new features and learn how to use them.<p><ul><li><a href='http://www.marthastewart.com/yourplace'><img src='http://images.marthastewart.com/images/content/pub/blueprint/2006/inside_job_s.jpg' alt='' /></a><br /><a href='http://www.marthastewart.com/yourplace'>Take the Tour</a></li></ul></div>");
		// two pics
		//Element.update('profile_inspiration', "<div id='profile_inspiration_inner' class='two'><h1>They're full of Inspiration...</h1><p>Find out what other contributors are into and up to by visiting their portfolios.</p><ul><li><a href='TEST'><img src='images/assets/temp/darcy65.jpg' alt='' /></a><br /><a href='TEST'>jasontheplay<br />ahammons</a></li><li><a href='http://www.marthastewart.com/yourplace'><img src='images/assets/temp/darcy65.jpg' alt='' /></a><br /><a href='http://www.marthastewart.com/yourplace'>Editor's Name</a></li></ul></div>");
		// three pics
		//Element.update('profile_inspiration', "<div id='profile_inspiration_inner' class='three'><h1>They're full of Inspiration...</h1><p>Find out what other contributors are into and up to by visiting their portfolios.</p><ul><li><a href='TEST'><img src='images/assets/temp/darcy65.jpg' alt='' /></a><br /><a href='TEST'>jasontheplay<br />ahammons</a></li><li><a href='http://www.marthastewart.com/yourplace'><img src='images/assets/temp/darcy65.jpg' alt='' /></a><br /><a href='TEST'>Editor's Name</a></li><li><a href='http://www.marthastewart.com/yourplace'><img src='images/assets/temp/darcy65.jpg' alt='' /></a><br /><a href=''>Editor's Name</a></li></ul></div>");
//    sIFR.replaceElement("#profile_inspiration h1", named({sFlashSrc: "http://images.marthastewart.com/images/assets/flash/fonts/archer.swf", sColor: "#8C5838", sWmode: "transparent"}));
	}
}

addLoadEvent(editorInspiration.update);

// hint framework
/*hintOpen = "<div class='reg_hint'><div class='reg_message_outer'><div class='reg_message_inner'><div>";
hintClose = "</div></div></div></div>";

bio_question1_hint = "How are you feeling? Happy? Stressed? Excited?";
bio_question2_hint = "Here's Martha's: &ldquo;Family instilled love of home and work-I took it from there!&ldquo;";
bio_question3_hint = "We love this one that a Contributor submitted: &ldquo;It doesn't have to be perfect.&ldquo;";
bio_question4_hint = "Anyone from Ghandi to your granddaughter.";
bio_question5_hint = "When we're looking for experts from the Community Table, we'll know you're one of them.";
bio_question8a_hint = "A little mood-making music for your trip?";
bio_question8b_hint = "Maybe it's the one that always laugh or cry-or both.";
bio_question8c_hint = "There's no &ldquo;right&rdquo; answer.";
bio_question8d_hint = "Soon, you'll also be able to upload that photo.";
bio_question8e_hint = "Do tell...";
bio_question9_hint = "Any room that's not listed above.";
bio_question10_hint = "Soon you will be able to submit your recipes, so others can try them out.";
bio_question11_hint = "Dream big!";
bio_question12_hint = "This is also a perfect spot to leave a personal note for visitors to Your Place.";

keyword_search_hint = "Use commas to seperate keywords";


function fieldHint() {
	var getAllHints = document.getElementsByClassName("hintBubble");
	for(var i=0; i<getAllHints.length; i++) {
		getAllHints[i].onfocus = function() {
			var getId = this.getAttribute("id");
      this.style.backgroundColor = '#EDF7F7';
			$(getId + "-M").innerHTML =  hintOpen + eval(getId + "_hint") + hintClose;
			if(!$(getId).hasClassName("required")) {
				$(getId).onblur = function() {
					$(getId + "-M").innerHTML = "";
					$(getId).style.background = "";
				}
			}
		}	
	}
}

addLoadEvent(fieldHint);*/



function trackEvent(action, contestId)
{
	var events = '';
	var evar22 = '';

	if(action=='upload')
	{
		events = 'event33';
		evar22 = 'upc_'+contestId;
	
	}	
	else if(action=='save_photo')
	{
		events = 'event35';
		evar22 = 'upc_'+contestId+'_Success';
	}
	else if(action=='save_details')
	{
		events = 'event36';
		evar22 = 'upc_'+contestId+'_SuccessWithDetail';
	}

	var s=s_gi(s_account);
	s.linkTrackVars='eVar22,evar28,events';
	s.linkTrackEvents=events;
	s.events=events;
	s.eVar22=evar22;
	s.evar28='registered';
	s.tl(this,'o','Community Event');
	
	return true;
}



 function cf_writeContestInfo(contestId, contestMetadata) 
 {
   if(contestMetadata.contestName) 
   { 
   	var title = document.title; 
   	title = title.replace(contestId, contestMetadata.contestName); 
   	document.title = title; 
   }
   
   if(contestMetadata.contestImgSrc && !(contestMetadata.contestImg)) 
   { 
   	contestMetadata.contestImg = ''; 
   }
   
   for (contestAttr in contestMetadata) 
   { 
   	var attrValue = contestMetadata[contestAttr]; 
   	var dataElements = document.getElementsByClassName('contest_' + contestAttr);
   	dataElements.each(function(element) { Element.update(element,attrValue); }); 
   }
}

// function cfWeddingsRedirect() {
// 	if (window.location.host.indexOf("marthastewartweddings.com") == -1) {
// 		if (document.getElementById("my_weddings_btn")) {
// 			document.getElementById("my_weddings_btn").getElementsByTagName("a")[0].href = "http://tools.marthastewart.com/wedding/UserHome";
// 		}
// 	}
// }
// 
// addLoadEvent(cfWeddingsRedirect);


function shareLink(svc) {
	//alert('sharelink called');
	var u = encodeURIComponent(window.location.href);
	// var t = encodeURIComponent(document.title);
	var t = title;
		t += " on MarthaStewart.com";
	var b;
	
	switch(svc) {
		case "delicious":
			b = "http://delicious.com/save?v=5&noui&jump=close&url="+u+"&title="+t;
			break;
		case "facebook":
			b = "http://www.facebook.com/sharer.php?u="+u;
			break;
		case "digg":
			b = "http://digg.com/remote-submit?phase=2&url=" + u + '&title=' + t;
			break;
		case "google":
			b = "http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+u+"&title="+t;
			break;
		case "kirsty":
			b = "http://www.kirtsy.com/submit.php?url="+u;
			break;
		case "stumbleupon":
			b = "http://www.stumbleupon.com/submit?url="+u+"&title="+t;
			break;
		case "twitter":
			b = "http://twitter.com/home?status="+t+" - "+u;
			break;
		case "yahoo":
			b = "http://buzz.yahoo.com/submit?submitUrl="+u+"&submitHeadline="+t;
	}
	//alert(b);
	var bookmark = window.open(b, "bookmark", "width=600, height=500, menubar=0, toolbar=0");
	return false;
}

addLoadEvent(function() {
	if (document.getElementById('sharables') != null) {
		elems = document.getElementById('sharables').childNodes;
		i = 0;
		while (i< elems.length) {
			if (typeof(elems[i].childNodes) != 'undefined') {
				actualelem = elems[i].childNodes
				j=0;
				while (j<actualelem.length) {
				
					if (typeof(actualelem[j]) != 'undefined' && actualelem[j].tagName== 'A') {
						//if (typeof(actualelem[j].onclick) != 'undefined') {
							actualelem[j].onclick = function() {
								myel = this;
								var svc = myel.className;
							//	alert('2');
								shareLink(svc);
								return false;
								
							}
							//alert(actualelem[j].onclick);
						//}
						//alert('attached');
					}
					j++;
				} 
			
				
			}
			i++;
		}
	}
});

/*
var svc = $j(this).attr("class");
shareLink(svc);
var passedaction = 'share_'+$j(this).attr('class');
doTrackAction(passedaction);
*/



function write_fb_button() {
		$('fbuserbox').update($('fbuserbox').innerHTML + '<fb:login-button length="long" onlogin="update_user_box();"></fb:login-button>');
}


 function updateCommunityToolsParams()
{
	var slideNavText = $$("li.current_slide .slide_nav span")[0].innerHTML;
	var sArray = slideNavText.split(" of ");
	var slideNo = sArray[0]; 
	var h2 = document.getElementById("slide_title_"+slideNo);
	itemUrl = h2.attributes.getNamedItem("rel").value; 
	//itemUrl = location.href.split('#')[0]+'?';
	
	var li = document.getElementById("display_slide_1");
	contentId = li.attributes.getNamedItem("rel").value;
	
	var img = li.getElementsByTagName('img');
	thumbnail = img[0].attributes.getNamedItem("src").value;
	thumbnail = thumbnail.replace("_xl","_s"); 
	
	
	thumbnail = $$('#display_slide_1 a img')[0].src;
	thumbnail = thumbnail.replace('_xl.jpg', '_s.jpg');
	
	
	
	if(contentType =="MSLO-PHOTOGALLERY")
	{
		var children = h2.getElementsByTagName('a');
//		title = children[0].innerHTML;
		title = $$('#display_slide_1 .slide_info h1')[0].innerHTML;
		itemUrl = location.protocol+"//"+location.host+itemUrl;
		itemUrl = location.href.split('#')[0]+'?';
		thumbnail = $$('#display_slide_1 .view_image')[0].href;
		thumbnail = thumbnail.replace('_xl.jpg', '_s.jpg');
		itemUrl = itemUrl.replace('&rsc=cf_link', '').replace('??', '?');
	}
	else
	{
		title = h2.innerHTML;
		contentType = 'MSLO-MENU';
		
		
		
		contentType = 'MSLO-MENU'; 
		itemUrl = h2.attributes.getNamedItem("rel").value;
		itemUrl = location.protocol+"//"+location.host+itemUrl;   
		var li = document.getElementById("display_slide_"+slideNo);
		contentId = li.attributes.rel.value; 
		//var img = li.getElementsByTagName('img');
		
		thumbnail = $$('#display_slide_'+slideNo+' a')[0].href
		thumbnail = thumbnail.replace('_xl.jpg', '_s.jpg');
		
		//thumbnail = img[0].attributes.getNamedItem("src").value; 
		title = h2.innerHTML; 

		
	}
	shortTitle = title;
	shortDescription = document.getElementById("slide_shrt_desc_"+slideNo).innerHTML;
	origin = "";
	
	
}
