var currentURL = location.href;
var anchorPosition = currentURL.indexOf('#');
var encodedCurrentURL;
if (anchorPosition == -1) {
    encodedCurrentURL = encodeURIComponent(currentURL);
} else {
    encodedCurrentURL = encodeURIComponent(currentURL.substring(0, anchorPosition));
}

// value is being get from META tag
var sharedTitle;
// value is being get from META tag
var sharedDescription;
function shared_links_init() {
    if (typeof sharedTitle == "undefined" || typeof sharedDescription == "undefined") {
        // value is being get from META tag
        sharedTitle = encodeURIComponent($("meta[name='title']").attr("content"));
        if (sharedTitle == "undefined"){
        	sharedTitle = encodeURIComponent(document.title);
        }
        // value is being get from META tag
        sharedDescription = encodeURIComponent($("meta[name='description']").attr("content"));        
    }
}

/*
 Facebook: Message on the wall of the profile page with:
 Title
 = (value it's getting from meta tag "title") Rejta.se
 Image, user has possibility to choose picture from Page
 = <img> with attribute "src" linked to .jpg or .gif file
 Link to site,
 = link to toplist which user comes from
 Some invitation description
 = (value it's getting from meta tag "description") Sveriges st&ouml;rsta sajt f&ouml;r omd&ouml;men

 */
function fbs_click() {
    shared_links_init();
    var link = 'http://www.facebook.com/sharer.php?u=' + encodedCurrentURL;
    var fbSuffix = encodeURIComponent("fblink");
    if (link.indexOf(fbSuffix, link.length - fbSuffix.length) == -1) {
        var slash = encodeURIComponent("/");
        if (link.indexOf(slash, link.length - slash.length) == -1) {
            link += slash;
        }
        link += fbSuffix;
    }

    link += '&t=' + sharedTitle;

    window.open(link, 'facebooksharer');
    return false;
}

/*
 Twitter :Some text about what user doing
 Link
 = link to toplist which user comes from
 Some description
 = (value it's getting from meta tag "description") Sveriges st&ouml;rsta sajt f&ouml;r omd&ouml;men
 */
function ts_click() {
    shared_links_init();    
    var link = 'http://twitter.com/home?status=' + encodedCurrentURL;            
    window.open(link, 'twittersharer');
    return false;
}
