/* Function to copy a selection to clipboard */
function copyText(obj){
	//var copyText = $j("#"+obj).text();
	//$j.clipboard(copyText);
	/* OLD ID-ONLY STUFF
	if (obj.type == "text" || obj.type == "textarea") var oControlRange = obj.createTextRange();
	else{
		var oControlRange = document.body.createTextRange();
		oControlRange.moveToElementText(obj);
	}
	oControlRange.execCommand("copy");
	*/
}
(function () {
	var window = this,
		$ = this.jQuery;

	$.extend({
		threadedEach: function (arr, fn, settings) {
			settings = $.extend({
				wait: 100,
				after: null
			}, settings);

			var i = 0,
				wait = function () {
					setTimeout(function () {
						if ($.isFunction(fn) && i < ((arr.size && arr.size()) || arr.length)) {
							if (arr instanceof $) {
								fn.apply($(arr).eq(i), [i]);
							} else {
								fn.apply(arr[i], [i]);
							}
							i++;
							wait();
						} else if ($.isFunction(settings.after)) {
							settings.after.apply(window);
						}
					}, settings.wait);
				};

			if ($.isArray(arr) || arr instanceof $) {
				wait();
			}

			return arr;
		}
	});

	$.fn.extend({
		threadedEach: function (fn, settings) {
			return $.threadedEach(this, fn, settings);
		}
	});
}());

$j(document).ready(function () {
	$j(".TransLine").threadedEach(function() {

            //Create a new clipboard client for this single line
            var clip = new ZeroClipboard.Client();

            //Cache the last td and the parent row
            var transLineButtonId = $j(this).attr('id');
			var transLineId = transLineButtonId.substring(0, transLineButtonId.length - 6);

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

            //Grab the text from the parent row of the icon
            clip.setText($j('#'+transLineId).text());

            //Add a complete event to let the user know the text was copied
			/*clip.addEventListener('complete', function(client, text) {
				alert(text);
			});*/
        });
});


