// +--------------------------------------------------------+
// | PopNDrop Communication Include							|
// +--------------------------------------------------------+
// | Author: Frank Spitzka (fspitzka@fimlabs.com)			|
// | Company: Fox Interactive Media Labs					|
// | Date Created: Nov 11 2005								|
// | Date Modified:	JUN 01 2005								|
// | Version: 1.0											|
// +--------------------------------------------------------+


	var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	var buttonCounter = 0;
	var BASE_PATH = "http://downloads.thespringbox.com/";
	
	function global_DoFSCommand(movieName,command,args)
	{			
			switch(command)
			{
				case "out":				
					alert(args);
					break;						
					
				case "getCurrentCoordinates":							
					if(isInternetExplorer)
					{
						//alert(movie + "_" + command)	
						
						// IE
						var movie = window[movieName];
						
						var x = 1 + window.screenLeft + 1*document.body.leftMargin - document.body.scrollLeft - document.documentElement.scrollLeft;
						var y = 2 + window.screenTop + 1*document.body.topMargin - document.body.scrollTop - document.documentElement.scrollTop;					
					
						currentTag = movie
						
						while(currentTag != undefined && currentTag != null)
						{
							x += currentTag.offsetLeft;
							y += currentTag.offsetTop;
							
							currentTag = currentTag.offsetParent;
							//alert(currentTag);							
						}

						//alert("Testing: " + movie.offsetTop +"|" + movie.offsetParent.offsetTop + "__" + window.screenTop + "__" + 1*document.body.topMargin + "--" + document.body.scrollTop + "__" + document.documentElement.scrollTop);
					
					}else{
						// Mozilla + Other
						var movie = document[movieName];
						
						var x = movie.offsetLeft + window.screenX  - window.scrollX;
						var y = movie.offsetTop + window.screenY  - window.scrollY + 115;					
					}					
					
					//alert(window.screenLeft + "__" + window.screenTop);
					//alert(document.body.scrollLeft + "__" + document.body.scrollTop + "--" + document.documentElement.scrollLeft + "__" + document.documentElement.scrollTop)
					//alert(x + " | " + y);	
					
					movie.SetVariable("/pndc:xPos", x); 
					movie.SetVariable("/pndc:yPos", y);
					movie.SetVariable("/yPos", y);
					alert("setting" + x + "|" + y + "   -   " +movie);
						
					break;			
			}//END SWITCH	
	}
	

/////////////////////////////////////////////////////////////////////

	function printButton(widgetName,arg,memberId,size)
	{
		//nn var x = window.screenX + window.scrollX + 10;
		//nn var y = window.screenY + window.scrollY + 10;
		
		var x = window.screenLeft + 12;// + window.scrollX + 10;
		var y = window.screenTop + 12;// + window.scrollY + 10;
		
		
		size = !!size ? size : 'small';
		
		if(size == 'small'){
			var w = 16;
			var h = 16;
		}else{
			var w = 100;
			var h = 20;
		}
		
		var filename = BASE_PATH + "widgets/" + widgetName + ".sbw";
		//var filename = widgetName + ".sbw";
				
		var path = '';
		path += BASE_PATH + 'web/'+size+'button.swf';
		path += '?x=' + x;
		path += '&y=' + y;
		path += '&file=' + filename;
		path += '&myName=moduleButton' + buttonCounter;		

		if(typeof(arg) == 'object'){
			for(var a in arg){
				if(a == 'param'){ 
					path +='&param='+escape(arg[a]); 
				}else{
					path += '&param_'+a+'='+escape(arg[a]);	
				}
			}
		}else{
			path +='&param='+escape(arg);
		}
		
		if(!!memberId && memberId != '')
		{
			path += '&memberId=' + memberId;
		}
		
		var embedstr = '';	
		embedstr += '<embed src="' + path;
		embedstr += '" quality="high" wmode="transparent" bgcolor="#000000" width="'+w+'" height="'+h+'" name="moduleButton' + buttonCounter + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true"/>';
				
		var paramstr = '';	
		paramstr += '<param name="movie" value="' + path + '" />';
		
		//
		
		var flashstr = '';
		flashstr += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" id="moduleButton' + buttonCounter + '" align="middle">';
		flashstr += '<param name="allowScriptAccess" value="always" />';		
		flashstr += paramstr;
		flashstr += '<param name="quality" value="high" />';
		flashstr += '<param name="wmode" value="transparent">';
		flashstr += '<param name="bgcolor" value="#000000" />';
		flashstr += embedstr;
		flashstr += '</object>';		
		
		
		this["moduleButton" + buttonCounter + "_DoFSCommand"] = function(movie, command)
		{
			//var module_wrapperObj = isInternetExplorer ? document.all.moduleButton : document.moduleButton;
		
			//alert(movie + "_" + command)
			global_DoFSCommand(movie,command);		
		};
		
		// Hook for Internet Explorer.
		if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
			document.write('<script language=\"VBScript\"\>\n');
			document.write('On Error Resume Next\n');
			document.write('Sub moduleButton'+ buttonCounter +'_FSCommand(ByVal command, ByVal args)\n');
			document.write('	Call moduleButton'+ buttonCounter +'_DoFSCommand(command, args)\n');
			document.write('End Sub\n');
			document.write('</script\>\n');
		}

		
		document.write(flashstr);		
		//alert(flashstr);
		
		buttonCounter++;		
	}
	
	
