var videoPlaying = false;
var mp3Playing = false;
var realPlaying = false;
var vidCreated=false;
var mp3Created=false;
var realCreated=false;
var numErrors=0;

function createMp3()
{
  window["mpplayer"] = new Object();
  var so1 = new SWFObject(staticSite + "/media/flashplayer/mp3Player4.swf", "mpplayer", "482", "303", "9.0.0.0", "#1a1a19");
  so1.useExpressInstall(staticSite + "/media/homepageflash/expressinstall.swf");
  so1.addParam("quality", "high");
  so1.addParam("align", "middle");
  so1.addParam("allowscriptaccess", "sameDomain");
  so1.addParam("allowfullscreen", "true");
  so1.addParam("wmode", "transparent");
  // check to make sure this is true
  if(so1.write("mp3PlayerDiv"))
  {
    // check to see if the varable Needs update is set
    if(so1.getVariable("NeedsUpdate"))
    {
        // report that flash needed to be updated, include the currentl installed player version
        $.post("/layouts/systemitems/reportclientsideerror.aspx",{fm:'MP3LessThen9',ver:so1.installedVersion().toString()});
        alert("Adobe Flash version " + so1.installedVersion().toString() + " was found installed on your system.\nTo listen to this audio, Flash version 9.0 or higher is required.\nYou will be presented with a choice to update your version.");
        return 1;
    }
    else
    {
        // everything looks great
          SWFFormFixNew("mp3PlayerDiv","mpplayer");
          mp3Created=true;
        return 0;
    }
  }
  else
  {
    // check and see if a version is installed
    if(so1.installedVersion().toString()=="0.0.0")
    {
        // flash is not installed
        $.post("/layouts/systemitems/reportclientsideerror.aspx",{fm:'MP3NotFound',ver:so1.installedVersion().toString()});
        alert("Adobe Flash was not found installed on your computer.\nPlease visit the Adobe site to install the latest Flash Player to listen to this audio.");
        return 3;
    }
    else
    {
        // flash is installed, just not a high enough version to support the self install
        $.post("/layouts/systemitems/reportclientsideerror.aspx",{fm:'MP3LessThen6',ver:so1.installedVersion().toString()});
        alert("Adobe Flash version " + so1.installedVersion().toString() + " was found installed on your computer.\nTo listen to this audio, Flash version 9.0 or higher is required.\nPlease visit the Adobe site to install the latest player.");
        return 2;
    }
  }

}
function createFlash()
{
  window["saintsplayer"] = new Object();
  var so = new SWFObject("/media/flashplayer/saintsPlayer3.swf", "saintsplayer", "482", "303", "9.0.0.0", "#1a1a19");
  so.useExpressInstall("/media/homepageflash/expressinstall.swf");
  so.addParam("quality", "high");
  so.addParam("align", "middle");
  so.addParam("allowscriptaccess", "sameDomain");
  so.addParam("allowfullscreen", "true");
  if(parent.frames.length==0){so.addParam("wmode", "transparent");}
  if((navigator.userAgent.toLowerCase().indexOf("mac")!=-1) && (so.installedVersion()>"9.0.28"))
  {
    alert("It appears that you are running a Macintosh computer and a version of Adobe Flash that affects playback of video on the New Orleans Saints site. Please follow the directions that will be displayed to the left to uninstall your version and re-install version 9.0.28.");
    $("#flvPlayerDiv").html("<br/><h3>1) Uninstall the Flash Player following these <a class='wtWtLink' href='http://www.adobe.com/go/tn_14157' target='_blank'>instructions</a>.<br/><br/>2) <a class='wtWtLink' href='http://www.adobe.com/go/tn_14266' target='_blank'>Download an archived version</a> of player 9.<br/><br/>3) Install version 9.0.28 of the Flash Player.</h3>");
    return 4;
  }
  else
  {
      // check to make sure this is true
      if(so.write("flvPlayerDiv"))
      {
        // check to see if the varable Needs update is set
        if(so.getVariable("NeedsUpdate"))
        {
            // report that flash needed to be updated, include the currentl installed player version
            $.post("/layouts/systemitems/reportclientsideerror.aspx",{fm:'LessThen9',ver:so.installedVersion().toString()});
            alert("Adobe Flash version " + so.installedVersion().toString() + " was found installed on your system.\nTo view this video, Flash version 9.0 or higher is required.\nYou will be presented with a choice to update your version.");
            return 1;
        }
        else
        {
            // everything looks great
            SWFFormFixNew("flvPlayerDiv","saintsplayer");
            vidCreated=true;
            return 0;
        }
      }
      else
      {
        // check and see if a version is installed
        if(so.installedVersion().toString()=="0.0.0")
        {
            // flash is not installed
            $.post("/layouts/systemitems/reportclientsideerror.aspx",{fm:'NotFound',ver:so.installedVersion().toString()});
            alert("Adobe Flash was not found installed on your computer.\nPlease visit the Adobe site to install the latest Flash Player to view this video.");
            return 3;
        }
        else
        {
            // flash is installed, just not a high enough version to support the self install
            $.post("/layouts/systemitems/reportclientsideerror.aspx",{fm:'LessThen6',ver:so.installedVersion().toString()});
            alert("Adobe Flash version " + so.installedVersion().toString() + " was found installed on your computer.\nTo view this video, Flash version 9.0 or higher is required.\nPlease visit the Adobe site to install the latest player.");
            return 2;
        }
      }
    }
}
function createReal()
{
    //window["realplayer"] = new Object();
    var temp="";
    temp="<object id=\"realplayer\" classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" width=\"482\" height=\"303\">";
    temp+="<param name=\"CONTROLS\" value=\"ImageWindow,ControlPanel,StatusBar\">";
    temp+="<param name=\"MAINTAINASPECT\" value=\"true\">";
    temp+="<param name=\"SCRIPTCALLBACKS\" VALUE=\"OnPresentationClosed,OnErrorMessage\">";
    //temp+="<embed src=\"plugin.rpm\" WIDTH=482 HEIGHT=303 NOJAVA=true CONTROLS=ImageWindow CONSOLE=one AUTOSTART=true>";
    temp+="<embed name=\"realplayer\" type=\"audio/x-pn-realaudio-plugin\" width=\"482\" height=\"303\" scriptcallbacks=\"OnPresentationClosed,OnErrorMessage\" maintainaspect=\"true\" controls=\"ImageWindow,ControlPanel,StatusBar\"></embed>";
    temp+="</object>";
    document.getElementById("realPlayerDiv").innerHTML=temp;
    //$("#realPlayerDiv").html(temp);
    realCreated=true;
}

