var fi = fi || {};
fi.component = fi.component || {};
fi.component.Share = function($context) {
    this.$context = $context;
    this.button = $("ul li", $context);
};
fi.component.Share.prototype = {
    init: function() {
        this.button.bind("mouseenter", $.proxy(this.onButtonOver, this));
        this.button.bind("mouseleave", $.proxy(this.onButtonOut, this));
        this.button.bind("click", $.proxy(this.onButtonClick, this));
    },
    onButtonOver: function(e) {
        var button = $("div", e.currentTarget);
        $(button).addClass("hover");
        this.showButtonLabel(button);
    },
    onButtonOut: function(e) {
        var button = $("div", e.currentTarget);
        $(button).removeClass("hover");
        this.hideButtonLabel(button);
    },
    showButtonLabel: function(button) {
        var label = $(button).next();
        var labelWidth = label.outerWidth();
        $("img", button).stop().animate({
            opacity: 1
        },
        {
            duration: 50,
            easing: "easeOutQuad"
        });
        label.stop().animate({
            marginLeft: -labelWidth
        },
        {
            duration: 150,
            easing: "easeInOutQuad"
        });
        $("span", label).stop().css({
            left: 10
        }).delay(150).animate({
            left: 0,
            opacity: 1
        },
        {
            duration: 100,
            easing: "easeOutQuad"
        });
    },
    hideButtonLabel: function(button) {
        var label = $(button).next();
        $("img", button).stop().delay(200).animate({
            opacity: 0.5
        },
        {
            duration: 150,
            easing: "easeOutQuad"
        });
        label.stop().animate({
            marginLeft: 40
        },
        {
            duration: 150,
            easing: "easeInQuad"
        });
        $("span", label).stop().animate({
            opacity: 0
        },
        {
            duration: 150
        });
    },
    onButtonClick: function(e) {
        var type = $("a div", e.currentTarget).attr("class").split(" ")[0];
        var location = encodeURIComponent(window.location);
        var title = encodeURIComponent(document.title);
        if (type == "buzz") {
            window.open("http://www.google.com/buzz/post?message=" + title + "&amp;url=" + location + "");
        } else if (type == "twitter") {
            window.open("http://twitter.com/share?url=" + location + '&text=' + title + "");
        } else if (type == "fb") {
            window.open('http://www.facebook.com/sharer.php?u=' + location + '&t=' + title, 'sharer', 'toolbar=0,status=0,width=626,height=436');
        } else if (type == "mail") {
            window.open("mailto:?subject=Internet Marketing Inquiry&body=" + location + "");
        }
        return false;
    }
};
fi.common.ComponentLoader.register("share", fi.component.Share);
