// JavaScript Document

// JavaScript Document

var theLineupId = 9205807001;
//var theLineupId = 1586429974;


var ctr = 0;
var ctr2 = 0;
var ctr3 = 0;
var lineupLength = 0;
var newArray = new Array();
var htmlVariable = "";


function onTemplateLoaded(message){
	
	callFlash("addEventListener","contentLoad","onContentLoad");
	callFlash("addEventListener","titleLoad","onTitleLoad");

	callFlash("addEventListener","mediaStart","onMediaStart");
}
 
 
function onContentLoad(){

	callFlash("fetchLineupById",theLineupId);
	
}


function onMediaStart(){

	callFlash("getCurrentTitle");
	
}



function fetchLineupById_Result(theObj){
	
	lineupLength = theObj.videoIds.length;

	for ( var i=0, len=theObj.videoIds.length; i<len; ++i ){
		
		callFlash("fetchTitleById",theObj.videoIds[ctr]);
		ctr++;
		
	}
	var clear_div2 = document.createElement("div");
	clear_div2.innerHTML = "<div style='clear:both;'></div>";
	document.getElementById("brightcove_inner_content").appendChild(clear_div2);
	
}

 
function onTitleLoad(evt){
	
	var id = evt.parameters.title.id;
	var thumbnailURL = evt.parameters.title.videoStillURL;
	var displayName = evt.parameters.title.displayName;
	var shortDescription = evt.parameters.title.shortDescription;
	
	creatediv(id,thumbnailURL,displayName,shortDescription);
	

}
	

function creatediv(id,thumbnailURL,displayName,shortDescription) {
		
	var theURL = "http://www.sullivanmovies.com/video/index.php?videoId=";

	htmlVariable = htmlVariable+"<div id='brightcove_title'><a href='#' onclick='javascript:playTitleNow("+ id +");return false;' ><img src='"+ thumbnailURL +"' class='brightcove_title_img' title='"+ displayName +"' alt='"+ displayName +"' /></a><h3 class='brightcove_title_title'>"+ displayName +"</h3><a href='#' onclick='javascript:playTitleNow("+ id +");return false;' ><ul class='brightcove_title_info'><li>Watch Video!</li></ul></a></div>";
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', id);
	newdiv.setAttribute('class', 'brightcove_title');
	newdiv.innerHTML = htmlVariable;
	
	
	if(ctr2 >= 3){
		ctr2 = 0;
		//var clear_div = document.createElement("div");
		//clear_div.setAttribute('style', 'clear:both');
		//document.getElementById("brightcove_inner_content").appendChild(newdiv);
		//document.getElementById("brightcove_inner_content").appendChild(clear_div);
		htmlVariable = htmlVariable + "<div style='clear:both;'></div>";
		
	}else{
		ctr2++;
		//document.getElementById("brightcove_inner_content").appendChild(newdiv);
	}
	
	ctr3++;
	
	if(ctr3 == lineupLength){
		
		//var clear_div2 = document.createElement("div");
		//clear_div2.innerHTML = "<div style='clear:both;'></div>";
		//document.getElementById("brightcove_inner_content").appendChild(clear_div2);
		htmlVariable = htmlVariable + "<div style='clear:both;'></div>";
		document.getElementById("brightcove_inner_content").innerHTML = htmlVariable;
		//document.write('<!--'+htmlVariable+'-->');
	}
	
	
	
	
	//document.getElementById("brightcove_inner_content").appendChild(newdiv);
 	
}
  

function playTitleNow(theLineupId){
	
	callFlash("loadTitleById",theLineupId);

}


function onLoadStart(){
	
	callFlash("getCurrentTitle");
	
}


function getCurrentTitle_Result(theTitleInfo){
	
	if(theTitleInfo.id != undefined){
		
		newArray[0] = theTitleInfo.id;
		newArray[1] = theTitleInfo.displayName;
		newArray[2] = theTitleInfo.shortDescription;
		newArray[3] = theTitleInfo.videoStillURL;

		/*document.write("<meta name=\"title\" content=\""+ theTitleInfo.displayName +"\" />");
		document.write("<meta name=\"description\" content=\""+ theTitleInfo.shortDescription +"\" />");
		document.write("<link rel=\"image_src\" href=\""+ theTitleInfo.thumbnailURL +"\" />");
		*/
		
//		document.getElementsByTagName("meta")["title"].content = theTitleInfo.displayName;

		var metaDesription = document.createElement('meta');
		metaDesription.setAttribute('name', 'description');
		metaDesription.setAttribute('content', theTitleInfo.shortDescription);
		document.all.head.appendChild(metaDesription);
		
		
		//document.getElementsByTagName("meta")[1].content = newArray[2];
		//document.getElementsByTagName("meta")[2].content = newArray[3];
		//document.title = "Sullivan Entertainment ~ "+ newArray[1];
		
	}else{
		return false;	
	}
	
}





