/******************************************************************************
This is a part of the LoopTek LLC Software Code.
Copyright (C) 2006-2007 LoopTek LLC.
All rights reserved
The contents of this file are subject to the LoopTek LLC Software License Agreement Version 1.0 (the "License"); 
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.looptek.com
********************************************************************************/
function CFLASH ( oFlash, oMedia,i_myJSONObject )
{
	
	this.Flash = oFlash;
	this.Media = oMedia;
	this.cbFunction = null;	
	this.PlayerState = null;
	this.SWFObject=null;
		
	
	CFLASH.prototype.Play = FLASH_Play;
	CFLASH.prototype.Stop = FLASH_Stop; 
	CFLASH.prototype.Pause = FLASH_Pause; 
	CFLASH.prototype.CB = FLASH_CB;
	CFLASH.prototype.Exec = FLASH_Exec;



	YAHOO.log(i_myJSONObject);


	this.LayerDIVName=i_myJSONObject["divname"]; // UniplayDivName"];	
	 var t_UniplayDivName=this.LayerDIVName+"CFLASH"; //this.Player;	
	    

	YAHOO.log(t_UniplayDivName);


	this.SWFObject = new SWFObject(oMedia.URL,"single","100%","100%","7");
//	var s1 = new SWFObject("flvplayer.swf","single","100%","100%","7");
	this.SWFObject.addParam("allowfullscreen","false");
	this.SWFObject.addVariable("file",this.Media.URL);
//	s1.addVariable("image","preview.jpg");
//	s1.addVariable("width","100%");
//	s1.addVariable("height","100%");
	this.SWFObject.addVariable("autostart","true");
	this.SWFObject.write(t_UniplayDivName);
	this.LayerDIVName=i_myJSONObject["UniplayDivName"];	
	CFLASH.prototype.Duration = FLASH_Duration;
	CFLASH.prototype.TimeOut = FLASH_TimeOut;			
	CFLASH.prototype.Inital = FLASH_Inital;
	// Inital
	this.Inital(i_myJSONObject);	
	

}

function FLASH_Inital(i_myJSONObject)
{
	////////////////////////////////////////
	// for Duration time
			
		YAHOO.log(t_duration);
	    var t_UniplayDivName=this.LayerDIVName+"CFLASH"; //this.Player;	

		YAHOO.log(t_duration);	    
		var  EventArray = {"action":"event","actiondetail":"PlayStateChange","player":"CFLASH","data":0};		
             EventArray["UniplayDivName"]=t_UniplayDivName;			 
             EventArray["jsondata"]=i_myJSONObject;		
		var t_currentcontent=i_myJSONObject["currentcontent"];	
	    var t_duration=0;
		try
	    {
		    t_duration=i_myJSONObject["jsondata"][t_currentcontent]["parameter"]["duration"];		
		}catch(err)
		{
			t_duration=g_GlobeValue["default"]["duration"];
			//var g_GlobeValue = {"title":"globe","default":{"duration":15000} };
		}	
		YAHOO.log(t_duration);			 	 							
		if (t_duration!=-1)
		{
			this.Duration(EventArray,t_duration);
		}
			
}
function FLASH_TimeOut(i_EventArray)
{
	var myObject = i_EventArray.parseJSON();
	// YAHOO.log(myObject);   
	JS_JSONStringProcess(myObject);
}

function FLASH_Duration(i_EventArray,t_duration)
{
	var t_divname=i_EventArray["jsondata"]["divname"];	
	i_EventArray["TimeIDField"]= t_divname;
	// var timerID=0; 	
	this.EventArray=i_EventArray;
	var t_EventArrayString=i_EventArray.toJSONString();
	var t_CallBackFunction="FLASH_TimeOut('"+t_EventArrayString+"')";	
	var timerID=setTimeout(t_CallBackFunction,t_duration);	
	return timerID;
}


function FLASH_Inital(i_myJSONObject)
{
	////////////////////////////////////////
	// for Duration time
			
		YAHOO.log(t_duration);
	    var t_UniplayDivName=this.LayerDIVName+"CFLASH"; //this.Player;	

		YAHOO.log(t_duration);	    
		var  EventArray = {"action":"event","actiondetail":"PlayStateChange","player":"CFLASH","data":0};		
             EventArray["UniplayDivName"]=t_UniplayDivName;			 
             EventArray["jsondata"]=i_myJSONObject;		
		var t_currentcontent=i_myJSONObject["currentcontent"];	
	    var t_duration=0;
		try
	    {
		    t_duration=i_myJSONObject["jsondata"][t_currentcontent]["parameter"]["duration"];		
		}catch(err)
		{
			t_duration=g_GlobeValue["default"]["duration"];
			//var g_GlobeValue = {"title":"globe","default":{"duration":15000} };
		}	
		YAHOO.log(t_duration);			 	 							
//		this.uniplay_Control.Duration(EventArray,t_duration);
		this.Duration(EventArray,t_duration);
			
}
function FLASH_TimeOut(i_EventArray)
{
	var myObject = i_EventArray.parseJSON();
	// YAHOO.log(myObject);   
	JS_JSONStringProcess(myObject);
}

