ZeroClipboard.setMoviePath('http://behindthecounter.com/wp-content/plugins/couponscrape/ZeroClipboard.swf');

jQuery(document).ready( function($) {
	
	clip = new ZeroClipboard.Client();
	clip.setHandCursor(true);
	
	$('.coupon .code .link').mouseover( function() {
		
		clip.setText($(this).html());
		
		if(clip.div)
		{
			clip.receiveEvent('mouseout', null);
			clip.reposition(this);
		}
		else
			clip.glue(this);
		
		clip.receiveEvent('mouseover', null);
		
		$(this).parent().find('.linkhelp').show();
	});
	
	clip.addEventListener('mouseOver', function(client, text) {
		var div = client.domElement;
		$(div).parent().find('.linkhelp').show();
	});
	
	clip.addEventListener('mouseOut', function(client, text) {
		div = client.domElement;
		linkhelp = $(div).parent().find('.linkhelp');
		if(linkhelp.html() != 'Copied!')
			linkhelp.hide();
	});
	
	clip.addEventListener('complete', function(client, text) {
		var div = client.domElement;
		div.style.backgroundColor = 'Yellow';
		
		$(div).parent().find('.linkhelp').show().html('Copied!');
		
		window.open($(div).attr('href'), 'coupon');
	});

});