// JavaScript Document

maxL=140;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
	}
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}

$(document).ready(function() {
	$('textarea[name=message]').val('RT @tweetmakr Turn any message you want into your own custom tweet button! http://tweetmakr.com');
$('.why').live('click', function() {
	$('#pop').animate({marginTop: "25"}, 1000,'easeOutBounce');
	moveBgAround(); 
});



$('#xOut').live('click', function() {
	$('#pop').animate({marginTop: "-550"}, 500,'easeInCirc');
	});
	
function resetBg() {
	$('.scrollBg').animate({backgroundPosition: '0px 0px'}, 0, function() {
		moveBgAround();
	});
}
function moveBgAround() {
$('.scrollBg').animate({backgroundPosition: '0px 1548px'}, 25000, function() {
	resetBg();
});
}


$('.embed').hide();
$('.source1').hide();
$('.yours').hide();
$('.button').css({height: "0", width: "0"});
$('.instruct').hide();
$('.outputRaw').css({height: "0", width: "0"});



function reTweet() {
	var message2 = $('textarea[name=message]');
	var message = $.URLEncode(message2);
		
		$('.button').html('<a target="_blank" href="http://twitter.com/home?status=' + message + '"><img src="http://www.tweetmakr.com/twitter/images/retweet.gif"/></a>');  
		//$('.source').html(message.val());
		$('.source1').html('<a target="_blank" href="http://twitter.com/home?status=' + message + '"><img src="http://www.tweetmakr.com/twitter/images/retweet.gif"/></a>');
		
		//cancel the submit button default behaviours
		return false;
	
}

$('.back').live('click', function() {
		$('.instruct').fadeOut().animate({marginTop: "0"}); 
		$('.button').animate({height: "0", width: "0"}, 75);
		$('.texttocopy').fadeOut();	
		$('.yours').fadeOut();
		$('.source1').fadeOut();
		$('.embed').fadeOut();
		$('textarea[name=message]').val('try again!');
		$('.outputRaw').animate({height: "0", width: "0"}, function() {
			$('#Submit').fadeIn(200,  function () {
				$('#Submit').animate({height: "74", width: "133"}, 50);
				$('#Submit').animate({height: "68", width: "122"}, 200);
				});
			$('.counter').fadeIn();
			$('.text').fadeIn();
			$('.messageEntry').delay(250).animate({height: "125", width: "543"}, 200);
			$('.messageEntry').fadeIn(200, function() {
				var message = $('textarea[name=message]');
		
		});
		//cancel the submit button default behaviours
		
				
		$('.back').fadeOut();
		
			
			
		});	
		
		//$('.block').fadeOut();
		//Get the data from all the fields
	});	

	//if submit button is clicked
	$('#Submit').live('click', function() {
		$('#Submit').animate({height: "74", width: "133"}, 50,  function () {
			$('#Submit').animate({height: "0", width: "0"}, 200);
			$('#Submit').fadeOut(200);
		});
	$('.counter').fadeOut();
			$('.text').fadeOut();
			$('.messageEntry').delay(250).animate({height: "0", width: "0"}, 200);
			$('.messageEntry').fadeOut(200, function() {
	var message2 = $('textarea[name=message]').val();
	var message = encodeURI(message2);
		
		$('.button').html('<a target="_blank" href="http://twitter.com/home?status=' + message + '"><img src="http://www.tweetmakr.com/images/retweet.gif"/></a>');  
		//$('.source').html(message.val());
		$('.source1').text('<a target="_blank" href="http://twitter.com/home?status=' + message + '"><img src="http://www.tweetmakr.com/images/retweet.gif"/></a>');
		$('.outputRaw').animate({height: "104", width: "429"}, function() {
		$('.embed').fadeIn();
		$('.source1').fadeIn();
		$('.yours').fadeIn();
		$('.texttocopy').fadeIn();
		$('.button').animate({height: "37", width: "120"}, 75, function() {
			$('.button').animate({height: "30", width: "113"}, 75);
			});
		$('.instruct').animate({marginTop: "140"}).fadeIn(); 
		});
		//cancel the submit button default behaviours
		
				
		$('.back').fadeIn();
		
			
			
		});	
		
		//$('.block').fadeOut();
		//Get the data from all the fields
	});	
});	

