var paste = "Paste your long link here!";

$(document).ready(function() {

	$("#textinput").val(paste);
	$("#textinput").keyup(_onChange);
	$('#textinput').focusin(_onFocusIn);
	$('#textinput').focusout(_onFocusOut);

	if ($("#input_result").val() != "") {
		$("#input_result").select();
		$("#input_result").click(function() {
			window.open("http://" + $("#input_result").val(), "_blank");
		});
		_addTween();
	}

	_addErrorsTween();
});

function _addCopy() {
	clip = new ZeroClipboard.Client();
	ZeroClipboard.setMoviePath('/swf/ZeroClipboard.swf');
	// create client
	var clip = new ZeroClipboard.Client();
	// event
	clip.addEventListener('mousedown', function() {
		clip.setText($("#input_result").val());
	});
	clip.addEventListener('complete', function(client, text) {
		// alert('copied: ' + text);
	});
	// glue it to the button
	clip.glue("copy");
}

function _onChange() {

	var txt = $("#textinput").val();

	if (txt == "")
		return;

	var firstLetter = txt[0];

	var opts = $("#combobox").get(0).options;
	for ( var i = 0; i < opts.length; i++) {
		if (firstLetter == opts[i].text[0]) {
			opts[i].selected = true;
			return;
		}
	}
}

function _onFocusIn() {
	var txt = $("#textinput").val();
	if (txt == paste) {
		$("#textinput").val("");
	}
}

function _onFocusOut() {
	var txt = $("#textinput").val();
	if (txt == "") {
		$("#textinput").val(paste);
	}
}

function _addTween() {
	$('#new').animate({
		top : "+=60px"
	}, 1000, _onCompleteTween);
	$('#new').css("background-color");
}

function _onCompleteTween() {
	$('#new').css("z-index", "1");
	//_addCopy();
}

function _addErrorsTween() {
	$('#errors').animate({
		top : "+=74px"
	}, 1000);
}
