// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


$(document).ready( function() {
	
	
	$("a.coupon_code").each(function() {
		$(this).click(
			function() {				
				ZeroClipboard.setMoviePath( '/javascripts/ZeroClipboard.swf' );
				
				//Create a new clipboard client
			    var clip = new ZeroClipboard.Client();
				clip.setHandCursor( true );

				clip.glue(this);
	         
	            //Grab the text from the parent row of the icon
				var anchor = $(this).parent().find(".coupon_code");
				var url = anchor.attr('href');
				var container = $(this).parent().parent().find(".code_container");
				var txt = $.trim(anchor.text());
	            
				clip.setText($(this).text());
				
				//Add a complete event to let the user know the text was copied
	            clip.addEventListener('complete', function(client, text) {
	            	//clip.setText(text);
	                //alert("Copied text to clipboard:\n" + text);	
					window.location.href = url; 
				});
				
				return false;
			}
		);
		$(this).hover(
			function(){				
				$(this).parent().find(".code_hint").show();
			},	
			function(){				
				$(this).parent().find(".code_hint").hide();
			});
	});
	
	$("a.yes_work_link").each(function() {
		 $(this).click(function(){	
			$.ajax({url: '/coupons/is_work',
				data: "id="+$(this).attr('rel')+'&work_bit=1',
				dataType: "json",
				success: function(data) {
					//if(data.response.message == "success")
					//	$("#lead_id").val(data.response.lead_id);
					// 
				}
			});		
			$(this).parent().html('Thank you! Your help is much appreciated.');
		});

	});
	$("a.no_work_link").each(function() {
		$(this).click(function(){
			$.ajax({url: '/coupons/is_work',
				data: "id="+$(this).attr('rel')+'&work_bit=0',
				dataType: "json",
				success: function(data) {
					//if(data.response.message == "success")
					//	$("#lead_id").val(data.response.lead_id);
				}
			});
			$(this).parent().html('Thank you! Your help is much appreciated.');
		});
	});			
});

