
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=320, height=347,  resizable=no" );
	} else {
		//  AOL 9.0 and higher have SnugFit
		document.location.href = MiniUrl;
	}
}

  
function _DL_OpenFullMXID ( server, mxid) {
	var FullUrl = "http://" + server + "/video.index.adp?mxid=" + mxid;
	FullUrl +=  "&referer=" + escape( this.restartUrl) + "&_AOLFORM=w708.h344.p7.R10";
	this.OpenFull(FullUrl);
}

function _DL_OpenFullPMMSID ( server, pmmsid) {
	var FullUrl = "http://" + server + "/video.index.adp?pmmsid=" + pmmsid;
	FullUrl +=  "&referer=" + escape( this.restartUrl) + "&_AOLFORM=w708.h344.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
		if (window.name == "_dlplayer") {
			// prevent multiple instantiation
			window.name = "";
		} 
		window.open( FullUrl, "_dlplayer", 
			"width=708, height=344, resizable=no" );
	} else {
		//  AOL 9.0 and higher have SnugFit
		document.location.href = FullUrl;
	}
}

function _DL_OpenAudioFullMXID( server, mxid ) {
	var AudioFullUrl = "http://" +server +  "/audio.index.adp?mxid=" + mxid +  "&referer=" + escape( this.restartUrl) + "&_AOLFORM=w708.h344.p7.R37";
	this.OpenAudioFull( AudioFullUrl );
}

function _DL_OpenAudioFullPMMSID( server, pmmsid ) {
	var AudioFullUrl = "http://" +server +  "/audio.index.adp?pmmsid=" + pmmsid +  "&referer=" + escape( this.restartUrl) + "&_AOLFORM=w708.h344.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
		if (window.name == "_dlplayer") {
			// prevent multiple instantiation
			window.name = "";
		} 
		window.open( AudioFullUrl, "_dlplayer", 
			"width=708, height=344, resizable=no" );
	} else {
		//  AOL 9.0 and higher have SnugFit
		document.location.href = AudioFullUrl;
	}
}

function _DL_OpenTop11Show( server, type, start ) {
	var FullUrl = "http://" + server + "/top11show.adp?type=";
	if (type != null) {
		FullUrl += type;
	} else {
		FullUrl += "nsv";
        }
	if (start != null && start != "0") {
		FullUrl += "&start=" + start;
	} 

	FullUrl +=  "&referer=" + escape( this.restartUrl) + "&_AOLFORM=w708.h344.p7.R10";
	this.OpenFull(FullUrl);
}

function _DL_OpenPlaylist(server, pls, start, startid ) {
	var FullUrl = "http://" + server + "/video.index.adp?pls=" + pls;
	if (start != null) {
		FullUrl += "&start=" + start;
	} 
	if (startid != null) {
		FullUrl += "&startid=" + startid;
	} 

	FullUrl +=  "&referer=" + escape( this.restartUrl) + "&_AOLFORM=w708.h344.p7.R10";
	this.OpenFull(FullUrl);
}

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=325, height=110, 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 );
	this.OpenAudioMini( AudioMiniUrl );
}

function _DL_OpenMiniEasy(asset_or_id, title, brandurl, scroll_array, franchise) {
	if (franchise != null)
		this.franchise = franchise;

	var MiniUrl = this.GenMiniUrl( asset_or_id, title, brandurl, scroll_array );
	this.OpenMini( MiniUrl );
}

function _DL_GenMiniUrl( asset_or_id, title, brandurl, scroll_array ) {
        var anum = /^\d+$/;
        var isPmmsId = anum.test(asset_or_id);

	var rv = "http://" + this.DLServer + "/" + "video.mini.adp?";
	if (isPmmsId) {
		rv += "pmmsid=" + asset_or_id; 
	} else {
		rv += "stream=" + escape(asset_or_id);
    
		if (scroll_array && scroll_array.length ) {
			for (var i = 0; i < scroll_array.length; i++ ) {
			rv += "&scroll" + (i + 1) + "=" + escape( scroll_array[i] );
      			}
		}
	}
    
	rv += "&title=" + escape( title );
	rv += "&logo=" + escape( brandurl );
	rv += "&restarturl=" + escape( this.restartUrl );
	rv += "&referer=" + escape( this.restartUrl );
        if (this.franchise != "unused")
		rv += "&franchise=" + escape(this.franchise);
	rv += "&_AOLFORM=w325.h348.p7.R10";
	return rv;
}

function _DL_GenMiniAudioUrl( asset_or_id, title, brandurl, scroll_array ) {
	var anum = /^\d+$/;
	var isPmmsId = anum.test(asset_or_id);

	var rv = "http://" + this.DLServer + "/" + "audio.mini.adp?";
	if (isPmmsId) {
		rv += "pmmsid=" + asset_or_id; 
	} else {
		rv += "stream=" + escape(asset_or_id);
    
		if (scroll_array && scroll_array.length ) {
			for (var i = 0; i < scroll_array.length; i++ ) {
			rv += "&scroll" + (i + 1) + "=" + escape( scroll_array[i] );
      			}
		}
	}
    
	rv += "&title=" + escape( title );
	rv += "&logo=" + escape( brandurl );
	rv += "&_AOLFORM=w325.h110.p7.R10";
	return rv;
}

