﻿// Please steal this from wireclub and don't include horribly slow and bloated remote scripts like sharethis
Networker.Share = {
    shareBoxHtml: function(url, description, cols) {
        return "<a target='_blank' title = '1' href=\"http://www.facebook.com/sharer.php?u=" + url + "&t=" + description + "\"><span class='Icon1'>Facebook</span></a>" + (1 % cols == 0 ? "<br />" : "") +
            "<a target='_blank' title = '2' href=\"http://www.myspace.com/Modules/PostTo/Pages/?u=" + url + "&t=" + description + "\"><span class='Icon2'>MySpace</span></a>" + (2 % cols == 0 ? "<br />" : "") +
            "<a target='_blank' title = '3' href=\"http://www.bebo.com/c/share?Page=c/share&Url=" + url + "&Title=" + description + "&popup=0\"><span class='Icon3'>Bebo</span></a>" + (3 % cols == 0 ? "<br />" : "") +
            "<a target='_blank' title = '4' href=\"http://twitter.com/home?status=" + description + "+" + url + "\"><span class='Icon4'>Twitter</span></a>" + (4 % cols == 0 ? "<br />" : "") +
            "<a target='_blank' title = '5' href=\"http://www.stumbleupon.com/submit.php?url=" + url + "&title=" + description + "\"><span class='Icon5'>StumbleUpon</span></a>" + (5 % cols == 0 ? "<br />" : "") +
            "<a target='_blank' title = '6' href=\"http://del.icio.us/post?url=" + url + "&title=" + description + "\"><span class='Icon6'>del.icio.us</span></a>" + (6 % cols == 0 ? "<br />" : "");
    }
};
$(document).ready(function() {
    $("a.ShareLink[href='#']").attr("href", window.location);
    $("a.ShareLink").click(function() {
        $(".ShareBox").remove();
        var isSelected = $(this).hasClass("Selected");
        $(".ShareLink").removeClass("Selected");
        if (!isSelected) {
            var url = encodeURIComponent(this.href);
            var description = encodeURIComponent($(this).attr("description"));
            var shareBox = $("<div class='ShareBox'><div>Share a link to this on:</div>" + Networker.Share.shareBoxHtml(url, description, 2) + "</div>");
            shareBox.find("a").click(function() {
                $(".ShareBox").remove();
                $(".ShareLink").removeClass("Selected");
                $.get("/Management/Gateway.ashx?SharedLink=" + this.title);
                return true;
            });

            shareBox.css("top", $(this).offset().top + $(this).height());
            shareBox.css("left", $(this).offset().left);
            $(this).before(shareBox);
            $(this).addClass("Selected");
        }

        return false;
    });
});