function SVote() {
    var obj = this;

    twttr.events.bind('tweet', function(event) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = window.location.origin + "/svote/vote/?id="+obj.video_id+"&social=tw";
        document.getElementsByTagName("head")[0].appendChild(script);
    });

    VK.Observer.subscribe("widgets.like.liked", function(event) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = window.location.origin + "/svote/vote/?id="+obj.video_id+"&social=vk";
        document.getElementsByTagName("head")[0].appendChild(script);
    });

    FB.Event.subscribe('edge.create',
        function(response) {
            var script = document.createElement("script");
            script.type = "text/javascript";
            script.src = window.location.origin + "/svote/vote/?id="+obj.video_id+"&social=fb";
            document.getElementsByTagName("head")[0].appendChild(script);
        }
    );

    obj.showVoteDiv = function(url,x,y) {
        arr = url.split("/");
        obj.video_id = arr[arr.length-2];

        var div =document.createElement("div");
        div.id = "voteDiv";
        div.style.position = "absolute";
        div.style.top = y + "px";
        div.style.left = x + "px";
        div.innerHTML = '<div class="like_el"><a href="http://twitter.com/share" data-url="'+url+'" class="twitter-share-button">Tweet</a></div>'+
            '<div class="like_el"><div id="vk_like"></div></div>'+
            '<div class="like_el"><div class="fb-like" data-href="'+url+'" data-send="false" data-layout="button_count" data-width="90" data-show-faces="false"></div></div>';
        document.getElementsByTagName("body")[0].appendChild(div);
        twttr.widgets.load();
        VK.Widgets.Like('vk_like',{type: "mini",pageUrl:url});
        FB.XFBML.parse();
    }

    obj.hideVoteDiv = function() {
        document.getElementsByTagName("body")[0].removeChild(document.getElementById("voteDiv"));
    }

    obj.moveVoteDiv = function(x,y) {
        var div = document.getElementById("voteDiv");
        div.style.top = y + "px";
        div.style.left = x + "px";
    }
    
    return obj;
}

sVote = SVote();
