// -----------------------------------------------------------------------------
// which video should play?
var videoBaseSrc = "http://www.videozam.com/clientscripts/";
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// -----------------------------------------------------------------------------

// Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
}
// -->

function drawThumbs(divId, accountId, category, theWidth, theHeight)
{
    document.write("<iframe id=\"f1\" style=\"width:0px; height:0px; border: 0px;\" src=\"http://www.videozam.com/PlayerThumbs/PlayerThumbs.aspx?id=" + accountId + "&ca=" + category + 
        "&dv=" + divId + "&w=" + theWidth.toString() + "&h=" + theHeight.toString() + "\"></iframe>");
}

var trackDescriptionDivId_global;
var flashContainerDivId_global;

function setContainers(trackDescriptionDivId, flashContainerDivId)
{
    trackDescriptionDivId_global = trackDescriptionDivId;
    flashContainerDivId_global = flashContainerDivId;
}

function showClip(item, e, url, information)
{
    var clickObject;
    if (e.srcElement)
        clickObject = e.srcElement;
    else
        clickObject = e.target;
    
    while ( clickObject != undefined && clickObject != item)
    {
        if (clickObject.getAttribute('isMovieStart') || item.getAttribute('isMovieStart'))
        {
            document.getElementById(trackDescriptionDivId_global).innerHTML = information;
            document.getElementById(flashContainerDivId_global).innerHTML = CreateFlashPlayerHTML(url);
            clickObject = item;
        }
        else
        {
            if (clickObject.parentElement)
                clickObject = clickObject.parentElement;
            else
                clickObject = clickObject.parentNode;
        }
    }
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

// Handle all the FSCommand messages in a Flash movie.
function jsTest_DoFSCommand(command, args) {
	var jsTestObj = isInternetExplorer ? document.all.jsTest : document.jsTest;

	if(document.getElementById('trackDescription'))
		document.getElementById('trackDescription').innerHTML = args;
}

// 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 jsTest_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call jsTest_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

function CreateFlashPlayer(videoSrc)
{
    //alert(CreateFlashPlayerHTML(videoSrc));
    document.write(CreateFlashPlayerHTML(videoSrc));
}

function CreateFlashPlayerHTML(videoSrc)
{
    var accountID;
    var category;
    
    /* Usage:
        1 - videoSrc = "http://<fully qualified URL to Flash Video File>.flv"
        2 - videoSrc = "id=<accountID>&ca=<category>"
        3 - videSrc = null - Use document.URL parameters as: ?id=<account#>&ca=<category>
    */

    if (videoSrc == null)
    {
        //alert("case 3");
        docURL = document.URL.toUpperCase();
        // 3 - Use document.URL as parmeters
        if (docURL.indexOf("CA=") == -1 ||
            docURL.indexOf("ID=") == -1)
        {
            alert("Expecting URL parameters");
            return;
        }
        
        category = docURL.substr(docURL.indexOf("CA=")+3);
        accountID = docURL.substr(docURL.indexOf("ID=")+3);
        
        if (category.indexOf("&") != -1)
            category = category.substr(0, category.indexOf("&"));
        if (accountID.indexOf("&") != -1)
            accountID = accountID.substr(0, accountID.indexOf("&"));
        
        if (accountID == '' || category == '')
            return;
   
    } else {
    
        videoSrc = videoSrc.toUpperCase();

        if (videoSrc.indexOf(".flv") == -1) 
        {
    
            // alert("case 2");
            // 2 - Use parameters as accountID and Category
           
            if (videoSrc.indexOf("CA=") != -1 && videoSrc.indexOf("ID=") != -1)
            {
                category = videoSrc.substr(videoSrc.indexOf("CA=")+3);
                accountID = videoSrc.substr(videoSrc.indexOf("ID=")+3);

                if (accountID.indexOf("&") != -1)
                    accountID = accountID.substr(0, accountID.indexOf("&"));
                
                if (category.indexOf("&") != -1)
                    category = category.substr(0, category.indexOf("&"));

                if (accountID == '' || category == '')
                    return;
                
                videoSrc = null;
         } else {
            // 1 - Use fully qualified URL to Flash Video File
            //alert("case 1");
         }
       }
    }
    
    // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
    var hasProductInstall = DetectFlashVer(6, 0, 65);

    // Version check based upon the values entered above in "Globals"
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

    // Location visited after installation is complete if installation is required
    var MMredirectURL = window.location;

    // Stored value of document title used by the installation process to close the window that started the installation process
    // This is necessary to remove browser windows that will still be utilizing the older version of the player after installation is complete
    // DO NOT MODIFY THE FOLLOWING TWO LINES
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

    // Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
    if ( hasProductInstall && !hasReqestedVersion ) {
	    var productInstallOETags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
	    + 'width="342" height="489"'
	    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
	    + '<param name="movie" value="' + videoBaseSrc + 'vzPlayerProductInstall.swf?MMredirectURL='+MMredirectURL+'&MMplayerType=ActiveX&MMdoctitle='+MMdoctitle+'" />'
	    + '<param name="quality" value="high" /><param name="bgcolor" value="#EAEAEA" />'
	    + '<embed src="' + videoBaseSrc + 'vzPlayerProductInstall.swf?MMredirectURL='+MMredirectURL+'&MMplayerType=PlugIn" quality="high" bgcolor="#EAEAEA" '
	    + 'width="342" height="489" name="detectiontest" aligh="middle"'
	    + 'play="true"'
	    + 'loop="false"'
	    + 'quality="high"'
	    + 'allowScriptAccess="sameDomain"'
	    + 'type="application/x-shockwave-flash"'
	    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
	    + '<\/embed>'
	    + '<\/object>';
	    return productInstallOETags;   // embed the Flash Product Installation SWF
    } else if (hasReqestedVersion) {  // if we've detected an acceptable version
	    var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
	    + 'width="342" height="' + (videoSrc == null ? '320' : '320' ) + '" id="jsTest" swliveconnect="true" '
	    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
	    + '<param name="movie" value="' + videoBaseSrc
	    + (videoSrc == null ?
	        'VideoZamSolo.swf?id=' + accountID.toString() + '&ca=' + category.toString() : 'VideoZamSolo.swf?src=' + videoSrc.toString())
	    + '" /><param name="quality" value="high" />'
	    + '<param name="wmode" value="transparent" />'
	    + '<embed src="' + videoBaseSrc
	    + (videoSrc == null ?
	        'VideoZamSolo.swf?id=' + accountID.toString() + '&ca=' + category.toString() : 'VideoZamSolo.swf?src=' + videoSrc.toString()) + '" quality="high"'
	    + 'width="342" height="' + (videoSrc == null ? '320' : '320' ) + '" align="middle" name=jsTest swliveconnect="true" '
	    + 'play="true" '
	    + 'loop="false" '
	    + 'quality="high" wmode="transparent" '
	    + 'allowScriptAccess="sameDomain" '
	    + 'type="application/x-shockwave-flash" '
	    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
	    + '<\/embed>'
	    + '<\/object>';
	    return oeTags;   // embed the Flash Content SWF when all tests are passed
	    } else {  // flash is too old or we can't detect the plugin
	    var alternateContent = '<table border="0" width="350" align="center"><tr><td>'
	    +'<span class="noFlashHeading">We\'re Sorry!</span><br>'
	    + '<span class="noFlashCopy">Our tests have determined that you do not have the <a href="http://www.macromedia.com/go/getflash/">Macromedia Flash Player</a> installed or are using an out of date version. You may download the latest player <a href="http://www.macromedia.com/go/getflash/">here</a>. It only takes a few seconds and we encourage you to return when you\'re done. </span>'
	    +'</td></tr></table>'
	    return alternateContent;  // insert non-flash content
	    }
}

function StartPopup(theURL, theLeft, theTop, theWidth, theHeight)
{
    var playerStatus = 'scrollbars=no';
    if (theLeft != null) playerStatus += ',left=' + theLeft;
			else playerStatus += ',left=' + (screen.width - theWidth) / 2;
    if (theTop != null) playerStatus += ',top=' + theTop;
			else playerStatus += ',top=' + (screen.height - theWidth) / 2;
    if (theWidth != null) playerStatus += ',width=' + theWidth;
    if (theHeight != null) playerStatus += ',height=' + theHeight;

	playerWindow = window.open(theURL,'VideoPlayer', playerStatus); 

	if (!playerWindow.closed) {
		playerWindow.focus();
	} 
}