

var flashWindows = new Array();




//movieURL, agency, title, director
function popupVideo(movieURL, agency, title, director)
{
	//alert(movieURL +', '+agency+', '+title+', '+	director);
	
	extension = '.mov';
	var thisFile = movieURL.split('/');
	thisFile = thisFile[thisFile.length-1];
	
	var thisFileNoExt = thisFile.substring(0,thisFile.indexOf(extension));
	
	
	var myWidth;
	var myHeight;
	
	
	myWidth = '320';
	myHeight = '240';
	
	// 50 is below	
	var agt=navigator.userAgent; 
	if (agt.indexOf('Safari') > -1 )
	{
		//myHeight+=16;
	}
	var windowLeftMargin = 30;
	var windowVerticalMargin = 80;
	var windowWidth = parseInt(myWidth) + windowLeftMargin;
	var windowHeight = parseInt(myHeight) + windowVerticalMargin;
	windowWidth = windowWidth + '';
	windowHeight = windowHeight + '';
	
	//////////////// CENTER
	var w = 480;
	var h = 340;
	
	var viewportwidth;
	var viewportheight;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth,
	  viewportheight = window.innerHeight
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) 	{
	   viewportwidth = document.documentElement.clientWidth,
	   viewportheight = document.documentElement.clientHeight
	} else 	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	
	var popW = windowWidth
	var popH = windowHeight;
	
	var leftPos = (viewportwidth-windowWidth)/2
	var topPos = (viewportheight-windowHeight)/2;
	
	//alert('viewportwidth = ' +viewportwidth + ', viewportheight = ' + viewportheight + ', windowWidth = ' + windowWidth + ', windowHeight = ' + windowHeight );
	//////////////// CENTER
	//alert('height = '+h+' width = '+w +' top = '+topPos+' left = '+leftPos)
	
	var windowFeatures = 'width='+windowWidth+',height='+windowHeight+', top='+topPos+', left='+leftPos+', location=0,toolbar=0,directory=0,scrollbars=0,menubar=0,resizable=1';
	
	//movieURL = "/uploads/movies/"+movieURL;
	//alert('movieURL = ' + movieURL);
	// FLASH
	
	var flashVars = "jam=" + director + "&agency=" + agency + "&projectTitle=" +title + "&theDirector=" +director;
	
	////////
	// 
	if (thisFileNoExt.charAt(thisFileNoExt.length-1) == '.')
		thisFileNoExt = thisFileNoExt.substring(0, thisFileNoExt.length-1);
	
	var newfile = thisFileNoExt;
	var tempfile='';
	
	for (var i=0; i<newfile.length; i++) {
		if (newfile.charAt(i) != "-") {
			tempfile = tempfile + "" + newfile.charAt(i);
		}
	}
	w = windowWidth;
	h = windowHeight;
	
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	windowFeatures = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left;
	//var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
	
	thisFileNoExt = tempfile;
	
	//flashWindows[thisFile] = window.open('',thisFileNoExt,windowFeatures); // bug
	flashWindows[thisFile] = window.open('/popup.php?agency='+agency+'&title='+title+'&movieURL='+movieURL+'&director='+director+'',thisFileNoExt,windowFeatures);
	
	if (window.focus)
		flashWindows[thisFile].focus();
	
	return;
	
	flashWindows[thisFile] = window.open ('', thisFileNoExt, windowFeatures);
	
	flashWindows[thisFile].document.write('<html>\n<title>WILD(CHILD) '+agency+'- '+title+'</title>\n');
	flashWindows[thisFile].document.write('<body scrolling="no" style="overflow:hidden;" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" bgcolor="#ffffff">\n');
	flashWindows[thisFile].document.write('<div id="quicktimeDiv" style="position:absolute;z-index:10000;top:15px;left:' +(windowLeftMargin/2)+ 'px;"><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+myWidth+'" height="'+myHeight+'">\n');
	flashWindows[thisFile].document.write('<param name="scale" value="tofit">\n');
	flashWindows[thisFile].document.write('<param name="src" value="'+movieURL+'">\n');
	flashWindows[thisFile].document.write('<param name="autoplay" value="true">\n');
	flashWindows[thisFile].document.write('<param name="controller" value="true">\n');
	flashWindows[thisFile].document.write('<embed scale="tofit" width="'+myWidth+'" height="'+myHeight+'" pluginspage="http://www.apple.com/quicktime/download/" src="'+movieURL+'" type="video/quicktime" controller="true" autoplay="true">\n');
	flashWindows[thisFile].document.write('</object></div>\n');
	
	flashWindows[thisFile].document.write('<div style="position:absolute;top:262px;left:15px;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="320" height="50" id="videoPopup" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="popup.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	flashWindows[thisFile].document.write('<param name="flashVars" value="'+flashVars+'" />');
	flashWindows[thisFile].document.write('<embed flashVars="'+flashVars+'" src="popup.swf" quality="high" bgcolor="#ffffff" width="320" height="50" name="videoPopup" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></div>');

	flashWindows[thisFile].document.close();
	
	
	
	if (window.focus)
		flashWindows[thisFile].focus();
}
