$(document).ready(function(){
	
	var clip = null;						   
	var url = $('#URLCreate').val();
	
	$("#userAccount").click(function () {
      $("#box-login").slideToggle("fast");
    });
	
	$('#btoTwit').click(function(){
		$('#twitte-this').toggle('slide');
		$('#txt-twitte-this').focus();
	});
	
	$('#goToTwit').click(function(){
		if ( $('#txt-twitte-this').val().length > 1 ) {
			var texto = $('#txt-twitte-this').val();
			
			texto = texto.replace('#','');
			
			window.location = 'http://twitter.com/home?status='+unescape(texto);
			//window.open('http://twitter.com/home?status='+$('#txt-twitte-this').val(),'win_twt');
		}else {
			alert('insira seu texto');
			$('#txt-twitte-this').focus();
		}
	});
	try
		{
			$('#counter').text(140-$('#txt-twitte-this').val().length );
			
			clip = new ZeroClipboard.Client();
			clip.setHandCursor( true );
			
			clip.addEventListener('mouseOver', function (client) {
				// update the text on mouse over
				clip.setText( url );
			}); 
			
			clip.addEventListener('complete', function (client, text) {
				debugstr( text );
			});
			
			clip.glue( 'btoCopy' );
			clip.setText( url );
	}
		catch(err)
		 {
			//alert(err.description);
		  }
});

function debugstr(url_msg) {
	var divSucessHtml = '<div id="sucessCopy">Link copiado para o clipboard: '+url_msg+'</div>'
	
	$('body').prepend(divSucessHtml);
	$('#sucessCopy').slideUp(10000).delay(100).fadeIn(1500);
	$('#sucessCopy').slideUp(400).delay(3000).fadeOut(14550)
	
	
}
function countTxt(){
	$('#counter').text(140 - $('#txt-twitte-this').val().length );
	if ( $('#counter').text() >= 10 && $('#counter').text() <= 20 ){
		$('#counter').css('color','#FF6600');
	}else if ( $('#counter').text() <= 9 ){
		$('#counter').css('color','#F00');
	}else {
		$('#counter').css('color','#000');
	}
}
function validaFrm(){
	if ( $('#URL').val() == "" ) {
		alert('insira uma URL valida para prosseguir.');
		$('#URL').focus();
		return false;
	}
}

