function _DL_OpenMiniOrReal ( MiniUrl, RealUrl ) {
    if ( this.UA.isWindows ) {
      this.OpenMini(MiniUrl);
    }
    else {
        // use Real for Mac
	document.location.href = RealUrl;
    }
}


function _DL_OpenMini( MiniUrl ) {
  if ( !this.UA.isAOL9Plus ){
    // Must set the window attributes and size for pre-AOL 9.0 
    //and out of client Windows users
    window.open( MiniUrl, "playerwin", 
		 "width=388, height=380,  resizable=no" );
  }
  else {
    //  AOL 9.0 and higher have SnugFit
    document.location.href = MiniUrl;
  }
}

  
function _DL_OpenFullMXID ( server, mxid ) {

  var FullUrl = "http://" + server + "/dalaillama/video.index.adp?mxid=" +
    mxid + "&_AOLFORM=w656.h390.p7.R10";
  this.OpenFull(FullUrl);
}

function _DL_OpenFull( FullUrl ) {

  if ( !this.UA.isAOL9Plus ){
    // Must set the window attributes and size for pre-AOL 9.0 
    // and out of client users
    window.open( FullUrl, "playerwin", 
		 "width=650, height=388, resizable=no" );
  }
  else {
    //  AOL 9.0 and higher have SnugFit
    document.location.href = FullUrl;
  }
}

function _DL_OpenAudioFullMXID( server, mxid ) {
  var AudioFullUrl = "http://" +server +  "/dalaillama/audio.index.adp?mxid=" +
    mxid + "&_AOLFORM=w604.h305.p7.r37";
  this.OpenAudioFull( AudioFullUrl );
}

function _DL_OpenAudioFull ( AudioFullUrl ) {
  if ( !this.UA.isAOL9Plus ){
    // Must set the window attributes and size for pre-AOL 9.0 
    // and out of client users
    window.open( AudioFullUrl, "playerwin", 
		 "width=650, height=380, resizable=no" );
  }
  else {
    //  AOL 9.0 and higher have SnugFit
    document.location.href = AudioFullUrl;
  }
}


function _DL_OpenAudioMini ( AudioMiniUrl ) {
  if ( !this.UA.isAOL9Plus ){
    // Must set the window attributes and size for pre-AOL 9.0 
    // and out of client users
    window.open( AudioMiniUrl, "playerwin", 
		 "width=650, height=380, resizable=no" );
  }
  else {
    //  AOL 9.0 and higher have SnugFit
    document.location.href = AudioMiniUrl;
  }
}

function _DL_OpenAudioMiniEasy( asset, title, brandurl, scroll_array ) { 
  var AudioMiniUrl = this.GenMiniAudioUrl( asset, title, brandurl, scroll_array );
  ///	alert (AudioMiniUrl );
  this.OpenAudioMini( AudioMiniUrl );
}

	
  
function _DL_OpenMiniEasy( asset, title, brandurl, scroll_array ) {
  var MiniUrl = this.GenMiniUrl( asset, title, brandurl, scroll_array );
  this.OpenMini( MiniUrl );
}
    
			    

function _DL_GenMiniUrl( asset, title, brandurl, scroll_array ) {
    var rv = 
      "http://" + this.DLServer + "/" +
      "video.mini.adp?" +
      "stream=" + escape(asset) +
      "&logo="  + escape( brandurl ) +
      "&title=" + escape( title );
    
    if (scroll_array && scroll_array.length ) {
      for (var i = 0; i < scroll_array.length; i++ ) {
	rv += "&scroll" + (i + 1) + "=" + escape( scroll_array[i] );
      }
    } 
    
    rv += "&_AOLFORM=w388.h380.p7.R10";
    return rv;
}

function _DL_GenMiniAudioUrl( asset, title, brandurl, scroll_array ) {
    var rv = 
      "http://" + this.DLServer + "/" +
      "audio.mini.adp?" +
      "stream=" + escape(asset) +
      "&logo="  + escape( brandurl ) +
      "&title=" + escape( title );
    
    if (scroll_array && scroll_array.length ) {
      for (var i = 0; i < scroll_array.length; i++ ) {
	rv += "&scroll" + (i + 1) + "=" + escape( scroll_array[i] );
      }
    } 
    
    rv += "&_AOLFORM=w388.h380.p7.R10";
    return rv;
}

