var isFlashAppComplete = 0;

function flash_app_complete( InFlashObjectId, InChatSessionId ){
        isFlashAppComplete = 1;        
        updateChatSessionIdExtInt( InFlashObjectId, InChatSessionId );
}

function openVideoChat( InFlashObject ){
    try{InFlashObject.openVideoChatFromExtInt();}catch(e){if(window.console) console.log(e.message); }
}

function closeVideoChat( InFlashObject ){
    try{InFlashObject.closeVideoChatFromExtInt();}catch(e){if(window.console) console.log(e.message); }
}

function openVideoChatWSound( InFlashObject ){
    try{InFlashObject.openSoundChatFromExtInt();}catch(e){if(window.console) console.log(e.message); }
}

function closeVideoChatWSound( InFlashObject ){
    try{InFlashObject.closeSoundChatFromExtInt();}catch(e){if(window.console) console.log(e.message); }
}

function recieveVideoChatRequest( InFlashObjectId, InJabberId ){
    DMC.maximizeChat( InJabberId );
    DMC.maximizeVideoChat( InJabberId );
}

function receiveSoundChatRequest( InFlashObjectId, InJabberId){
    DMC.maximizeChat( InJabberId );
    DMC.maximizeVideoChat( InJabberId );
}

function updateChatSessionIdExtInt( InFlashObjectId, InChatSessionId ){

	if( isFlashAppComplete ){
		var flash_object = document.getElementById( InFlashObjectId );
		try{
			//console.log("updateChatSessionIdExtInt");
			flash_object.updateChatSessionIdExtInt( InChatSessionId );
		}catch(e){}
	}
}

function initializeVideoChat( InFlashObjectId, InChatSessionId, InJabberId ){
    
    var swfVersionStr = "10.0.0";
    var xiSwfUrlStr = "playerProductInstall.swf";
    var flashvars = {};
    flashvars.sid = 10;
    flashvars.flashObjectId = InFlashObjectId;
    flashvars.chatSessionId = InChatSessionId;
    flashvars.jabberId = InJabberId;
    var params = {};
    params.quality = "high";
    params.bgcolor = "#ffffff";
    params.allowscriptaccess = "always";
    params.allowfullscreen = "true";
    var attributes = {};
    attributes.old_height = "210";
    attributes.id = InFlashObjectId;
    attributes.name = InFlashObjectId;
    attributes.width = "380";
    attributes.align = "middle";

	if(!window.swfobject){
		if(window.console) console.log('swfobject is not defined')
		return;
	}

    swfobject.embedSWF(
    "/videochat/bin-debug/SingleVs.swf", InFlashObjectId,
    "380", ((!$.support.objectAll)?"1":'0'),
    swfVersionStr, xiSwfUrlStr,
    flashvars, params, attributes);
    swfobject.createCSS("#" + InFlashObjectId, "display:block;text-align:left;");
}