$(function() {
    $(".clipboard-link").each(function() {
        
        //Create a new clipboard client
        ZeroClipboard.setMoviePath('/js/clipboard/ZeroClipboard.swf')
        var clip = new ZeroClipboard.Client();
        clip.setHandCursor(true);
        
        //Cache the last td and the parent row    
        var target = $(this);
        target = target[0];

        //Glue the clipboard client to the last td in each row
        clip.glue(target);

        //Grab the text from the parent row of the icon
        var txt = $(this).attr('rel');
        clip.setText(txt);

        //Add a complete event to let the user know the text was copied
        clip.addEventListener('complete', function(client, text) {
            
            // Redirect
            var href = client.domElement.href;
            window.open(href)
        });
    });
    
    // Show "click to copy and open site" text
    $('[id^="ZeroClipboardMovie_"]').each(function() {
        var target = $(this);
        $('<span class="promt-text">click to copy and open site</span>').insertAfter(target);
        target.parents('div:first').hover(function() {
            $(this).find('.promt-text').show();
        }, function() {
            $(this).find('.promt-text').hide()
        });
    });
});

