var captionLength = 0;
var caption = "";
var tickerIterations = 0;
var currentTickerIteration = 0;

$(document).ready(function()
{
	setInterval ( "cursorAnimation()", 600 );
});

var lines = new Array("WE MAKE AWESOME STUFF","WE STILL LOVE FLASH", "WE ROCK AT WORDPRESS", "WE MAKE MOBILE APPS", "WE MAKE COOL T-SHIRTS", "WE DONATE MONEY TO HELP FIGHT CANCER", "WE LOVE THE BEACH", "WE LOVE TO JAM OUT", "WE CREATE DIGITAL LOVE");
var index = 0;

function testTypingEffect()
{
	type();
}

function type() 
{
	if(index<lines.length)
	{
		caption = lines[index];
		$('span.caption').html(caption.substr(0, captionLength++));
		if(captionLength < caption.length+1)
		{
			setTimeout("type()", 75);
		}
		else
		{
			captionLength = caption.length;
			if(index < lines.length -1)
			{
				setTimeout("erase()", 7000);
			}
			index++;
		}
	}
}

function erase()
{
	$('span.caption').html(caption.substr(0, captionLength--));	
	if(captionLength >= 0)
	{
		setTimeout("erase()", 75);
	}
	
	else
	{
		captionLength = 0;
		caption = "";
		setTimeout("type()", 500);
	}	
}

function cursorAnimation() 
{
  $("span.cursor").animate(
  {
    opacity: 0
  }, "fast", "swing").animate(
  {
    opacity: 1
  }, "fast", "swing");
}



/*
// when the DOM is ready...
var tickerIterations = 0;
var currentTickerIteration = 0;
$(document).ready(function () {
  // load the ticker
	createTicker();

}); 

function createTicker(){
	if (typeof $('#ticker-area').attr('alt') != 'undefined'){
		tickerIterations = $('#ticker-area').attr('alt');
	}
	// put all list elements within #ticker-area into array
	var tickerLIs = $("#ticker-area ul").children();
	tickerItems = new Array();
	tickerLIs.each(function(el) {
		tickerItems.push( jQuery(this).html() );
	});
	i = 0
	rotateTicker();
}

function rotateTicker(){
	if( i == tickerItems.length ){
	  i = 0;
		if( tickerIterations > 0 ){
			console.log( "tickerIterations: " +tickerIterations );
			currentTickerIteration++;
			console.log( "currentTickerIteration: " + currentTickerIteration );
			if( currentTickerIteration >= tickerIterations ){
				console.log( "Done iterating" );
				return false;
			}
		}
	}
  tickerText = tickerItems[i];
	c = 0;
	typetext();
	setTimeout( "rotateTicker()", 7000 );
	i++;
}

var isInTag = false;
function typetext() {	
	var thisChar = tickerText.substr(c, 1);
	if( thisChar == '<' ){ isInTag = true; }
	if( thisChar == '>' ){ isInTag = false; }
	$('#ticker-area').html("&nbsp;" + tickerText.substr(0, c++));
	if(c < tickerText.length+1)
		if( isInTag ){
			typetext();
		}else{
			setTimeout("typetext()", 65);
		}
	else {
		c = 1;
		tickerText = "";
	}	
}
*/
