var clip = null;

$(document).ready(function() {

    $("div[id$='divArticleText']").bind('copy', function(e) {
        //copy the selected text into the text area, focus on the text area, and select all the text

        //Save scroll position
        var ScrollTop = document.body.scrollTop;

        if (ScrollTop == 0) {
            if (window.pageYOffset)
                ScrollTop = window.pageYOffset;
            else
                ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
        var selectedText = getSelectedText();
        $("textarea[id$='txtCopyTxt']").val(selectedText + '\n\nRead more from this Tulsa World article at ' + document.location.href);
        $("textarea[id$='txtCopyTxt']").select();
        window.scroll(0, ScrollTop);
    });

});

function getSelectedText() {
    if (window.getSelection) {
        return window.getSelection().toString();
    }
    else if (document.getSelection) {
        return document.getSelection();
    }
    else if (document.selection) {
        return document.selection.createRange().text;
    }
} 