function _DL_GenIframeUrl( asset, type, scroll_array ) {
    // Real files end with .rm, .ra, or .smil
    var RealRegEx = /\.rm$|\.ra$|\.smil$|\.mpg$|\.mpeg$/;

    // Quicktime ends with .mov
    var QtRegEx   = /\.mov$/;
    
    // A single unsv url starts with unsv://
    // (both for on demand and live)
    var UNSVRegEx = /^unsv/;

    var rv = "http://" + this.DLServer + "/_dl_main.adp?";

     if ( RealRegEx.test( asset ) || QtRegEx.test(asset) || UNSVRegEx.test(asset) ) {
  	  rv += "stream=" + escape ( asset );
     }
     else {
       if (type == "video" ) {
	 // on demand NSV
	 
	 var stream350 = escape ( "/uvox?cachefile=" + asset + "_350.nsv" );
	 var stream220 = escape ( "/uvox?cachefile=" + asset + "_220.nsv" );
	 var stream120 = escape ( "/uvox?cachefile=" + asset + "_120.nsv" );
	 var stream36  = escape ( "/uvox?cachefile=" + asset + "_36.nsv" );
	 var stream26  = escape ( "/uvox?cachefile=" + asset + "_26.nsv" );
	 
	 rv   += "multiplex=1&stream=%2ensv&br1=350&url1=" +	stream350 + 
	   "&br2=220&url2=" + stream220 +
	   "&br3=120&url3=" + stream120 + 
	   "&br4=36&url4=" + stream36 +
	   "&br5=26&url5=" + stream26;
       }
       else {
	   //NSA
	   var stream64 = escape ( "/uvox?cachefile=" + asset + "_64.nsa" );
	   var stream48 = escape ( "/uvox?cachefile=" + asset + "_48.nsa" );
	   var stream16 = escape ( "/uvox?cachefile=" + asset + "_16.nsa" );
	   
	   if ( this.size == _DL_AUDIO_LARGE ) {
	     rv  += "multiplex=1&stream=%2ensa&br1=64&url1=" + stream64 + 
	       "&br2=48&url2=" + stream48 +
	       "&br3=16&url3=" + stream16;
	   }
	   else {
	     // The small audio widgets don't have room to display the 
	     // the bandwidth select form
	     rv  += "multiplex=1&stream=%2ensa&br1=16&url1=" + stream16;
	   }	 
	 }
       }
       
       if ( scroll_array ) {
	 if ( scroll_array.length >= 1 ) {
	   rv +=   "&author=" + escape(scroll_array[0]);
	   rv +=   "&scroll1=" + escape(scroll_array[0]);
	 }
	 
	 if ( scroll_array.length >= 2 ) {
	   rv += "&title=" + escape(scroll_array[1]);
	   rv += "&scroll2=" + escape(scroll_array[1]);
	 }
	 
       if (scroll_array.length >= 3 ) {
	 rv += "&collection=" + escape(scroll_array[2]);
	 rv += "&scroll3=" + escape(scroll_array[2]);

       }
     }

     rv += "&mediatype=" + type;
     if ( this.isLive ) {
       rv += "&livestream=1";
     }
     else {
       rv += "&livestream=0";
     }


     rv += "&size=" + this.size;

     rv += "&skin=" + this.skin;
     rv += "&restartUrl=" + escape(document.location);

     return rv;
}



function _DL_Init( type ) {

  if ( this.initialized ) {
    return; // been there, done that.
  }
  else {
    this.initialized = true;
  }
  document.write( "<iframe id='_DL_IFRAME_' " );
  
  if ( type == "video" ) {
    document.write( " name=\"Video Embedded\" ");
    switch ( this.size ) {
    case _DL_VIDEO_OLD_LARGE:
      document.write ( " width=380 height=350 " );
      break;
    case _DL_VIDEO_OLD_MEDIUM:
      document.write ( " width=320 height=300 " );
      break;
    case _DL_VIDEO_OLD_SMALL:
      document.write ( " width=176 height=168 " );
      break;
    case _DL_VIDEO_LARGE:
      document.write ( " width=320 height=317 " );
      break;
    case _DL_VIDEO_MEDIUM:
      document.write ( " width=176 height=188 " );
      break;
    case _DL_VIDEO_SMALL:
      document.write ( " width=176 height=155 " );
      break;
    }
  }
  else {
    document.write( " name=\"Audio Embedded\" ");
    switch (this.size) {
    
    case _DL_AUDIO_LARGE:
      document.write ( " width=320 height=77 " );
      break;
    case _DL_AUDIO_MEDIUM:
      document.write ( " width=176 height=58 " );
      break;
    case _DL_AUDIO_SMALL:
      document.write ( " width=176 height=23 " );
      break;
    }
  }
  
  document.write ( " allowtransparency=true frameborder=0 scrolling=no border=0 style='border:1px solid #000000;overflow:hidden;position:relative; top:0px; left:0px;'  ></iframe>");
  

}

