//  This file contains the global configuration settings for the add this sharing widget tool
//  See http://addthis.com/help/menu-api for more details

//Global configuration
var addthis_config =
{
   username : "mysask",  						//the user account to track usage under
   data_track_clickback : true, 		//enables shared link to be tracked so usage stats can be gathered by addthis
	 ui_cobrand : "mysask.com"				//branding text that is displayed in the share menu
}

//Global sharing configuration
var addthis_share = 
{ 
    templates: {
                   twitter: "mysask.com: {{title}} {{url}}"
               }
}

/*
this is the list of services to show for the toolbox link
change this list to alter the service shown on the page when the toolbox is rendered
(other services will still be available when the widget is hovered or clicked)
see here: http://www.addthis.com/services/list for a full list of valid service codes
*/
toolbox_services = "facebook,delicious,google,twitter,email";


/*
This function renders the toolbox view of the widget (see http://addthis.com/help/menu-api#rendering-js for more details)
The function takes the following parameters:
  1) elementID - the id of an html element that will includes the toolbox markup inside that element.  The element should be a a div marked with a class of "addthis_toolbox"
  2) an object whose members set the configuration for the button, if not given global defaults are used
  3) an object whose members set the sharing configuration for the object, if not given the defaults are used
  4) a comma delimited list of service codes to render in the toolbox, if not given the defaults from "toolbox_services" are used (see above)

 Ex:  <div id="sharing-toolbox" class="addthis_toolbox"></div> 
		 <script>renderShareToolbox("sharing-toolbox",{ui_click : true}, {url : "http://mysask.com", title : "mysask" }, "facebook,google");</script>		

*/
function renderShareWidget(elementID, configurationObject, sharingObject, services)
{
	//check for thie addthis library and return if not present
	if(typeof addthis == 'undefined')
		return;
	
	var element = document.getElementById(elementID);
	if(element)
	{
	
		//use the default services if not provided
		if(typeof(services) == "undefined")
			services = toolbox_services;
		
		//write the basic share menu
		element.innerHTML = "";
		element.innerHTML += " <a class='addthis_button_compact'>Share</a> ";
		element.innerHTML += " <span class='addthis_separator'>|</span> ";
	
		//write the service buttons
		//since the event tracking does not work for the standalone buttons (except email and print)
		//add the tracking function directly
		serviceArray = services.split(",");
		for(var i = 0; i < serviceArray.length; i++)
		{
			x = " <a class='addthis_button_" + serviceArray[i] + "'";
			if('email' != serviceArray[i] && 'print' != serviceArray[i])
				x  += " onClick=\"trackShareClick('" +  serviceArray[i] + "')\" ";
			x += "></a> ";
			element.innerHTML += x;
		}
		
		//add a dummy swfurl,height, and width attribute to fool facebook so it will use the given
		//content paramters instead of screen scrape
		if(!element.attributes['addthis:swfurl'])
		{				
			if(typeof(sharingObject) == "undefined")
			{
				sharingObject = { swfurl : "http://www.mysask.com/portal/images/misc/spacer.gif", height : 1, width: 1};
			}
			else if(!sharingObject.swfurl)
			{
					sharingObject.swfurl = 	"http://www.mysask.com/portal/images/misc/spacer.gif";
					sharingObject.height = 1;
					sharingObject.width = 1;
			}
		}
		
		//call the addthis api to markup the toolbox using link 
		addthis.toolbox(element, configurationObject, sharingObject);
	}
}

//event handler to track sharing clicks in webtrends
function addThisShareHandler(evt) 
{ 
	trackShareClick(evt.data.service);
}

//tracks share clicks in webtrends
function trackShareClick(service)
{
        var webtrendsTag = getWebtrendsObject();
        webtrendsTag.dcsMultiTrack("WT.cg_n","Share","WT.cg_s", service, "WT.mc_id", "Share");
}


//adds an event listener to run when content is shared through the addthis widget
if(typeof addthis != 'undefined')
	addEvent(addthis, 'addthis.menu.share', addThisShareHandler);



