 jQuery(document).ready(function() {

	//button
	$("button, input:submit, input:reset, a", ".button").button();
	//end
	
	//image
	$("#home").click(function()
	{
		$("#sendSms").slideUp("slow");
		$("#readNews").slideUp("slow");
		$("#formSubscribe").slideDown("slow");
	});
	
	$("#sms").click(function()
	{
		$("#formSubscribe").slideUp("slow");
		$("#readNews").slideUp("slow");
		$("#sendSms").slideDown("slow");	
	});

	$("#news").click(function()
	{
		$("#formSubscribe").slideUp("slow");
		$("#sendSms").slideUp("slow");
		$("#readNews").slideDown("slow");	
	});	
	//end
	
	//input fields
	
		$("#text").keyup(function()
		{
			var box=$(this).val();
			var main = box.length * 100;
			var value= (main / 420);
			var count= 420 - box.length;

		if(box.length <= 420)
		{
			$('#count').html(count);
			$('#bar').animate(
			{
			"width": value + '%',
			}, 1);
			
			if(box.length <= 139)
			{
				$("#count").html("1-3");
			}			
			
			if(box.length >= 141)
			{
				$("#count").html("2-3");
			}
			
			if(box.length >= 281)
			{
				$("#count").html("3-3");
			}		
		}
		else if(box.length >= 421)
		{
			$("#count").html("- FULL -");
			$("#text").val($("#text").val().substr(0, 420));
		}
			return false;
		});	
	
/* 	$("#name").focus(function()
	{
		if($(this).attr("value") == "" || $(this).attr("value")	==	'Required')
		{
			$(this).val("");
		}		
		$(this).css("color", "GRAY");
	});
	
	$("#name").blur(function()
	{
		if($(this).attr("value") == "")
		{
			$(this).val("Required");
		}
	});	
	
	$("#mobile").focus(function()
	{
		if($(this).attr("value") == "" || $(this).attr("value")	==	'Required')
		{
			$(this).val("");
		}
		$(this).css("color", "GRAY");
	});
	
	$("#mobile").blur(function()
	{
		if($(this).attr("value") == "")
		{
			$(this).val("Required");
		}
	});		

	$("#text").focus(function()
	{
		if($(this).attr("value") == "" || $(this).attr("value")	==	'Required')
		{
			$(this).val("");
		}
		$(this).css("color", "GRAY");
	});	
	
	$("#text").blur(function()
	{
		if($(this).attr("value") == "")
		{
			$(this).val("Required");
		}
	}); */		
	//end
	
	$("#img_read_info").click(function()
	{
		var text	=	"<p><b>History:</b> SmsAruba has been around since the 29th of May, 2006.<br />It has been great! In average we had over 5.000 faithfull members. The Last update that I made was in 2007 (minor updates)</p>";
		text 		+= "<p><b>Reason:</b> The reason that SmsAruba is underconstruction is that we want to make something different, something new! There are gonna be tons of new features and the great thing about is that it's free.</p>";
		text		+=	"<p><b>Email:</b> If you want to be the first one's to know the minute that SmsAruba goes live. Please subscribe.</p>";
		text		+=  "<p>If you decide for yes. Awesome! otherwise you'll hear about us.</p>";
	
		$("#read_info").slideDown("slow").html(text);
	});
	//end
	
	//btn
		$("#btn_submit").click(function()
		{
			var email	=	$("#email").val();
		
			$.ajax({
				type: 	'POST',
				url:	base_url + "/ajax/subscribe",
				data: {"email": email},
				beforeSend: function() { $('#wait').fadeIn("fast"); },
				success:
					function(responseData)
					{
						$("#wait").fadeOut("fast");
						$("#error").fadeOut("fast");
						$("#formSubscribe").fadeOut("fast");
						$("#notifications").fadeIn("fast");
						$("#success").fadeIn("slow").html(responseData);
					},
				error:
					function(xhr, ajaxOptions, thrownError)
					{
						$("#wait").fadeOut("fast");
						$("#notifications").fadeIn("fast");
						$("#error").fadeIn("slow").html(xhr.responseText);
					}
				});
		});
		
		$("#btn_submit_sms").click(function()
		{
			var name	=	$("#name").val();
			var mobile	=	$("#mobile").val();
			var text	=	$("#text").val();
		
			$.ajax({
				type: 	'POST',
				url:	base_url + "/ajax/sendsms",
				data: {"name": name, "mobile": mobile, "text": text},
				beforeSend: function() { $('#wait').fadeIn("fast"); },
				success:
					function(responseData)
					{
						$("#wait").fadeOut("fast");
						$("#error").fadeOut("fast");
						$("#success").fadeIn("slow").html(responseData);
						autoHide("#success");
					},
				error:
					function(xhr, ajaxOptions, thrownError)
					{
						$("#wait").fadeOut("fast");
						$("#notifications").fadeIn("fast");
						$("#error").fadeIn("slow").html(xhr.responseText);
					}
				});
		});		
	//end
	
	//functions
	function autoHide(divName)
	{
		setTimeout(function() {
		    $(divName).fadeOut("slow");
			$(divName).html("");
		}, 10000);
		
	}	
	//end
	
});

