
// the below script is supposed to have the following work flow :
//
// { detect for flash version 8 or greater}
//        if(Flash 8 >) 
//                then play in 8
//        else
//             {detect for WMP 9 or greater}
//              if(WMV 9 >)
//                  then play WMP display get flash link    
//              else
//                  display get flash link.
//

//seting up the member variables...
var versionFlash = 8;
var versionWMV = 9;
var agt = navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);
var opera = (agt.indexOf("Opera")!= -1);

//the list that will contain a comma seperated 
var pluginlist ="";

//checkin to see what browser we are working with and building a list of string.  
if (ie)
{	
    //alert("ie");    
    if(detectIEFlash("ShockwaveFlash.ShockwaveFlash") )
    {
        pluginlist += "Flash";
    }
    
    /*
    if(detectIEWMV("WMPlayer.OCX"))
    {
        pluginlist += "WindowsMediaPlayer";
    }
    */
    
    //alert(pluginlist);
}
else if (ns) 
{   
   //alert("ns");
   if(detectNSFlash("Shockwave Flash"))
	{
	    pluginlist += "Flash";
	}
	
	/*
	if(detectNSWMV("Windows Media Player Plug-in Dynamic Link Library"))
	{
	    pluginlist += "WindowsMediaPlayer";
	}
	*/
	
	//alert(pluginlist);
}
else
{
    //alert("other");
    nse = ""; 
	for (var i=0;i<navigator.mimeTypes.length;i++) 
	{
	    nse += navigator.mimeTypes[i].type.toLowerCase();
	}   
	pluginlist = otherDetect("application/x-shockwave-flash","Flash"); /*+ otherDetect("application/x-mplayer2","WindowsMediaPlayer");*/
	
	pluginlist = pluginlist.substring(0,pluginlist.length-1);
	
	//alert(pluginlist); 
}

//helper function for I.E that detects false player.. returns true or false. checking for versions
function detectIEFlash(ClassID) 
{ 
    result = false; 
    var fullVersion;
   
    try 
    {
		// version will be set for 9.X or greater players
		var axo = new ActiveXObject(ClassID);
		fullVersion = axo.GetVariable("$version");
	} 
	catch (e) {}
    if(fullVersion)
    {
        version = fullVersion.substring(3,fullVersion.length-7);
        
        var tempArray = fullVersion.split(' ');
        
        if(tempArray.length>1)
        	version = tempArray[1];
        	
        tempArray = version.split(',');
        if(tempArray.length>0)
        	version = tempArray[0];
        	
        if(!isNaN(version))
        {
            if(version >= versionFlash)
            {   //alert(version +" " + versionFlash);
                result = true;
            }
        }
    }
	return result;   
}

//helper function for I.E that detects WMV player.. returns true or false. checks the version.
function detectIEWMV(ClassID) 
{ 
    v_mediaplayer = 0;
    result = false; 
    
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('set myObject = CreateObject("' + ClassID + '")\n');
	document.write('result = ( IsObject(myObject))\n');
	document.write('v_mediaplayer = myObject.versionInfo\n');
	document.write('</SCR' + 'IPT\> \n');
	//alert(v_mediaplayer);
	if(v_mediaplayer >= 9);
	    result = true;
    
    return false;
}

//helper function for detection other for moz returns true or false depending on flash/version.
function detectNSFlash(ClassID) 
{ 
    result = false;
    var flashVersion = 0;
    var thePlugin = navigator.plugins[ClassID]; 
    if(thePlugin)
    {
        if(thePlugin.description)
        {
            flashVersion = parseInt( thePlugin.description.replace( /^[^\d]*/,'')); 
            //alert(flashVersion);
        }
    }
    if(flashVersion >= versionFlash)
    {
        result = true;
    }
    return result;
 }

//helper function for detection for wmp in mozilla no version check??
function detectNSWMV(ClassID)
{
    result = false;
    var wmpPlugin = navigator.plugins[ClassID]; 
    if(wmpPlugin)
    {
         if(wmpPlugin.description)
         {
            result = true;
         }
     }
     return false;
}


//used for other broswers no version check here just sees if the plugin is avalible.
function otherDetect(ClassID,name)
{
    n = ""; 
    if (nse.indexOf(ClassID) != -1)
    {
        if (navigator.mimeTypes[ClassID].enabledPlugin != null) 
        {
            n = name+","; 
        }
        return n;
    }
}


//function checks which plug in is installed and acts accordingly.
function cookieDetect()
{
	if(navigator.userAgent.toLowerCase().indexOf("iphone") != -1)
	{
			  var obj = document.getElementById('playerwrap');
			  obj.innerHTML = '<div> <br> <EMBED SRC=\"http://media1.break.com/dnet/media/'+sGlobalContentFilePath+'/'+sGlobalFileName+'.jpg\" HREF=\"http://media1.break.com/dnet/media/'+sGlobalContentFilePath+'/'+sGlobalFileName+'.mp4\" TYPE=\"video/mp4\" TARGET=\"myself\" SCALE=\"1\"><br/><br/></div>';
	}
	else
	{
	    if(pluginlist)//making sure the pluginlist var is valid
	    {
	        if((pluginlist.indexOf("Flash")!=-1))
	        {
		        flashOutPut();
		        hideVideoSettingDiv();   
		}
	        else
	        {
	            nothingActivate();
	        }
	    }
	    else
	    {
	        nothingActivate();
	    } 
	}
}

function nothingActivate()
{
  obj = document.getElementById('defaultDiv');
  obj.innerHTML = '<div style="float;left;width:464px;"><a href="http://www.adobe.com/products/flashplayer/" target="_blank" style="text-decoration:none;"><img src="http://media1.break.com/static/live/v1/img/getflash/flash_icon_lrg.gif" border="0"/><br/>Get Flash</a><br/><br/><br/><br/></div>';
  hideVideoSettingDiv();
}

function hideVideoSettingDiv()
{
	var vsettingsDiv = document.getElementById('videoSettingDiv');
	if(vsettingsDiv != null)
	{
		vsettingsDiv.style.display="none";
	}
}

/////get cookie set cookie functions...////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 10000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : ".break.com" ) +
		( ( secure ) ? ";secure" : "" );
}



