/*
 @filename localtools.js
 @programmer Sothea Nim, info@sotheanim.com
 @date August 2009
 @description This file is used to control share tools or local tools: print, share, and email
*/

var icon_path = 'http://globalmk.concordia.ca/images/icons/';
var icon_dim = ' width="16px" height="16px" ';
var share = false;
var img_style = ' style="margin:0;padding:0;border:0;"';

var request_uri = document.location.href;

var delicio_link = 'http://del.icio.us/post?url='+ request_uri;
var friendfeed_link = 'http://friendfeed.com/share?url='+ request_uri;
var twitter_link = 'http://twitter.com/concordianews';
var fb_link = 'http://www.facebook.com/share.php?u='+ request_uri;
var googlebookmark_link ='http://www.google.com/bookmarks/mark?op=edit&bkmk='+ request_uri;
var linkedin_link = 'http://www.linkedin.com/shareArticle?mini=true&amp;url='+request_uri+'&amp;summary=&amp;source=';
var live_link = 'https://favorites.live.com/quickadd.aspx?marklet=1&amp;mkt=en-us&amp;url='+request_uri+'&amp;top=1';
var myspace_link = 'http://www.myspace.com/Modules/PostTo/Pages/?l=3&u='+request_uri+'&c=%3Cp%3EPowered+by+%3Ca+href%3D%22http%3A%2F%2Fsharethis.com%22%3EShareThis%3C%2Fa%3E%3C%2Fp%3E';
var buzzup_link = 'http://buzz.yahoo.com/buzz?targetUrl='+request_uri+'&amp;src=sharethis';

function localTools(arg, pagetitle)
{
	if( arg === 'print' ) {
		localPrint();
	}
	else if( arg === 'share' ) {
		localShare(arg, pagetitle);
	}
	else if( arg === 'email' ) {
		localEmail();
	}
	else if( arg === 'printLegacy' ) {
		return localPrintLegacy(arg);
	}
	return false;
}

function localPrint()
{
	closeShare();
}
function localPrintLegacy(arg) {
	closeShare();
	return "?print=1";
}

function localShare(arg, pagetitle)
{
	if( share === false ) {
		$('#toolbox').show();
		share = true;
	}
	else if( share === true ) {
		$('#toolbox').hide();
		share = false;
	}
	
	pagetitle = "Concordia University &raquo; " + pagetitle;
	
	icons = '<div class="closeshare"><span><a href="?share=0" onclick="return closePanel()">x</a></a></span></div>';
	
	icons += '<div class="rightcol">';
	icons += '<a title="Google Bookmark" href="'+ googlebookmark_link +'&title='+pagetitle+'" target="_new"><img src="'+icon_path+'google-bookmark.gif"'+icon_dim+img_style+' /> Google Bookmark</a><br />';
	icons += '<a title="LinkedIn" href="'+ linkedin_link +'&title='+pagetitle+'" target="_new"><img src="'+icon_path+'linkedin.gif"'+icon_dim+img_style+'/> LinkedIn</a><br />';
	icons += '<a title="Live!" href="'+ live_link +'&t='+pagetitle+'" target="_new"><img src="'+icon_path+'live.gif"'+icon_dim+img_style+'/> Live!</a><br />';
	icons += '<a title="MySpace" href="'+myspace_link+'&t='+pagetitle+'" target="_new"><img src="'+icon_path+'myspace.gif"'+icon_dim+img_style+'/> MySpace</a><br />';
	icons += '</div>';
	
	icons += '<div class="leftcol">';
	icons += '<a title="Delicious" href="'+ delicio_link +'&amp;title='+pagetitle+'" target="_new" onclick="return closeShare()"><img src="'+icon_path+'delicio.gif"'+icon_dim+img_style+'/> Delicious</a><br />';
	icons += '<a title="Friendfeed" href="'+ friendfeed_link +'&title='+pagetitle+'" target="_new"><img src="'+icon_path+'friendfeed.gif"'+icon_dim+img_style+'/> Friendfeed</a><br />';
	icons += '<a title="Twitter" href="'+ twitter_link +'" target="_new"><img src="'+icon_path+'twitter.gif"'+icon_dim+img_style+'/> Twitter</a><br />';
	icons += '<a title="Facebook" href="'+ fb_link +'&t='+pagetitle+'" target="_new"><img src="'+icon_path+'fb.gif"'+icon_dim+img_style+'/> Facebook</a><br />';
	icons += '<a title="Buzz Up!" href="'+ buzzup_link +'&headline='+pagetitle+'" target="_new"><img src="'+icon_path+'buzz-up.gif"'+icon_dim+img_style+'/> Buzz Up!</a><br />';
	icons += '</div>';
	icons += '<div class="clear">&nbsp;</div>';
		
	$('#toolbox').html(icons);
	
	return false;
}

function localEmail()
{
	closeShare();
}

function closeShare()
{
	share = false;
	$('#toolbox').hide();
}

function closePanel() {
	closeShare();
	return false;
}