var newsText = new Array();
newsText[0] = "Leveraging YouTube's API, we built a video portal for AFI to showcase 40+ years of archived material.";
newsText[1] = "Covered by NBC, CBS and Forbes, we helped build and launch LottoGopher.com";
newsText[2] = "We created a customer response system for ConsumerAffairs.com";
newsText[3] = "We are in the process of launching a new portal for the CalArts CAP program";
newsText[4] = "We launched the JobBoard at USC School of Cinematic Arts.";
newsText[5] = "Want a video portal in traditional Chinese?  Yes, we do those too!";
newsText[6] = "Currently in development, this portal will help connect businesses.";

var tghgh,dsdasd;

var mainpos = -1;

function setText(val){//news2
	
	if(!document.getElementById("typing")){
		setText(val);
		return false;
	}
	
	document.getElementById("typing").innerHTML = "";

	txttext = "";
	
	strpos=0;

	clearTimeout(dsdasd);

	dsdasd = setTimeout(function(){ addChar1(newsText[val]);val++;},1800);

	clearTimeout(tghgh);

	tghgh = null;

	if(val == newsText.length)
		val = 0;

	mainpos = val+1;
}

function setText1(val){//news2
	
	if(!document.getElementById("typing")){
		setText(val);
		return false;
	}
	
	if(mainpos == 7){

		document.getElementById('myImageFlow_slideshow').onclick();
		return false;
	}
	
	document.getElementById("typing").innerHTML = "";

	txttext = "";
	
	strpos=0;
	
	setTimeout(function(){ addChar1(newsText[val]);val++;},600);	

	if(val == newsText.length)
		val = 0;

	tghgh = setTimeout(function(){setText1(val);},14000);

	mainpos = val+1;
}

var tspeed = 35;
var txtlength=0;
var txttext='';
var strpos=0;

function addChar1(dwAText) {

	txttext = dwAText;

	txtlength = txttext.length;

	writeCharacter();
}

function writeCharacter(){

	if(strpos <= txtlength){//alert(txttext+' '+txttext.char[strpos]);
		
		var str = document.getElementById("typing").innerHTML;

		document.getElementById("typing").innerHTML = txttext.substring(0,strpos);

		strpos++;
		
		setTimeout(function(){ writeCharacter();},tspeed);

	}else {
		
		strpos = 0;
	}
}

var captionLength = 0;
var caption = "";

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


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

function checkkey(e){

	var keyvalue = e.keyCode;

	//Check Right Arrow Key
	if(keyvalue == 39){
		
		setText(mainpos);
	}

	//Check Left Arrow Key
	if(keyvalue == 37){
		
		if(mainpos-2 < 0)
			mainpos=newsText.length-1;
		else
			mainpos=mainpos-2;

		//document.getElementById('sdsdsdsd').value = keyvalue+" "+mainpos+" "+newsText.length+" "+(mainpos-2)+" sd";
		
		setText(mainpos);
	}
}