function FLASH_Duration(i_EventArray,t_duration)
{
	var t_divname=i_EventArray["jsondata"]["divname"];	
	i_EventArray["TimeIDField"]= t_divname;
	// var timerID=0; 	
	this.EventArray=i_EventArray;
	var t_EventArrayString=i_EventArray.toJSONString();
	var t_CallBackFunction="FLASH_TimeOut('"+t_EventArrayString+"')";	
	var timerID=setTimeout(t_CallBackFunction,t_duration);	
	return timerID;
}

function FLASH_CB(obj)
{

	//if(this.cbFunction == null ) return;
	 if(obj.PlayerState == undefined ) return;
	UNI_CB( obj.PlayerState, obj );
	//this.cbFunction(obj);
}
var _flshp;
function FLASH_Play()
{
	
	
	/*
	this.Flash.LoadMovie(0, this.Media.URL);
	this.Flash.Play();
	*/
	/*
	var oUni = oUniPlayer;
			oUni.dsInfoArea('visible');
			
	switch(this.PlayerState) {
		case 'play':
			//this.Pause();
			break;
		case 'pause':
		default:
			//this.Flash.LoadMovie(0, 'c..');
			
			this.Flash.LoadMovie(0, this.Media.url);
			this.Flash.Play();
			this.PlayerState = 'play';
			var oUni = oUniPlayer;
			FLASH_PlayStateChange(oUni, this.PlayerState);

			if (this.Media.Duration > 0)
			{
				clearTimeout(_flshp);
				_flshp = setTimeout(function(){
				FLASH_FSCommand(oUniPlayer, 'mediaEnd', 123);
				}, this.Media.Duration * 1000);
			}
	}
	*/
}

function FLASH_Stop()
{
	this.Flash.Stop();
    this.Flash.LoadMovie(0, "images/dummy.jpg");
	this.PlayerState = 'stop';
	
	var oUni = oUniPlayer;
	FLASH_PlayStateChange(oUni, this.PlayerState);
}

function FLASH_Pause()
{
	if (indx != -1)
	{
		this.Flash.LoadMovie(0, "images/dummy.jpg");
	}
	else
	{
		this.Flash.Stop();
	}
	this.PlayerState = 'pause';
}

//Event
function FLASH_FSCommand(oUni, command, args)
{
	var CFLASH = oUni.CurrPlayer;
	var o = new Object();
var oUni = oUniPlayer;
	switch(command) {
		case 'mediaEnd':

					try
					{
						
						if(this.Media.Duration != undefined) 
						{
							if(this.Media.Duration != 0 && this.Media.Duration != '')
							{
								if (args != 123)
								{
									this.Flash.Stop();
								}
								else
								{
									this.Flash.Stop();
								}
							}
						}
					}
					catch(errr)
					{
					}
					
				

				
		
			o.oUni = oUni;
			o.on = false;
            this.PlayerState = 'end';
			CFLASH.PlayerState = 'end';
			//CFLASH.CB(o);
             FLASH_PlayStateChange(oUni, this.PlayerState);
			break;
		case 'mouseDown':						
			/*if(safeToCall('parent.toggleDMMonClick')) { //commented by christy to fix double click issue
				
				parent.toggleDMMonClick();
				UNI_doClickedMedia();
			}
			flcnt = flcnt + 1;
			clearTimeout(fltmr);
			fltmr = setTimeout('flcnt = 0', 500);
			if (flcnt > 1)
			{
				if(safeToCall('parent.toggleDMMonClick')) 
				{
					UNI_toggleScreenDisplay();
				}
			}
			*/
			UNI_toggleScreenDisplay();
		break;
		case "mouseMove":
			
			/*if(safeToCall('parent.toggleDMMonClick'))
			{
				parent.toggleDMMonClick();
			}*/ //commented to fix DMM bugs
		  break;						
			return;						
	}
}
var fltmr;
var flcnt = 0;
function FLASH_PlayStateChange(oUni, PlayState)
{
	var CFLASH = oUni.CurrPlayer;
	var o = new Object();
	
	switch(PlayState) {
		case 'play' :
			CFLASH.PlayerState = PlayState;
			o.imgFile = '';
			o.on = false;
            o.PlayerState = CFLASH.PlayerState;
			CFLASH.CB(o);
			break;
		case 'end' :
		case 'stop' :
		case 'pause' :
			CFLASH.PlayerState = PlayState;
			o.oUni = oUni;
			o.on = false;
			o.PlayerState = CFLASH.PlayerState;
			CFLASH.CB(o);
	}
}

function FLASH_Exec()
{
	
	if (oUniPlayer.Media.Stretch == false)
	{
		/*var cW = parent.parent.document.body.clientWidth;
		var cH = parent.parent.document.body.clientHeight;
		var wW = window.screen.width;
		var wH = window.screen.height;
		var strtch = false
		if ((wW - cW)/cW < 0.09)
		{
			strtch = true;
		}
		
		if ((wH - cH)/cH < 0.09)
		{
			strtch = true;
		}
	
		if (strtch)
		{
			this.Flash.Scale = 'exactfit';
		}
		else
		{*/
			this.Flash.Scale = 'showall';
		//}
	}
	else
	{
		this.Flash.Scale = 'exactfit';
	}

}


















/*
 * 
 * 123123
 */














