(function ($) {

    $(document).ready(function () {

        var footer = $('#share');


        function getPosition() {
            return {
                position: 'absolute',
                top: ($(window).height() + $(window).scrollTop()) - footer.outerHeight(),
                right: 0
            };
        };


        $(window).resize(function () {
            footer.css(getPosition());
        });
        $(window).scroll(function () {
            footer.css(getPosition());
        });


        footer.css(getPosition());

        //toggle social widgets

        var faceBookCount = 0;
        var twitterCount = 0;

        function resetCount() {
            twitterCount = 0;
            faceBookCount = 0;
        }

        $('#triggerFacebook').bind("click", function () {

            if (faceBookCount == 0) {
                resetCount();
                hideWidget();
                $("#facebookWidget").removeClass("hideWidget");
                faceBookCount++;
            } else {
                hideWidget();
                resetCount();
            }
            return false;
        });

        $('#triggerTwitter').bind("click", function () {

            if (twitterCount == 0) {
                resetCount();
                hideWidget();
                $("#twitterWidget").removeClass("hideWidget");
                twitterCount++;
            } else {
                hideWidget();
                resetCount();
            }
            return false;
        });

        function hideWidget() {
            $(".widget").addClass("hideWidget");
        }

    });

})(jQuery);
