/*
+-----------------------------------------------------------------------+
| SiSTeR Zoomer Javascript Code - players.js    						|
+-----------------------------------------------------------------------+
| Copyright (c) 2003-2005 Silver Screen Tele-Reality, Inc.				|
+-----------------------------------------------------------------------+
| The contents of this source file are the sole property of				|
| Silver Screen Tele-Reality, Inc.										|
| Unauthorized duplication or access is prohibited.						|
+-----------------------------------------------------------------------+
*/
var playername = "flv_player_v8";
var flLeft = -900;
var flTop = 100;
var dragColor = '#ddddff';
var client_type = ((is_ie5up) && (is_win) && (is_WMPMajor >= 9)) ? "WMV" : "FLV"; //autodetect
var ws_url = "&webservice_url=http://ws.pod0.sister.tv/demos/zoomers/autos/sister-zoomer-objects.php?wsdl";
var zoomername = "zoomer";
var nAttempts = 0;
var flash_width = 570;
var flash_height = 400;
var flashSA_width = 245;
var flashSA_height = 245;
var wmvPlayerDOM = null;
var FlashPlayerDOM = null;
var flash_swf_layer = null;
var wmLayer = null;
var flashLayer = null;
var dragHandle = null;
var dragLayer = null;
var dragGalleryLayer=null;
var wm_layer_org_x;
var wm_layer_org_y;
var mediaid = null;
var vm_prefix = 'http://pic2vid.com/p2vcom/wrk/p2vcom-pl.asx';
var au_prefix = '';
var swf_prefix = '/1/Resources/Pic2Vid/Zoomer/';
var mediaItems = Array();
var externalDetailsMode = "window.open";
var bIsStandAlone = false;
var bIsEmbedded = false;
var player_open;
var is_flash = false;
var nMaxAttempts = 12;
var bContinue = true;
var bReturnErrors = false;
var bVCSubmitted = false;
var bInit = false;
var fullsizePlayerDOM=null;
var fullsizegallery_layer=null;
var fullsizegalleryObjId="Pic_flv_player_v8";
var galleryname="fullsize_gallery";
var chkFullsizegallery=false;
var chkPlay=false;
var closeGallery=false;
var soapid;
var dragGalleryColor = '#ffddff';
var needtoDrag;
var bLoadSuccess = false;


function vendorConfig()
{
	this.index = Array();
}

function keypair(k,v)
{
	this.key = k;
	this.value = v;
}

vendorConfig.prototype.push = function(k,v)
{
	this.index.push(new keypair(k,v));	
}

var vendor_config = new vendorConfig();

function DoFSCommand(command, args)
{
	var fargs = fixArgs(args)
	var tmp = command + '(' + fargs + ')';
	
	eval(tmp);	
}
function SoapRedirectError(MediaID)
{
	msgSOAPFAULT = new MessageWindow("Zoomer Unavailable","Click 'ok' to be forwarded to the details page.",MediaID);
}
function ActiveXControl()
{
	this.init = function() { }
	
	this.setAttribute = function (attribute,value)
	{
		this.attributes.index.push(attribute);
		this.attributes[attribute] = value;
		return true;
	}
	
	this.setParam = function (param,value)
	{
		this.params.index.push(param);
		this.params[param] = value;
		
		return true;
	}
	
	this.setEmbed = function (attribute,value)
	{
		this.embed.index.push(attribute);
		this.embed[attribute] = value;
	}
	
	this.ExportHTML = function ()
	{
		var s = '<object ';
		
		for(var i = 0; i < this.attributes.index.length; i++)
		{
			v = this.attributes[this.attributes.index[i]];
			s = s + " " + this.attributes.index[i] + '="' + v + '"';
		}
		
		s = s + '>';
		
		for(var i = 0; i < this.params.index.length; i++)
		{
			v = this.params[this.params.index[i]];
			s = s + '<param name="' + this.params.index[i] + '" value="' + v + '"/>';
		}
		
		if ( this.embed.index.length > 0 )
		{
			s = s + '<embed ';
		
			for(var i = 0; i < this.embed.index.length; i++)
			{
				v = this.embed[this.embed.index[i]];
				s = s + " " + this.embed.index[i] + '="' + v + '"';
			}
		
			s = s + '></embed>';
		}
		
		s = s + '</object>';
		
		return s;
	}
	
	this.getDOMObject = function()
	{
		 if (window.document[this.attributes.id]) 
		 {
		      return window.document[this.attributes.id];
		 }
		 
		 if (navigator.appName.indexOf("Microsoft Internet")==-1)
		 {
		   if (document.embeds && document.embeds[this.attributes.id])
		      return document.embeds[this.attributes.id]; 
		 } else {
		    return document.getElementById(this.attributes.id);
		 }
	}
	
	this.attributes = 
	{
		"classid" : null,
		"id" : null,
		"width" : null,
		"height" : null,
		"align" : null,
		"archive" : null,
		"border" : null,
		"codebase" : null,
		"codetype" : null,
		"data" : null,
		"declare" : null,
		"hspace" : null,
		"name" : null,
		"standby" : null,
		"type" : null,
		"usemap" : null,
		"vspace" : null,
		"title" : null,
		"style" : null,
		"dir" : null,
		"lang" : null,
		"index" : new Array()
	}
	
	this.params = 
	{
		"index" : new Array()
	}
	
	this.embed = 
	{
		"src" : null,
		"width" : null,
		"height" : null,
		"align" : null,
		"name" : null,
		"pluginspage" : null,
		"pluginsurl" : null,
		"hidden" : null,
		"href" : null,
		"target" : null,
		"autostart" : null,
		"loop" : null,
		"playcount" : null,
		"volume" : null,
		"controls" : null,
		"controller" : null,
		"mastersound" : null,
		"starttime" : null,
		"endtime" : null,
		"index" : new Array()	
	}
}

