
/* TheBostonChannel.com scripts */
// Begin national js scripts


/* *******************************************************************************
  Copyright 2007, Internet Broadcasting Systems. All Rights Reserved.
  $Id: tools.js,v 1.12 2008/03/20 21:40:23 jlillibridge Exp $
  $Source: /u01/cvsroot/storytools/tools/tools.js,v $
  Phaedra Content ID: 13260191
  Example URL: http://dev.clickondetroit.com/storytoolstest/13253058/detail.html
******************************************************************************** */

var st = {
	init:function() {
		if (!document.getElementById("toolbox")) {
			var tools = new Array();
			tools.push({label:"newsvine",align:"left",target:"_blank",type:"dynamic"});
			tools.push({label:"delicious",align:"left",target:"_blank",type:"dynamic"});
			tools.push({label:"digg",align:"left",target:"_blank",type:"dynamic"});
			tools.push({label:"facebook",align:"left",target:"_blank",type:"dynamic"});
			tools.push({label:"reddit",align:"left",target:"_blank",type:"dynamic"});
			tools.push({label:"rss",align:"right",target:"_blank",type:"static"});
			tools.push({label:"print",align:"right",target:"_self",type:"dynamic"});
			tools.push({label:"email",align:"right",target:"_self",type:"dynamic"});
			st.displayTools(st.createTools(tools));
		}
	},
	createTools:function(tools) {
		var toolbox = document.createElement("div");
		toolbox.id = "toolbox";
		for (var tool = 0; tool < tools.length; tool++) {
			toolbox.appendChild(st.createTool(tools[tool]));
		}
		return toolbox;
	},
	createTool:function(tool) {
		var shortTitle = document.title.split(' - ')[0];
		var image = document.createElement("img");
		var share = document.createElement("a");
		image.src = "/sh/storytools/storytools_" + tool.label + ".gif";
		image.align = tool.align;
		image.title = tool.label.toUpperCase();
		if (tool.type == "dynamic") {
			image.title += ": " + shortTitle;
		}
		image.id = 'st' + tool.label + 'Icon';
		image.border = 0;
		share.href = st.getAction(tool.label);
		share.target = tool.target;
		image.className = "storytool";
		share.appendChild(image);
		return share;
	},
	displayTools:function(toolbox) {
		stel = document.getElementById("storytools");
		stel.appendChild(toolbox);
		if (siteinfo.owner != 'nbcoo') {
			try{st.resizeTools()} catch(e) {}
			if (isNN && siteinfo.owner == 'ibs' ) {
				stel.style.display = 'block';
				stel.style.height = '16px';
			}				
			YAHOO.util.Event.onDOMReady(st.resizeTools);
			YAHOO.util.Event.addListener(window, "load", st.resizeTools);
			YAHOO.util.Event.addListener(window, "resize", st.resizeTools);
			//addEvent(window, "load", st.resizeTools);
			//addEvent(window, "resize", st.resizeTools);		
		}
	},
	resizeTools:function() {		
		var sidebarwidth;
var storywidth;
		var storyid = document.getElementById("story") || document.getElementById("story" + pageProps.coid);
		var cosmologicalConstant = siteinfo.owner == 'post' ? 100 : 50;
		// Check for associated content and get size, the check for "sideSignup" which can appear in the same position, before resorting to a default.
		// 2008-11-11 nthuening: PTS 165022 - Moved "sideSignup" check to this if-else block to fix issues with "sideSignup" appearing outside of the story container.
		 if (YAHOO.util.Dom.getElementsByClassName("AssocContentTD").length > 0) {
			sidebarwidth = YAHOO.util.Dom.getElementsByClassName("AssocContentTD")[0].offsetWidth + 50;
		} else if (document.getElementById("sideSignup")) {
			sidebarwidth = document.getElementById("sideSignup").offsetWidth + cosmologicalConstant;
		} else if (siteinfo.sitekey.lc == 'life') {
			sidebarwidth = 0;
		} else {	
			sidebarwidth = 290;	// Wild Guess
		}
			/*
			var tds = storyid.getElementsByTagName("td");
			for (var i=0;i<tds.length;i++) {
				if (tds[i].className == "AssocContentTD") {
					sidebarwidth = tds[i].offsetWidth + 80;
				} else {
					sidebarwidth = 290;	// Wild Guess
				}
			}
			*/
		storywidth = storyid.offsetWidth;
		if (siteinfo.storysettings.clearsite == 'true') {
		sidebarwidth = '340';	
		document.getElementById("storytools").style.width =  '480px';                                
		} else{
		document.getElementById("storytools").style.width = storywidth - sidebarwidth + "px";
		}
	},
	getAction:function(label) {
		var shortTitle = document.title.split(' - ')[0];
		if (label == "rss") {
			return "/rss/";
		}
		else if (label == "email") {
			return 'javascript:popUp("http://cf.'+siteinfo.sitename.lc+
				'.'+siteinfo.tld+'/'+siteinfo.sitekey.lc+'/sh/toafriend/index.cfm?page='+
				window.location.href+'","width=450,height=250");';
		}
		else if (label == "print") {
			return "javascript:popUp('/print/"+pageProps.coid+
				"/detail.html','width=460,height=400,scrollbars');";
		}
		else if (label == "delicious") {
			return "http://del.icio.us/post?title="+
				escape(shortTitle)+"&url="+
				window.location.href;
		}
		else if (label == "digg") {
			return "http://digg.com/submit?phase=2&title="+escape(shortTitle)+
				"&url="+window.location.href;
		}
		else if (label == "newsvine") {
			return "http://www.newsvine.com/_tools/seed?popoff=0&u="+window.location.href;
		}
		else if (label == "reddit") {
			return 'http://reddit.com/submit?url='+
				encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(shortTitle);
		}
               else if (label == "facebook") {
			if (siteinfo.owner != 'tele'){
			return "http://www.facebook.com/sharer.php?u="+
				window.location.href+"&t="+shortTitle+"&src=sc&pos=top&from_posted=1";	
			}				
			else{		
			return "http://www.facebook.com/sharer.php?u="+
				window.location.href+"&src=sc&pos=top&from_posted=1";
			}
		}
	}
}

if (window.location.href.indexOf('/print/')==-1) {
	st.init();	
}


// End national_js scripts