function _DL_GenIframeUrl( asset_or_id, scroll_array ) {
	var anum = /^\d+$/;
	var isPmmsId = anum.test(asset_or_id);

	var rv = "http://" + this.DLServer + "/_dl_main.adp?";

	if ( isPmmsId ) {
		rv += "pmmsid=" + asset_or_id;
	} else {
		rv += "stream=" + escape ( asset_or_id );
		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 += "&collection=" + escape(scroll_array[1]);
				rv += "&scroll2=" + escape(scroll_array[1]);
			}
	 
			if ( scroll_array.length >= 3 ) {
				rv += "&title=" + escape(scroll_array[2]);
				rv += "&scroll3=" + escape(scroll_array[2]);
			}
		}
	}

	rv += "&mediatype=" + this.type;
	if ( this.isLive ) {
		rv += "&livestream=1";
	}
	else {
		rv += "&livestream=0";
	}

	if (this.franchise != "unused") {
		rv += "&franchise=" + escape(this.franchise);
	}
	rv += "&size=" + this.size;
        if (this.skin != null && this.skin != "undefined")
		rv += "&skin=" + this.skin;
	rv += "&restartUrl=" + escape(this.restartUrl);
	rv += "&referer=" + escape(this.restartUrl);
	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_MEDIUM:
      document.write ( " width=320 height=304 " );
      break;
    case _DL_VIDEO_LARGE:
      document.write ( " width=324 height=321 " );
      break;
    case _DL_VIDEO_SMALL:
      document.write ( " width=178 height=156 " );
      break;
    case _DL_VIDEO_WIDESCREEN:
      document.write ( " width=372 height=288 " );
      break;
    case _DL_VIDEO_SUPER_LARGE:
      document.write ( " width=642 height=560 " );
      break;
    }
  }
  else {
    document.write( " name=\"Audio Embedded\" ");
    switch (this.size) {
    
    case _DL_AUDIO_LARGE:
      document.write ( " width=320 height=77 " );
      break;
    case _DL_AUDIO_SMALL:
      document.write ( " width=176 height=23 " );
      break;
    }
  }
  
  document.write ( " frameborder=0 marginwidth=0 marginheight=0 scrolling=no border=1 style='overflow:hidden;position:relative; top:0px; left:0px;'  ></iframe>");
  

}

var _DL_VIDEO_OLD_MEDIUM   = "1";
var _DL_VIDEO_LARGE     = "large";
var _DL_VIDEO_SMALL     = "small";

var _DL_VIDEO_WIDESCREEN       = "widescreen";
var _DL_VIDEO_SUPER_LARGE  = "superlarge";

var _DL_AUDIO_LARGE  = "large";
var _DL_AUDIO_SMALL  = "small";


function _DL_Play( asset_or_id, aScrollText  ) {
	this.Init(this.type);
	this.isPlaying = true;   
	this.Asset      = asset_or_id;
	this.scrollText = aScrollText;

	document.getElementById( "_DL_IFRAME_" ).src =
	      this.GenIframeUrl( asset_or_id, 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.type        = "video";
    this.skin        = "blue";
    this.restartUrl  = document.location; 
    this.franchise   = "unused"
    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.OpenFullPMMSID = _DL_OpenFullPMMSID;
    this.OpenFull     = _DL_OpenFull;
    this.OpenAudioFull = _DL_OpenAudioFull;
    this.OpenAudioFullMXID = _DL_OpenAudioFullMXID;
    this.OpenAudioFullPMMSID = _DL_OpenAudioFullPMMSID;
    this.OpenAudioMini = _DL_OpenAudioMini;
    this.OpenTop11Show = _DL_OpenTop11Show;
    this.OpenPlaylist = _DL_OpenPlaylist;
    this.GenIframeUrl  = _DL_GenIframeUrl;

    this.PlayVideoOldMedium = _DL_PlayVideoOldMedium;
    this.PlayVideoLarge     = _DL_PlayVideoLarge;
    this.PlayVideoSmall     = _DL_PlayVideoSmall;

    this.PlayAudioLarge     = _DL_PlayAudioLarge;
    this.PlayAudioSmall     = _DL_PlayAudioSmall;
}

// Video Embedded Widgets
function _DL_PlayVideoOldMedium( asset_or_id, skin) {
	this.type = "video";
	this.size = _DL_VIDEO_OLD_MEDIUM;
	this.skin = skin;
	this.Play( asset_or_id );
}

function _DL_PlayVideoLarge( asset_or_id, scrollarray, skin ) {
	this.type = "video";
	this.size = _DL_VIDEO_LARGE;
	this.skin = skin;
	this.Play(asset_or_id, scrollarray );
}

function _DL_PlayVideoSmall( asset, skin) {
	this.type = "video";
	this.size = _DL_VIDEO_SMALL;
	this.skin = skin;
	this.Play( asset );
}

function _DL_PlayAudioLarge( asset, scrollarray, skin ) {
	this.type = "audio";
	this.size = _DL_AUDIO_LARGE;
	this.skin = skin;
	this.Play( asset , scrollarray);
}

function _DL_PlayAudioSmall( asset, skin ) {
	this.type = "audio";
	this.size = _DL_AUDIO_SMALL;
	this.skin = skin;
	this.Play( asset , 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();