var _DL_VIDEO_OLD_LARGE = "";
var _DL_VIDEO_OLD_MEDIUM   = "1";
var _DL_VIDEO_OLD_SMALL = "2";
var _DL_VIDEO_LARGE     = "large";
var _DL_VIDEO_MEDIUM       = "medium";
var _DL_VIDEO_SMALL     = "small";

var _DL_AUDIO_LARGE  = "large";
var _DL_AUDIO_MEDIUM = "medium";
var _DL_AUDIO_SMALL  = "small";


function _DL_Play( sAsset, type, aScrollText  ) {
       this.Init(type);
       this.isPlaying = true;   
       this.Asset      = sAsset;
       this.scrollText = aScrollText;
       document.getElementById( "_DL_IFRAME_" ).src =
	      this.GenIframeUrl( sAsset, type, aScrollText ) ;
}






function DalaiLlama() {

    this.size  = _DL_VIDEO_LARGE;
    this.autoplay = true;
    this.isPlaying = false;
    this.initialized = false;
    this.DLServer = "mp.aol.com";

    this.isLive   = false;

    this.skin        = "blue";
    this.Play        = _DL_Play;
    this.Init        = _DL_Init;
    this.UA          = new _DLUserAgent();
    this.OpenMiniOrReal = _DL_OpenMiniOrReal;

    this.GenMiniAudioUrl = _DL_GenMiniAudioUrl;
    this.GenMiniUrl      = _DL_GenMiniUrl;

    this.OpenMini   = _DL_OpenMini;
    this.OpenMiniEasy  = _DL_OpenMiniEasy;
    this.OpenAudioMiniEasy = _DL_OpenAudioMiniEasy;

    this.OpenFullMXID = _DL_OpenFullMXID;
    this.OpenFull     = _DL_OpenFull;
    this.OpenAudioFull = _DL_OpenAudioFull;
    this.OpenAudioFullMXID = _DL_OpenAudioFullMXID;
    this.OpenAudioMini = _DL_OpenAudioMini;
    this.GenIframeUrl  = _DL_GenIframeUrl;

    this.PlayVideoOldLarge  = _DL_PlayVideoOldLarge;
    this.PlayVideoOldMedium = _DL_PlayVideoOldMedium;
    this.PlayVideoOldSmall  = _DL_PlayVideoOldSmall;
    this.PlayVideoLarge     = _DL_PlayVideoLarge;
    this.PlayVideoMedium    = _DL_PlayVideoMedium;
    this.PlayVideoSmall     = _DL_PlayVideoSmall;

    this.PlayLiveVideoOldLarge  = _DL_PlayLiveVideoOldLarge;
    this.PlayLiveVideoOldMedium = _DL_PlayLiveVideoOldMedium;
    this.PlayLiveVideoOldSmall  = _DL_PlayLiveVideoOldSmall;
    this.PlayLiveVideoLarge     = _DL_PlayLiveVideoLarge;
    this.PlayLiveVideoMedium    = _DL_PlayLiveVideoMedium;
    this.PlayLiveVideoSmall     = _DL_PlayLiveVideoSmall;



    this.PlayAudioLarge     = _DL_PlayAudioLarge;
    this.PlayAudioMedium    = _DL_PlayAudioMedium;
    this.PlayAudioSmall     = _DL_PlayAudioSmall;
}

/*
function _DL_PlayAudioLarge( asset, scrollarray ) {
  this.size = _DL_AUDIO_LARGE;
  this.Play( asset, "video", scrollarray );
}

function _DL_PlayAudioMedium( asset, scrollarray ) {
  this.size = _DL_AUDIO_MEDIUM;
  this.Play( asset, "video",  scrollarray );
}

function _DL_PlayAudioSmall( asset ) {
  this.size = _DL_AUDIO_SMALL;
  this.Play( asset, "video" );
}
*/