function FlashControl(id)
{
	var f = new ActiveXControl();

	f.setAttribute('id',id);
	f.setAttribute('classid',"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
	f.setAttribute('codebase',"http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0");
	
	return f;
}

function WMVPlayer(id)
{
	var t = new ActiveXControl();

	t.setAttribute("id",id);
	t.setAttribute("classid","CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6");
	t.setAttribute("codebase","http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=7,0,0,1954");
	t.setAttribute("type","application/x-oleobject");
	
	return t;
}

function ZoomerFlash(id,playername,client_type,ws_url,w,h,zoomername)
{
	var	f = new FlashControl(id);
	
	var movie = swf_prefix + playername + ".swf?autoplay=true";
	
	if ( swf_prefix.length > 0 )
	{
		movie = movie + "&swf_prefix=" + swf_prefix;
	}
	
	if ((client_type == "WMV_SA") || (client_type == "FLV_SA"))
	{
		movie = movie + "&client_type=" + client_type + ws_url +"&noChangeScheme=true"+"&zoomername="+zoomername;	
	}
	else if (client_type == "WMV" || client_type == "FLV")
	{
		movie = movie + "&client_type=" + client_type + ws_url+"&zoomername="+zoomername;
	}
	f.setAttribute("width",w);
	f.setAttribute("height",h);
	
	f.setParam('allowScriptAccess','sameDomain');
	f.setParam('loop','false');
	f.setParam('menu','true');
	f.setParam('wmode','transparent');
	//Indian Team - Changed the wmode type for testing purpose
	//f.setParam('wmode','nottransparent');
	f.setParam('movie',movie); 
	f.setParam('quality','high');
	f.setParam('play','true');
	f.setParam('bgcolor','#CCCCCC');
		
	f.setEmbed('name',id);
	f.setEmbed('play',f.params.play);
	f.setEmbed('wmode',f.params.wmode);
	f.setEmbed('swliveconnect','true');
	f.setEmbed('allowscriptaccess','sameDomain');
	f.setEmbed('src',f.params.movie);
	f.setEmbed('quality',f.params.quality);
	f.setEmbed('bgcolor',f.params.bgcolor);
	f.setEmbed('type','application/x-shockwave-flash');
	f.setEmbed('pluginspage',"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash");
	f.setEmbed('width',f.attributes.width);
	f.setEmbed('height',f.attributes.height);
	
	return f;
}

function ZoomerWMV(id)
{
	var w = new WMVPlayer(id);
	
	w.setAttribute('width',240);
	w.setAttribute('height',180);
	w.setAttribute('style','visibility:hidden');
	
	w.setParam('autostart','FALSE');
	w.setParam('uimode','none');
	w.setParam('URL','');
	w.setParam('stretchToFit','TRUE');
	
	return w;
}

function StandalonePlayer(id,sID)
{	
	var w = new WMVPlayer(id);
	var ts = new Date();
	var sURL = vm_prefix + "?fd=" + sID + "&tc=" + ts.getMilliseconds();
		
	w.setAttribute('width',320);
	w.setAttribute('height',305); //should this not be 305?
	
	w.setParam('autostart',"TRUE");
	w.setParam('uimode',"FULL");
	w.setParam('URL',sURL);
	
	w.setEmbed('src',sURL);
	w.setEmbed('autostart',1);
	w.setEmbed('ShowStatusBar',1);
	w.setEmbed('ShowControls',1);
	w.setEmbed('width',320);
	w.setEmbed('height',310); //should this not be 305?
	w.setEmbed('autorewind',1);
	
	return w;
}

function flashPlayerVersion(v)
{
	is_flash = true;
}

function fixArgs(args)
{
	return "'"+args+"'";
}

function initZoomerSize(w, h){
	zoomer_width = Number(w);
	zoomer_height = Number(h);
}

function SendDataToFlashMovie(v,value)
{
	if ( is_flash )
	{
		if ( !bVCSubmitted )
		{
			if ( vendor_config.index.length > 0 )
			{
				for ( var i=0;i<vendor_config.index.length;i++ )
				{
					FlashPlayerDOM.SetVariable(vendor_config.index[i].key,vendor_config.index[i].value);
					if( client_type == "WMV" || client_type == "FLV" )
	  	 			{
					fullsizePlayerDOM.SetVariable(vendor_config.index[i].key,vendor_config.index[i].value);
					}
				}
			}
			bVCSubmitted = true;	
		}
		
		try 
		{
			FlashPlayerDOM.SetVariable("autoplay","true");
			FlashPlayerDOM.SetVariable("client_type", client_type);
			FlashPlayerDOM.SetVariable(v,value);
		    
			//Modified width and height for the SA type
			if(client_type == "WMV_SA" || client_type == "FLV_SA")
			{
				FlashPlayerDOM.style.width = flashSA_width + "px";
				FlashPlayerDOM.style.height = flashSA_height + "px";
			}
			else
			{
				FlashPlayerDOM.style.width = flash_width + "px";
				FlashPlayerDOM.style.height = flash_height + "px";
				
				//Set Position for fullsizePlayerDom
				fullsizePlayerDOM.SetVariable("autoplay","true");
				fullsizePlayerDOM.SetVariable("client_type", client_type);
				fullsizePlayerDOM.SetVariable(v,value);
				fullsizePlayerDOM.style.width = flash_width + "px";
				fullsizePlayerDOM.style.height = flash_height + "px";
			}

			if(!chkFullsizegallery)
			{
				FlashPlayerDOM.style.visibility = "visible";
				if( client_type == "WMV" || client_type == "FLV" )
				{
					fullsizePlayerDOM.style.visibility = "hidden";
				}
			}
			else
			{
				
				FlashPlayerDOM.style.visibility = "visible";
				if( client_type == "WMV" || client_type == "FLV" )
				{	
					fullsizePlayerDOM.style.visibility = "visible";
				}
			}
		} catch(e) {
			if (bReturnErrors)
			{
				alert('Unable to communicate with Zoomer DOM');	
			}	
		}
	}
}
function openExternalDetails(id)
{
	if ( mediaItems[id] != undefined && typeof(mediaItems[id]) == "object" )
	{
		var ci = mediaItems[id];
	
		if (externalDetailsMode == "window.open")
		{
			window.open(ci.fileurl,ci.windowtitle);
		} else if (externalDetailsMode == "window.location") {
			window.location = ci.fileurl;
		}
	}
}
function openExternalForm(id)
{
	if ( mediaItems[id] != undefined && typeof(mediaItems[id]) == "object" )
	{
		var ci = mediaItems[id];
	
		if (externalDetailsMode == "window.open")
		{
			window.open(ci.formurl,ci.windowtitle);
		} else if (externalDetailsMode == "window.location") {
			window.location = ci.formurl;
		}
	}
}	
function waitForSuccess()
{
	if ( !bLoadSuccess )
	{
		if (nAttempts >= nMaxAttempts)
		{
			movePlayer(flLeft,flTop);
			mediaItems[mediaid].fileurl = "http://sandbox.pic2vid.com/p2vcom/zoomervm.php?fd=" + mediaid;
			openExternalForm = function(id)
			{
				if ( mediaItems[id] != undefined && typeof(mediaItems[id]) == "object" )
				{
					var ci = mediaItems[id];
					window.open(ci.formurl,ci.windowtitle);
				}
			}	
			msgWindow = new MessageWindow("Zoomer Unavailable","Click 'OK' to view the firewall-friendly video in a new window.",mediaid);
			
		} else {
			nAttempts++;
			setTimeout("waitForSuccess();", 1000);
		}
	}
}
function loadMedia(id)
{
	soapid=id;
	
	if (( client_type == 'WMV' ) || ( client_type == 'WMV_SA' ))
	{
		player_show(true);
	}
		
	checkMovePlayer(flashLayer);
	
	if ( is_flash && bInit )
	{
		if ( mediaItems[id] != undefined && typeof(mediaItems[id]) == "object" )
		{
			var ci = mediaItems[id];
			if ( ci.guid != undefined )
			{
				setTimeout("SendDataToFlashMovie('guid','"+ci.guid+"');", 400);
			}
		}
		mediaid = id;
		nAttempts = 0;
		setTimeout("SendDataToFlashMovie('id','"+id+"');waitForSuccess()", 400);
		bContinue = true;
	} else {
		nAttempts++;
		if ( nAttempts < nMaxAttempts && bContinue)
		{
			setTimeout("loadMedia('"+id+"');", 1000);
		} else {
			movePlayer(flLeft,flTop);
			bContinue = false;
			nAttempts = 0;

			msgWindow = new MessageWindow("Zoomer Unavailable","Click 'OK' to be forwarded to the details page.",id);
		}
	}
	return false;
}
function playerVisible(onOffString)
{
	if (onOffString == "true" || onOffString == true)
	{
		player_open = true;
	} else {
		player_open = false;
		flashLayer.style.left = '-1000px';
	}
}

function wmpErrorHandler()
{
	var max = wmvPlayerDOM.error.errorCount - 1;
	var errItem = wmvPlayerDOM.error.item(max);
		
	errDesc = errItem.errorDescription;
	errNum = errItem.errorCode;
	if ( client_type == "WMV" )
	{
		client_type = "FLV";
	} else if ( client_type == "WMV_SA" ) {
		client_type = "FLV_SA";	
	}
	
	loadMedia('error');
}
function init_players()
{
	wm_layer_org_x = numToLoc(locToNum(wmLayer.style.left) - 16);
 	wm_layer_org_y = numToLoc(locToNum(wmLayer.style.top) - 38);	
}
function initzoomer()
{
	if (( client_type == "WMV" || client_type == "FLV" && !bInit ) || ( client_type == "WMV_SA" || client_type == "FLV_SA" && !bInit ))
	{
	    
		flash_swf_layer = document.getElementById('flash_swf_layer');
		wmLayer = document.getElementById('wmLayer');
		flashLayer = document.getElementById('flashLayer');
		dragLayer = document.getElementById('dragLayer');

		flashLayer.style.position 	= (bIsEmbedded) ? "relative" : "absolute";
		if ( !bIsEmbedded )
		{
			flashLayer.style.left 	= flLeft + "px";
			flashLayer.style.top 	= flTop + "px";
			flashLayer.style.zIndex	= 200;
		}
		
		//Modified width and height for the SA type
		if(client_type == "WMV_SA" || client_type == "FLV_SA")
		{
			flashLayer.style.width 		= flashSA_width + "px";
			flashLayer.style.height 	= flashSA_height + "px";
						
		}
		else
		{
			flashLayer.style.width 	        = flash_width + "px";
			flashLayer.style.height 	= flash_height + "px";
		}
		flashLayer.style.visibility	= "visible";
	
		wmLayer.style.position 	= (bIsEmbedded) ? 'absolute' : 'relative';
		wmLayer.style.zIndex 	= 200;
		if ( !bIsEmbedded )
		{
			wmLayer.style.left 	= '23px';
			wmLayer.style.top 	= ((-flash_height) + 44) + "px";
		} else {
			wmLayer.style.left 	= '23px';
			wmLayer.style.top 	= '46px';	
		}
			
		flash_swf_layer.style.visibility= 'visible';
		flash_swf_layer.style.position 	= 'relative';
		flash_swf_layer.style.left 	= '5px';
		flash_swf_layer.style.top 	= '0px';

		//Fixed the WM layer position for _SA type
		if(client_type == "WMV_SA" || client_type == "FLV_SA")
		{
			flash_swf_layer.style.width 	= '245px';
			flash_swf_layer.style.height 	= '245px';
		}
		else
		{
			flash_swf_layer.style.width 	= '424px';
			flash_swf_layer.style.height 	= '345px';
			
			//Set position for fullsizeGallery
			fullsizegallery_layer = document.getElementById('fullsizegallery_layer');
			dragGalleryLayer=document.getElementById('dragGalleryLayer');
			fullsizegallery_layer.style.visibility  = 'hidden';
			fullsizegallery_layer.style.position    = 'absolute';
			fullsizegallery_layer.style.left 	= '350px';
			fullsizegallery_layer.style.top 	= '40px';
			fullsizegallery_layer.style.width 	= '424px';
			fullsizegallery_layer.style.height      = '345px';
			//Set position for dragLayer
			dragGalleryLayer.style.width 		= flash_width + 10 + 'px';
			dragGalleryLayer.style.height		= flash_height + 'px';
			dragGalleryLayer.style.zIndex 		= 1;
			dragGalleryLayer.style.visibility 	= 'hidden';
			if ( is_win )
			{
				dragGalleryLayer.style.backgroundColor = dragGalleryColor;
				dragGalleryLayer.style.opacity = 0.5;
				dragGalleryLayer.style.filter 	= "alpha(opacity=50)";
			}
		}
		
		if (!bIsEmbedded )
		{
			flash_swf_layer.style.zIndex= 3000;
			dragLayer.style.left 	= flLeft + 'px';
			dragLayer.style.top 	= flTop + 'px';
			if ( client_type == "WMV" || client_type == "FLV")
			{
				fullsizegallery_layer.style.zIndex	= 3000;
				dragGalleryLayer.style.position 	= 'absolute';
				dragGalleryLayer.style.left 		= flLeft+100 + 'px';
				dragGalleryLayer.style.top 		= flTop+10 + 'px';
			}
		}
		dragLayer.style.position 	= 'absolute';
		dragLayer.style.width 		= flash_width + 10 + 'px';
		dragLayer.style.height		= flash_height + 'px';
		dragLayer.style.zIndex 		= 1;
		dragLayer.style.visibility 	= 'hidden';
		if ( is_win )
		{
			dragLayer.style.backgroundColor = dragColor; //'#ddddff';
			dragLayer.style.opacity = 0.5;
			dragLayer.style.filter 	= "alpha(opacity=50)";
		}
		
		attachMouseEvents();
		init_players();	
		FlashPlayerDOM = zFlash.getDOMObject();
		if( client_type == "WMV" || client_type == "FLV" )
	  	{	
			fullsizePlayerDOM = fullsizeFlash.getDOMObject();
		}	

		if (( client_type == "WMV" ) || ( client_type == "WMV_SA" ))
		{
			wmvPlayerDOM = zWMV.getDOMObject();
			wmvPlayerDOM.style.visibility = 'hidden';
		}
		
		bInit = true;
	}
	
	window.focus();
}
function addLoadEvent(f)
{
	var old = window.onload;
	if ( typeof old != 'function' )
	{
		window.onload = f;	
	} else {
		window.onload = function()
		{
			old();
			f();	
		}
	}
}
function AlertOnSDK(strVal)
{
	alert(strVal);
}
addLoadEvent(initzoomer);
function showfullsizePic(binclip)
{
	chkFullsizegallery=true;
	if (client_type == "WMV")
	{
		player_pause();	
		wmLayer.style.visibility = "hidden";	
		wmvPlayerDOM.style.visibility = 'hidden';
	}
	
	fullsizegallery_layer.style.visibility ="visible";
	fullsizePlayerDOM.style.visibility = "visible";
	
	fullsizegallery_layer.style.left = numToLoc(locToNum(flashLayer.style.left)+30);
	fullsizegallery_layer.style.top = numToLoc(locToNum(flashLayer.style.top)+30);
	
	fullsizePlayerDOM.SetVariable("autoplay","true");
	fullsizePlayerDOM.SetVariable("client_type", client_type);
	fullsizePlayerDOM.SetVariable("id",soapid);
	fullsizePlayerDOM.SetVariable("zoomer_binclip",binclip);
	fullsizegallery_layer.style.left = '400px';	
	FlashPlayerDOM.SetVariable("chkFullsizegallery","true");
}
function closefullsizegallery()
{	
	chkFullsizegallery=false;

	FlashPlayerDOM.SetVariable("chkFullsizegallery","false");
	fullsizegallery_layer.style.left = '-1000px';
	if (client_type == "WMV")
	{	
		wmLayer.style.visibility = "visible";
		if (chkPlay)
		{
			wmvPlayerDOM.style.visibility = 'visible';
		}
		else
		{
			wmvPlayerDOM.style.visibility = 'hidden';
		}
	}
}
function AlignDiv(divname)
{
	 needtoDrag=divname.id;
}
function loadMediaSuccess(loadSoapData)
{
	if(loadSoapData == "true")
	{
		bLoadSuccess = true;
		nAttempts = 0;	
	}
}
function contactSubmitted(emailSend)
{
	if(emailSend == "true")
	{
		
	}
}
function Closezoomer()
{
	
}