function startPlayer(){setTimeout("startPlaying()",1000);}
function switchView(div,setting){$(div).css("display",setting);}
function turnAllOff(){switchView("#imgSplash","none");switchView("#splashDiv","none");switchView("#imgMainBottom","none");switchView("#flvPlayerDiv","none");switchView("#mp3PlayerDiv","none");switchView("#realPlayerDiv","none");}
function showSplash(){turnAllOff();switchView("#imgSplash","block");switchView("#splashDiv","block");switchView("#imgMainBottom","block");}
function showVid() {turnAllOff();switchView("#flvPlayerDiv","block");}
function showAud() {turnAllOff();switchView("#mp3PlayerDiv","block");}
function showReal() {turnAllOff();switchView("#realPlayerDiv","block");}
function echo(object) {alert(object);}
function stopAll(){stopMP3();stopFlv();stopReal();}

function playFlv(object) 
{
    if(!vidCreated)
    {
        var temp=createFlash();
        showVid();
        if(temp==0)
        {
            numErrors=0;
            setTimeout("startFlv('" + object + "')",500);
        }
    }
    else
    {
        numErrors=0;
        setTimeout("startFlv('" + object + "')",500);
    }
}


function startFlv(object)
{
    try
    {
        stopAll();
	    thisMovie("saintsplayer").playFlv(null);
        showVid();
        thisMovie("saintsplayer").playFlv(staticSite + object);
        videoPlaying = true;
    }
    catch(e)
    {
        numErrors++;
        if(numErrors==5)
        {
            $.post("/layouts/systemitems/reportclientsideerror.aspx",{ex:dumpProps(e)});
            alert('There was an error starting the video.  The Saints have been notified.  Please try again soon.');
        }
        else
        {
            setTimeout("startFlv('" + object + "')",500);
        }
    }
}

function pauseFlv() {showVid();thisMovie("saintsplayer").pauseFlv();}
function unPauseFlv() {showVid();thisMovie("saintsplayer").unPauseFlv();}
function stopFlv() {if(vidCreated){showVid();try{thisMovie("saintsplayer").stopFlv();}catch(e){}}}

function playMP3(object,pos) 
{
    if(!mp3Created)
    {
        var temp=createMp3();
        showAud();
        if(temp==0)
        {
            numErrors=0;
            setTimeout("startMp3('" + object + "')",500);
        }
    }
    else
    {
        numErrors=0;
        setTimeout("startMp3('" + object + "')",500);
    }
}

function startMp3(object,pos)
{
    try
    {
        stopAll();
        showAud();
        thisMovie("mpplayer").playMP3(object,pos);
        mp3Playing = true;
    }
    catch(e)
    {
        numErrors++;
        if(numErrors==5)
        {
            $.post("/layouts/systemitems/reportclientsideerror.aspx",{ex:dumpProps(e)});
            alert('There was an error starting the audio.  The Saints have been notified.  Please try again soon.');
        }
        else
        {
            setTimeout("startMp3('" + object + "')",500);
        }
    }
}

function stopMP3(object) {if(mp3Created){try{thisMovie("mpplayer").stopMP3(object);}catch(e){}mp3Playing = false;}}

function playReal(object) {if(!realCreated){createReal();}showReal();numErrors=0;setTimeout("startReal('" + object + "')",500);}

function startReal(object)
{
    try
    {
        stopAll();
        showReal();
        document.realplayer.SetSource(object);
        document.realplayer.DoPlay();
        realPlaying  = true;
    }
    catch(e)
    {
        numErrors++;
        if(numErrors==5)
        {
            alert(e);
            alert('There was an error starting the video.  The Saints have been notified.  Please try again soon.');
        }
        else
        {
            setTimeout("startReal('" + object + "')",500);
        }
    }
}

function stopReal(){if(realCreated){try{document.realplayer.DoStop();}catch(e){}mp3Playing = false;}}

function videoComplete() {if(videoPlaying){showSplash();}videoPlaying = false;}
function mp3Complete() {if(mp3Playing){showSplash();}mp3Playing = false;}

function OnPresentationClosed(){if(realPlaying){showSplash();}realPlaying = false;}
function OnErrorMessage(severity,rma_code,user_code,user_string,more_info_url,error){alert(error);}

function thisMovie(movieName) {var isIE = navigator.appName.indexOf("Microsoft") != -1;return (isIE) ? window[movieName] : document[movieName];}
function dumpProps(obj) {var msg ="";for (var i in obj) {msg += i + ":" + obj[i] + "\n";if (typeof obj[i] == "object") { msg+=dumpProps(obj[i], i);}}return msg;}