function copyToClipboard(t) {
	if(typeof(t) == 'undefined') {
		return;
	} else if (window.clipboardData) {
		window.clipboardData.setData('Text',t);
	} else {
		var el = $('#flashcopier');
		if (el.length == 0) {
			$('body').append('<div id="flashcopier">test</div>');
			el = $('#flashcopier');
		}
		
		el.html('');
		//el.html('<embed src="/copy.swf" FlashVars="clipboard='+encodeURIComponent(t)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>');
		alert('The coupon code has been copied to your clipboard\nTip: You can press CTRL+V on your keyboard to paste it.');
	}
	
	return false;
}

function bindCopyLinks() {
	// create Flash widgets and overlay on top of HTML elements
	$('.btnClipboard').css('display','block');
	$('.couponGeneric, .couponFeatured').each(function() {
		coupon_id = $(this).attr('id').replace('c','');
		// get coupon code for Flash widget
		if($(this).find('.copyCode').length > 0) {
			code = encodeURI($(this).find('.copyCode').text());
		}
		$(this).find('.copyCode, .btnClipboard').each(function() {
			if($(this).hasClass('btnClipboard')) { /* <embed src="/CopyToClipboard.swf?coupon_code=' + code + '" class="CopyToClipboardEmbed" quality="high" scale="exactfit" wmode="transparent" width="' + $(this).outerWidth() + '" height="' + $(this).outerHeight() + '" name="CopyToClipboard" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />	*/
				var flashOverlay = $('<embed src="/CopyToClipboard.swf?coupon_code=' + code + '" class="CopyToClipboardEmbed" quality="high" scale="exactfit" wmode="transparent" width="' + $(this).outerWidth() + '" height="' + $(this).outerHeight() + '" name="CopyToClipboard" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />');
				//var flashOverlay = $('<object id="btnClip_' + coupon_id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + $(this).outerWidth() + '" height="' + $(this).outerHeight() + '" class="CopyToClipboard btnClipboardFlash" align="middle">	<param name="allowScriptAccess" value="always" />	<param name="allowFullScreen" value="false" />	<param name="movie" value="/CopyToClipboard.swf?coupon_code=' + code + '" /><param name="quality" value="high" /><param name="scale" value="exactfit" /><param name="wmode" value="transparent" />	</object>');
			} else { /* <embed src="/codefield.swf?w=' + $(this).outerWidth() + '&h=' + $(this).outerHeight() + '&coupon_code=' + code + '" class="CopyToClipboardEmbed" quality="high" scale="exactfit" wmode="transparent" width="' + $(this).outerWidth() + '" height="' + $(this).outerHeight() + '" name="CopyToClipboard" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /> */
				var flashOverlay = $('<embed src="/codefield.swf?w=' + $(this).outerWidth() + '&h=' + $(this).outerHeight() + '&coupon_code=' + code + '" class="CopyToClipboardEmbed" quality="high" scale="exactfit" wmode="transparent" width="' + $(this).outerWidth() + '" height="' + $(this).outerHeight() + '" name="CopyToClipboard" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />');
				//var flashOverlay = $('<object id="copyCode_' + coupon_id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + $(this).outerWidth() + '" height="' + $(this).outerHeight() + '" class="CopyToClipboard copyCodeFlash" align="middle">	<param name="allowScriptAccess" value="always" />	<param name="allowFullScreen" value="false" />	<param name="movie" value="/codefield.swf?w=' + $(this).outerWidth() + '&h=' + $(this).outerHeight() + '&coupon_code=' + code + '" /><param name="quality" value="high" /><param name="scale" value="exactfit" /><param name="wmode" value="transparent" />	</object>');
			}
			var coveredElement = $(this);
			flashOverlay.css({
				position: 'absolute',
				top: $(this).offset().top,
				left: $(this).offset().left,
				width: $(this).outerWidth(),
				height: $(this).outerHeight(),
				zIndex: 10
			});
			flashOverlay.attr('width',$(this).outerWidth()).attr('height',$(this).outerHeight());
			$(document.body).append(flashOverlay);
		});
		$(this).find('.copyCode').each(function() {
			$(this).css('color',$(this).css('background-color'));
		});
	});
}


