var u=location.href;
var t=document.title;
var d=document.domain;

var encodedURL = encodeURIComponent(u);
var encodedTitle = encodeURIComponent(t);
var encodedDomain = encodeURIComponent(d);

//FACEBOOK - supplied by them
function fbs_click()
{
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

//Digg
function digg_click()
{
    var desc = getDescription();
    window.open('http://digg.com/submit?url=' + encodedURL + '&title=' + encodedTitle + '&bodytext=' + desc + '&media=news&topic=health','digg_share', 'toolbar=0,status=0,menubar=0,resizable=1,scrollbars=1,width=626,height=436');
    return false;
}



//Twitter
function twitter_click()
{
    var desc = getDescription();
    var status = encodedDomain + "+" + encodedTitle + '+' + encodedURL;
    if(status.length > 140)
    {
        status = encodedTitle + "+" + encodedURL;

        if(status.length > 140)
        {
            status = encodedURL;
        }
    }

    //alert('status: ' + status.length + ", " + status);
    window.open('http://twitter.com/home/?status=' + status, 'twitter_share','toolbar=0,status=0,menubar=0,resizable=1,scrollbars=1,width=626,height=436');
    return false;
}

//delicious
function delicious_click()
{
    window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodedURL+'&amp;title='+encodedTitle, 'delicious','toolbar=no,width=550,height=550'); 
    return false;
}

//reddit
function reddit_click()
{
    window.open('http://www.reddit.com/submit?url='+encodedURL, 'reddit');
    return false;
}

//stumbleupon 
function stumbleupon_click()
{
    window.open('http://www.stumbleupon.com/submit?url='+encodedURL + '&title=' + encodedTitle, 'stumbleupon');
    return false;
}

//myspace
function myspace_click()
{
    var desc = getDescription();
    window.open('http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodedTitle + '&c=' + desc + '&u=' + encodedURL + '&l=' + 5, 'myspace','toolbar=0,status=0,menubar=0,resizable=1,scrollbars=1,width=626,height=436');
    return false;
}

//playahead
function playahead_click()
{
    var desc = getDescription();
    window.open('http://www.playahead.se', 'playahead');
    return false;
}

//lunarstorm
function lunarstorm_click()
{
    var desc = getDescription();
    window.open('http://www.lunarstorm.se', 'lunarstorm');
    return false;
}





//COMMON FUNCTIONS
function getDescription()
{
    var metatags;
    if (document.getElementsByTagName)
    {
        metatags = document.getElementsByTagName('meta');
        for (var i = 0; i < metatags.length; i++)
        {
            if (metatags[i].name=='description')
            {
                return metatags[i].content;
            }
        }
    }
    return "";
}