function _DL_PlayVideoOldLarge( asset, scrollarray ) {
  this.size = _DL_VIDEO_OLD_LARGE;
  this.Play( asset, "video", scrollarray );
}


function _DL_PlayVideoOldMedium( asset ) {
  this.size = _DL_VIDEO_OLD_MEDIUM;
  this.Play( asset, "video" );
}

function _DL_PlayVideoOldSmall( asset ) {
  this.size = _DL_VIDEO_OLD_SMALL;
  this.Play( asset, "video" );
}

function _DL_PlayVideoLarge( asset, scrollarray, skin ) {
  this.size = _DL_VIDEO_LARGE;
  this.skin = skin;
  this.Play(asset, "video", scrollarray );
}

function _DL_PlayVideoMedium( asset, scrollarray, skin ) {
  this.size = _DL_VIDEO_MEDIUM;
  this.skin = skin;
  this.Play(asset, "video",  scrollarray );
}

function _DL_PlayVideoSmall( asset, skin ) {
  this.size = _DL_VIDEO_SMALL;
  this.skin = skin;
  this.Play( asset , "video");
}

function _DL_PlayLiveVideoOldLarge( asset, scrollarray ) {
  this.size = _DL_VIDEO_OLD_LARGE;
  this.isLive = true;
  this.Play( asset, "video", scrollarray );
}


function _DL_PlayLiveVideoOldMedium( asset ) {
  this.size = _DL_VIDEO_OLD_MEDIUM;
  this.isLive = true;
  this.Play( asset, "video" );
}

function _DL_PlayLiveVideoOldSmall( asset ) {
  this.size = _DL_VIDEO_OLD_SMALL;
  this.isLive = true;
  this.Play( asset, "video" );
}

function _DL_PlayLiveVideoLarge( asset, scrollarray, skin ) {
  this.size = _DL_VIDEO_LARGE;
  this.isLive = true;
  this.skin = skin;
  this.Play(asset, "video", scrollarray );
  
}

function _DL_PlayLiveVideoMedium( asset, scrollarray, skin ) {
  this.size = _DL_VIDEO_MEDIUM;
  this.isLive = true;
  this.skin = skin;
  this.Play(asset, "video",  scrollarray );
}

function _DL_PlayLiveVideoSmall( asset, skin ) {
  this.size = _DL_VIDEO_SMALL;
  this.isLive = true;
  this.skin = skin;
  this.Play( asset , "video");
}


function _DL_PlayAudioLarge( asset, scrollarray, skin ) {
  this.size = _DL_AUDIO_LARGE;
  this.skin = skin;
  this.Play( asset , "audio", scrollarray);
}


function _DL_PlayAudioMedium( asset, scrollarray, skin ) {
  this.size = _DL_AUDIO_MEDIUM;
  this.skin = skin;
  this.Play( asset , "audio", scrollarray);
}


function _DL_PlayAudioSmall( asset, skin ) {
  this.size = _DL_AUDIO_SMALL;
  this.skin = skin;
  this.Play( asset , "audio", null);
}

function _DLUserAgent() {	
    this.UAString  = navigator.userAgent.toLowerCase();
    this.isAOL     =  (this.UAString.indexOf("aol") != -1);
    this.isAOL8    =  (this.UAString.indexOf("aol 8.0") != -1);
    this.isAOL7    =  (this.UAString.indexOf("aol 7.0") != -1);
    this.isAOL6    =  (this.UAString.indexOf("aol 6.0") != -1);
    this.isAOL5    =  (this.UAString.indexOf("aol 5.0") != -1);
    this.isAOL4    =  (this.UAString.indexOf("aol 4.0") != -1);
    this.isAOL3    =  (this.UAString.indexOf("aol 3.0") != -1);
    this.isGecko   =  (this.UAString.indexOf("gecko") != -1);

    this.isWindows = (this.UAString.indexOf("windows") != -1);
    
    this.isAOL9Plus = (this.isAOL && !this.isAOL8 && !this.isAOL7 && 
		       !this.isAOL6 && !this.isAOL5 && !this.isAOL4 && 
		       !this.isAOL3 );
}



var DalaiLlama = new DalaiLlama();

