var res_id;
var tid;
var envid;

function bizcardAPI(title_id)
{
	var apiURL = '/data/bizcardAPI.do?vtid=' + title_id + "&envid=" + envid; 
	var obj=new JSONscriptRequest(apiURL); 
	obj.buildScriptTag(); // Build the script tag      
	obj.addScriptTag(); // Execute (add) the script tag
}

function openBizcard()
{
	ttPauseVideo();
	var bizcardURL = '/data/document.do?fwd=overlaybp&res_id=' + res_id + "&envid=" + envid;
	tbr_show(null,bizcardURL + '&KeepThis=true&TB_iframe=true&height=500&width=600&modal=true',false);		
}

function getCurrentTitle_Result(titleDTO)
{
	tid = titleDTO.id;
	bizcardAPI(tid);
}

function onMediaStart(pEvent)
{
	callFlash("getCurrentTitle");
}

function ttStopVideo() 
{
	callFlash("stopVideo");
}

function ttStartVideo() 
{
	callFlash("startVideo");
}

function ttPauseVideo() 
{
	callFlash("pauseVideo","true");
}

function ttUnPauseVideo() 
{
	callFlash("pauseVideo");
}

function onTemplateLoaded(message) {
	if (typeof message == "undefined") {
 		// template loaded without error
 		callFlash("addEventListener", "mediaStart", "onMediaStart");
	}
}
 
function setValues(data)
{
    var doBC = data.bizcardAPI.doBC;
	if(doBC == true) res_id = data.bizcardAPI.res_id;
	else res_id = '';
	
	if(doBC == true) openBizcard();
}

// JSONscriptRequest -- a simple class for accessing Yahoo! Web Services
// using dynamically generated script tags and JSON

// Constructor -- pass a REST request URL to the constructor
//
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}



