$(function() {
    $('#mainfeature').after('<div id="slidenav" class="slidenav" style="margin: -62px 0 0 800px; z-index: 6;">').cycle({
        fx: 'fade',
        speed: '1000',
        timeout: 8000,
        pager: '#slidenav',
        before: function() { }
    });
});

$(function() {
	$('.toggler-closed').next('div').addClass('toggler-c-closed').hide();
    $('.toggler-closed').click(function(){
    	if($(this).next('div').hasClass('toggler-c-closed'))
    	{
    		$(this).removeClass('toggler-closed').addClass('toggler-opened').next('div').removeClass('toggler-c-closed').addClass('toggler-c-opened').slideDown('slow');
    	}
    	else
    	{
    		$(this).addClass('toggler-closed').removeClass('toggler-opened').next('div').slideUp('slow', function(){$(this).removeClass('toggler-c-opened').addClass('toggler-c-closed')});
    	}
    });
});

$(function() {
	$('#submit-btn').click(function()
	{
		$(this).attr('disabled', 'disabled');
		$.post('sign-up/post', 
		$("#sign-up-form").serialize(), 
		function(data) {
		console.log(data);
		  	$("#full-name").val('');
		  	$("#email").val('');
		  	$("#password").val('');
		  	$(".thank-you").css('display', 'block').delay(1000).fadeOut('slow');
		  	$("#submit-btn").removeAttr('disabled');
		})
		.error(function() { 
			$(".thank-you").html('Please Try Again.').css('display', 'block').css('color', 'red');
		  	$("#submit-btn").removeAttr('disabled');
		});
		
		return false;
	});
});

$(function() {
	$('#sign-in-box').jqm(
	{
		overlay:75
	});
	$('#sign-in-btn').click(function()
	{
		$(this).attr('disabled', 'disabled');
		$.post('sign-up/sign-in', 
		$("#sign-in-form").serialize(), 
		function(data) {
			if(data == 'true')
			{
				window.location.href = "/print-coupons";
			}
			else
			{
			  	$("#email").val('');
			  	$("#password").val('');
			  	$("#sign-in-btn").removeAttr('disabled');
			  	$(".error").html('Please enter a valid email or password.').css('display', 'block').css('color', 'red');
			  	$("#sign-in-btn").removeAttr('disabled');
		  	}
		})
		.error(function() { 
			$(".error").html('Please Try Again.').css('display', 'block').css('color', 'red');
		  	$("#sign-in-btn").removeAttr('disabled');
		});
		return false;
	});
});
