jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	}
});



$.fn.slideFadeToggle = function(speed, easing, callback) {
        return this.animate({ opacity: 'toggle', height: 'toggle' }, speed, easing, callback);
};

var url; var submit_string; var count; var submitform; var host; var url_string; var url_parsed; var index;

$(function() {
{

	$('#longurl').keyup();
	$(".submit-getinfo").css( {backgroundPosition: "-155px 0"} );
	$(".submit-getinfo").stop();

	host = document.location.hostname;
	
	$(function() {
  $('.submit-getinfo').live('mouseenter', function () {
      $(this).css( {backgroundPosition: "right bottom"} );
	  $(this).stop();
  }).live('mouseleave', function() {
      $(this).css( {backgroundPosition: "right top"} );
	  $(this).stop();
  });

  $('.submit').live('mouseenter', function () {
      $(this).css( {backgroundPosition: "left bottom"} );
	  $(this).stop();
  }).live('mouseleave', function() {
      $(this).css( {backgroundPosition: "left top"} );
	  $(this).stop();
  });
});

$('a.metrics').live('click', function() {

var anchor = $(this).attr('href').split('#');
anchor = anchor[anchor.length-1];
anchor = 'http://nx.ly/' + anchor;

			$("#longurl").val(anchor);
			$('#longurl').keyup();
			$('#submit').submit();
});
	
}});

$('#longurl').bind('keyup keydown keypress', function() { 

url = $("#longurl").val();
index = url.indexOf('nx.ly');

submit_string = $("#submit").val();
count = submit_string.length - 1;

if (index == 0 || index == 7 || url == 'devel') {
submit_string = submit_string.substr(count);
submit_string = 'Get Info ' + submit_string;
if($('#submit').hasClass('submit-getinfo')) {
$("#submit").val(submit_string).addClass("submit-getinfo").removeClass("submit");
//$(".submit-getinfo").stop();
$(".submit-getinfo").css( {backgroundPosition: "-155px 0"} ); // prevent animation buildup
} else {
$("#submit").val(submit_string).addClass("submit-getinfo").removeClass("submit");
$(".submit-getinfo").stop().animate({backgroundPosition:"(-155px 0)"}, {duration:200});

}


} else {
	if  (submit_string != 'Shorten &raquo;') {
		submit_string = submit_string.substr(count);
		submit_string = 'Shorten ' + submit_string;
		$("#submit").val(submit_string).removeClass("submit-getinfo").addClass("submit");
		$(".submit").stop().animate({backgroundPosition:"(0 0)"}, {duration:200})
	}
}

 } );
	
$("#shortener").submit(function(event){
	event.preventDefault();
	$.post("s.php", $("#shortener").serialize(),
	function(result) {
		if (url != 'nx.ly' && index == 0 || index == 7 || url == 'devel') {
		
			$("#stats").html(result);
		
		
			if ($('.largetxt').length != 0) {
			
			  $('#footer').animate(
			  { bottom: 50 },
			  {
			  duration: 'slow',
			  easing: 'easeOutElastic',
			  complete: function () {
				}
				});
				
				$("#stats").fadeIn("slow");
			
			} else {
				$("#notification").html(result).fadeIn("slow");
			}

		} else {
			$("#notification").html(result).fadeIn("slow");
		}
	});
});
