$(document).ready( function() {
	//Front Page Slider
	if ($("#slider").length > 0) {
		$("#slider ul li").each(function(){$(this).animate({opacity: "0.5"}, 0);});
		$("#slider ul li.current").animate({opacity: "1"}, 0);
		var timer = setInterval(function(){
			$("#slider ul li.current").animate({opacity: "0.5"}, 2000);
			$("#slider ul li.current").next("li").animate({opacity: "1"}, 3000);
			$("#slider ul").animate({marginLeft: "-=149"}, 3000, function(){
				$("#slider ul li:first").clone().appendTo($("#slider ul"));
				$("#slider ul li:first").remove();
				$("#slider ul").animate({marginLeft: "+=149"}, 0);
				$("#slider ul li.current").removeClass("current").next("li").addClass("current")
			});
		}, 5000);
	}
	if ($("#editlink").length > 0) {
		$("#editlink").click(function(){
			$("#editplan").toggle();
		});
	}
	if($("#paylink").length > 0) {
		$("#paylink").click(function(){
			$("#editpay").toggle();
		});
	}
	if ($(".editcodelink").length > 0) {
		$(".editcodelink").click(function(){
			$(this).parent('span').hide();
			$("#code-"+$(this).attr("id")).html("<input name='newcode' value='"+$("#code-"+$(this).attr("id")).html()+"' /> <input type='submit' value='save' />");
		});
	}
	if ($("#newcoupon").length > 0) {
		$("#newcoupon").click(function(){
			$("#newcouponform").html("<td>coupon<span class='description'>This will be a one-time-use coupon.</span></td><td><input id='jstitle' /><span class='description'>The name of the coupon. For example, ''Referral Reward''</span></td><td><input id='jsamount' /><span class='description'><strong>Value</strong> of the coupon. This is how much you will refund the customer's credit card once the coupon is redeemed.</span></td><td><input id='jsdescription' /><span class='description'>Enter the <strong>email address</strong> of the recipient and why the coupon was issued.</span></td><td><input id='jscode' /><span class='description'>The code that the customer must enter to redeem their coupon.</span></td><td><input type='submit' value='Create' onclick='sendtheform()' /></td>");
		});
	}
	if ($(".deletebutton").length > 0) {
		$(".deletebutton").click(function(){
			if (!confirm("Are you sure you wish to delete this coupon?")) {
				return false;
			}
		});
	}
	if ($(".redeemededit").length > 0) {
		$(".redeemededit").click(function(){
			$(this).parent('.redeemedreplace').html("<select name='redeemed'><option value='1' selected>Redeemed by Customer</option><option value='0'>NOT Redeemed</option><option value='2'>Credit Applied</option></select><input type='submit' value='Save' />");
		});
	}
});
function sendtheform() {
	$("#title").val($("#jstitle").val());
	$("#amount").val($("#jsamount").val());
	$("#description").val($("#jsdescription").val());
	$("#code").val($("#jscode").val());
	$("#newcouponsubmitter").submit();
}