/////////////////////////////////////////////////////////////////////


	function printWrapper(widgetName,arg,width,height,affiliate,hideControls)
	{
		//nn var x = window.screenX + window.scrollX + 10;
		//nn var y = window.screenY + window.scrollY + 10;
		
		var x = window.screenLeft + 12;// + window.scrollX + 10;
		var y = window.screenTop + 12;// + window.scrollY + 10;
		var w = width;
		var h = height;

		//var filename = BASE_PATH + "widgets/" + widgetName + ".sbw";
		var filename = widgetName + ".sbw";
		//alert(filename);
		
		var path = BASE_PATH + 'web/wrapper.php';
		
		var flashvars = '';
			//flashvars += 'x=' + x;
			//flashvars += '&y=' + y;
			//flashvars += 'file=' + filename;		
			flashvars += 'myName=moduleButton' + buttonCounter;		
		if(typeof(arg) == 'object'){
			for(var a in arg){
				if(a == 'param'){
					flashvars +='&param='+escape(arg[a]);
				}else{
					flashvars += '&param_'+a+'='+escape(arg[a]);	
				}
			}
		}else{
			flashvars +='&param='+escape(arg);
		}
		
		if(!!affiliate)
		{
			flashvars += '&memberId=' + affiliate;
		}
		if(!!hideControls)
		{
			flashvars += '&hideControls=' + hideControls;
		}
		
		if(widgetName == "SPBeta.sbw" || widgetName == "Studio Promo"){
			wmode = "window";
		}else{
			wmode = "transparent";
		}
		
		
		var embedstr = '';	
		embedstr += '<embed src="' + path + '?file='+filename+'" FlashVars="' + flashvars + '"';
		embedstr += ' allowFullScreen="true" allowNetworking="all" quality="high" bgColor="#000000" wmode="'+wmode+'" width="'+w+'" height="'+h+'" name="moduleButton' + buttonCounter + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true"/>';
				
		//var paramstr = '';	
		//paramstr += '<param name="movie" value="' + path + '" />';
		
		//
		
		var flashstr = '';
		flashstr += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" id="moduleButton' + buttonCounter + '" align="middle">';
		flashstr += '<param name="allowScriptAccess" value="always" />';		
		flashstr += '<param name="movie" value="' + path + '?file='+filename+'" />';
		flashstr += '<param name="FlashVars" value="' + flashvars + '" />';
		flashstr += '<param name="quality" value="high" />';
		flashstr += '<param name="wmode" value="'+wmode+'">';
		flashstr += '<param name="bgColor" value="#000000" />';
		flashstr += '<param name="allowFullScreen" value="true" />';
		flashstr += '<param name="allowNetworking" value="all" />';
		flashstr += embedstr;
		flashstr += '</object>';	
		
		
		
		this["moduleButton" + buttonCounter + "_DoFSCommand"] = function(movie, command)
		{
			//var module_wrapperObj = isInternetExplorer ? document.all.moduleButton : document.moduleButton;
		
			//alert(movie + "_" + command)			
			
			global_DoFSCommand(movie,command);		
		};
		
		// Hook for Internet Explorer.
		if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
			document.write('<script language=\"VBScript\"\>\n');
			document.write('On Error Resume Next\n');
			document.write('Sub moduleButton'+ buttonCounter +'_FSCommand(ByVal command, ByVal args)\n');
			document.write('	Call moduleButton'+ buttonCounter +'_DoFSCommand(command, args)\n');
			document.write('End Sub\n');
			document.write('</script\>\n');
		}

		
		document.write(flashstr);
		//document.getElementById("ta").value = flashstr;
		/*
		if(!!debug && debug === true)
		{
			var str = flashstr.replace("><",">\n<");
			alert(str);
		}
		*/
		buttonCounter++;		
	}