
//
// showPlayer
//
function showPlayer(info, promoText, hasWMP) 
{
    var o = '';
    
    var flash_version = get_flash_version();
    if (flash_version < 8)
    {
        o += '<div style="width:574px; height:352px; background-color:#ccc; border: 1px solid black;">'
                + '<div style="text-align: center; margin-top: 50px; padding: 10px;">'
                + 'For the best viewing experience, please upgrade to Flash Player 8 or'
                + ' higher.';
                
                
        if (flash_version > 1)
        	o += ' Current version installed is Flash Player ' + flash_version + '.';
        	
		o += '</p><p>Upgrade at <a h' + 'ref="http://www.adobe.com/go/getflashplayer">http://www.adobe.com/go/getflashplayer</a></p></div></div>';

        document.write (o);
        return;
    }

    // PATH TO PLAYER GOES HERE.
    // make sure that this is served from www.wral.com for Flash/JS communications
    var movie = '/presentation/v1/flash/video/videoplayer_VP2.swf?v=20080918';

    var parameters = '';
    if (info) parameters += 'videoInfo=' + info + '&';
    if (promoText) parameters += 'promoText=' + escape(promoText) + '&';
    if (!hasWMP) parameters += 'nowmp=true&';
    parameters += 'at=' + Cookie.get('at') + '&';

    parameters = parameters.substring(0, parameters.length - 1);

    // -- (1) width and height in the next line, AND below
    o += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="video_player" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="576" height="354">';

    o += '<param name="movie" value="' + movie + '" />';
    o += '<param name="FlashVars" value="' + parameters + '" />';

    o += '<param name="quality" value="high" />';

    // these are critical for site catalyst clickmap
    //o += '<param name="wmode" value="transparent" />';
    o += '<param name="allowScriptAccess" value="always" />';
    o += '<param name="allowFullScreen" value="true" />';
    o += '<param name="swLiveConnect" value="true" />';
    o += '<param name="wmode" value="opaque" />';

    o += '<embed name="video_player" s' + 'rc="' + movie + '" ';
    o += 'FlashVars="' + parameters + '" ';

    // -- (2) width and height in the next line, AND above
    o += 'wmode="opaque" allowScriptAccess="always" allowFullScreen="true" swLiveConnect="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="576" height="354"></embed>'
    o += '</object>';
    
    document.write(o);

}





//
// video_player_DoFSCommand -- gets called from the full player's
// fscommand; note that the function name prefix *must* match the
// swf's movie id
//
function video_player_DoFSCommand(command, args) {
    doFSCommand (command, args);
}


//
// showittome
//
function showittome(a,b,c)
{
    // for testing purposes
    var tajmaut=setTimeout("alert('sentFromFlash" + a[0] + a[1] + a[2] + "')",1);
}


//
// doFSCommand
//
function doFSCommand(args) 
{
    // args is an array with the first item being the command; this is for compatibility with the
    // ExternalInterface available in Flash 8.  With some browsers, Flash can call JavaScript
    // functions with arbitrary numbers of params, but with other browsers (IE6?) Flash can only
    // used one 

    var command = args.shift();


    // command might begin with FSCommand:, strangely.  maybe for local stuff?  maybe for safari?
    if (command.substring(0, 10) == 'FSCommand:') 
        command = command.substring(10);

    
    if (command == 'flashReady')   // the Flash sends this command once it has loaded and is setting up
    {
        vp2.flash_ready = true;
        
        if (vp2.analytics)
            setTimeout("vp2.send_analytics_to_vp()", 1);

        if (vp2.waiting_to_play)
            setTimeout("vp2.do_play_vid()", 2);
            
    }
    if (command == "setWMVURL") 
    {
        vp2.setWMVURL(args);
    }
    else if (command == 'ShutDownWMV') 
    {
        vp2.ShutDownWMV();
    } 
    else if (command == 'rateThis') 
    {
        vp2.rateThis(args);
    } 
    else if (command == 'emailThis')
    {
        vp2.emailThis(args);
    }
    else if (command == 'showWarning') 
    {
        // for error messages from the client
        alert(args);
    } 
    else if (command == 'setTitle') 
    { 
        // change the page title
        // should not apply in mini player.
        document.title = args;
    }
    else if (command == 'showAdFor')         // TODO FOR VP2
    {
        vp2.changeAd(args);
    }
    else if (command == 'displayAdHTML')     // TODO FOR VP2
    {
        var iframeElem = document.getElementById('video_display_ad');
        var iframeDoc = iframeElem.contentDocument || (iframeElem.contentWindow && iframeElem.contentWindow.document);
        iframeDoc.body.innerHTML = args;
        iframeDoc.body.style.backgroundColor = "transparent";
    }
    else if (command == 'onVideoPlay') 
    {
        if (stopReloadTimer != null)
        {
            stopReloadTimer();
        }
    }
    else if (command == 'onVideoStop') 
    {
        if (startReloadTimer != null)
        {
            startReloadTimer();
        }
    }
    else if (command == 'setAt')
    {
        //alert("at = " + args);
        Cookie.set('at',
                (args != '') ? args : '0',
                {domain:'.wral.com', path:'/', duration: 1});
    }
    else if (command == 'play_next_vid')
    {
        vp2.play_next_vid();
    }
    else if (command == 'get_next_vid_in_playlist')
    {
        return vp2.get_next_vid_in_playlist();
    }

}





var vp2 = {

			//  will be set after Flash has told us that it's initialized
	flash_ready: false,		
	
			//  set to true if trying to play vid before Flash has told us that it is initialized
	waiting_to_play: false,	
	
			// the video object that should be being played
	which_vid: {},

  			// the name of the playlist that currently playing vid is in
	last_played_playlist: null,

			// the index into the playlist
	last_played_n: -1,

  			// remember which div to use for next one
	next_vp_related_stuff: 0,

			// remember which div to use for next one
	next_vp_story_info: 0,
	
			// remember the analytics data that should be sent to the player so that they can be sent
			// once the player tells us that it is ready
	analytics: null,

			// which list of thumbs is being shown along the bottom; a number
	current_vid_list: null,
	
			// need this to compensate for the annoying Firefox scrollbars issues
	is_firefox: navigator.userAgent.indexOf('Firefox') != -1,

			// remember what the next index should be if a new playlist is encountered
	next_vid_section_num: 0,

			// should we be reloading the playlist data upon play of this video?
	reload_playlist: true,

			// for UI: are we currently hiding related stuff?
	isHidingRelatedStuff: false,

			// for UI: are we ready to show new stuff?  this may be set if data comes in
			// while hiding, and this flag should be checked after the hiding is complete
	readyForNextRelatedStuff: false,

			// an object of playlists (indexed by name) which includes an array of video objs
	__VIDS: {},



	//
	// play_vid(playlist_name_string, index_into_playlist)
	//
	play_vid: function(pn, vn, reload_playlist)
		{
			vp2.reload_playlist = reload_playlist;
		
			var which_vid = vp2.__VIDS[pn];
			if (which_vid)  // sanity check
			{
				which_vid = which_vid[vn];
		
				if (which_vid)
				{
					vp2.last_played_playlist = pn;
					vp2.last_played_n = vn;
					vp2.which_vid = which_vid;
					
					vp2.do_play_vid();
				}
			}
		},
		

		
	//
	// setclipboard
	//
	setclipboard: function(a)
		{
		
			if (navigator.appName.indexOf("Microsoft") != -1) {
				 window['video_player']._wral_vp_setClipboard(a);
			}
			else {
				 document['video_player']._wral_vp_setClipboard(a);
			}
			
			$('link_to_video').setHTML('Link copied to clipboard');
			$('link_to_video').setStyle('visibility', 'visible');  // Firefox gets mad otherwise.
		
			new Fx.Style($('link_to_video'), 'opacity', 
				{duration: 3000, 
				transition: Fx.Transitions.Cubic.easeOut,
				onComplete: function() { 
						$('link_to_video').setHTML('Link');
						$('link_to_video').setStyle('opacity', 1);
					}
				}).start(0.1);
		},


	
	//
	// send_analytics_to_vp
	//
	send_analytics_to_vp: function()
		{
			if (navigator.appName.indexOf("Microsoft") != -1) {
				 window['video_player']._wral_vp_receiveAnalyticsVars(vp2.analytics);
			}
			else {
				 document['video_player']._wral_vp_receiveAnalyticsVars(vp2.analytics);
			}
		},
	

	//
	// handleRelatedStuff (gets call back from the JSON Remote
	//
	handleRelatedStuff: function(result)
		{
			$('vp_related_stuff' + vp2.next_vp_related_stuff).setHTML (result.other_assets_html);
			vp2.showNextRelatedStuff ();
		
			if (vp2.reload_playlist)
			{
				vp2.process_video_collection( {name: 'Playlist', videos: result.videos });
				
				var which = $('vid_thumb_list_0');
				if (which)
					which.scrollTop = 0;
				
				vp2.last_played_playlist = 'Playlist';
				vp2.last_played_n = 0;
				vp2.updateNowPlayingBanners();
		
				vp2.tweenToWhich(0, 500);
		
				vp2.reload_playlist = false;
			}
		},
	
	
	
	// 
	// updateNowPlayingBanners
	//
	updateNowPlayingBanners: function()
		{
			if (!vp2.__VIDS[vp2.last_played_playlist])  // sanity check; could fail if last_played_playlist
						// is null, which could happen if a video outside of a playlist was played
				return; 
			
			for (var i = 0; i < vp2.__VIDS[vp2.last_played_playlist].length; i++)
			{
				var banner = $('vid_thumb_banner_' + i);
				if (!banner)
				{
					break;
				}
		
				if (i == vp2.last_played_n)
				{
					banner.setStyle ('visibility', 'visible');
					banner.setHTML ('NOW PLAYING');
				}
				else if (i == vp2.last_played_n + 1)
				{
					banner.setStyle ('visibility', 'visible');
					banner.setHTML ('UP NEXT');
				}
				else
				{
					banner.setStyle ('visibility', 'hidden');
					banner.setHTML ('');
				}
			}
		},



	
	//
	// do_play_vid() -- uses the object set in which_vid
	//
	do_play_vid: function()
		{
			var which_vid = vp2.which_vid;
			
			if (!which_vid)
			{
				return;
			}
		
			if (vp2.flash_ready)
			{
				if (navigator.appName.indexOf("Microsoft") != -1) {
					 window['video_player']._wral_vp_play_video(which_vid);
				}
				else {
					 document['video_player']._wral_vp_play_video(which_vid);
				}
			} else {
				vp2.waiting_to_play = true;
				return;
			}
				
			var html = '';
            
			if (which_vid.title)
				html += '<p class="storyInfo_title">' + which_vid.title + '</p>';
		
			if (which_vid.description)
				html += '<p class="storyInfo_blurb">' + which_vid.description + '</p>';
				
			if (which_vid.timestamp)
				html += '<p class="storyInfo_date">' + vp2.get_datestamp(which_vid.timestamp) + '</p>';
					
			var links = [];
		
			var linkhtml = 
				(which_vid.primary_story_link != undefined && which_vid.primary_story_link)
					? '<a h' + 'ref="' + which_vid.primary_story_link + '">Read</a>'
					: '';
			if (linkhtml) links.push (linkhtml);
		
			linkhtml = which_vid.assetID != undefined && which_vid.assetID ?
				'<a h' + 'ref="/rs/page/5019568/?id_asset_to_email=' + which_vid.assetID + '">Embed</a>' : '';
			if (linkhtml) links.push (linkhtml);
					
			var link = null;
			if (which_vid.assetID != undefined && which_vid.section_path != undefined && which_vid.assetID && which_vid.section_path)
				link = "http://www.wral.com/" + which_vid.section_path + "/video/" + which_vid.assetID + '/';
		
			linkhtml = (link)
				?  "<a id='link_to_video' h" + "ref='javascript:vp2.setclipboard(\"" + link + "\");'>Link</a>"
				: '';
			if (linkhtml) links.push (linkhtml);
	
			linkhtml = '';
			for (i = 0; i < links.length; i++)
			{
				if (i > 0)
				{
					linkhtml += ' | ';
				}
				linkhtml += links[i];
			}

            if (which_vid.socialMediaInfo)
            {
                linkhtml += " <a style='margin-left: 8px;' id='addthisLink'></a>";
            }
		
			html += '<style>a#addthisLink img { vertical-align: text-bottom; }</style><p class="storyInfo_shareLinks">' + linkhtml + '</p>';
				
			$('vp_story_info' + ((vp2.next_vp_story_info + 1) % 2)).setHTML('<br />');
			$('vp_story_info' + vp2.next_vp_story_info).setHTML(html);

            if (which_vid.socialMediaInfo)
            {
                var configObject = { 'services_compact': 'aim,ask,backflip,blogger,blogmarks,buzz,delicious,digg,facebook,fark,faves,favorites,google,linkedin,live,myaol,myspace,netvibes,newsvine,reddit,slashdot,stumbleupon,stylehive,technorati,tumblr,twitter,typepad,wordpress,yahoobkm' };
                var shareObject = { 'title': which_vid.socialMediaInfo.title, 'url': which_vid.socialMediaInfo.url };

                addthis.button("#addthisLink", configObject, shareObject);
            }
			
			/*
			$('vp_story_info' + vp2.next_vp_story_info).setStyle('visibility', 'visible');
			vp2.next_vp_story_info = (vp2.next_vp_story_info + 1) % 2;
			$('vp_story_info' + vp2.next_vp_story_info).setStyle('visibility', 'hidden');
			*/
		
			vp2.updateNowPlayingBanners();
		
			var url = which_vid.videoInfo.replace('xml', 'related_assets_json');
			new Json.Remote(url, {onComplete: vp2.handleRelatedStuff }).send();
			
			
			vp2.hideRelatedStuffBox();
		},



	//
	// play_next_vid()
	//
	play_next_vid: function()
		{
			vp2.last_played_n++;
			vp2.which_vid = vp2.__VIDS[vp2.last_played_playlist] 
				? vp2.__VIDS[vp2.last_played_playlist][vp2.last_played_n] 
				: null;
			vp2.do_play_vid();
		},
	
	
	//
	// get_next_vid_in_playlist() -- returns the object; useful if Flash wants to 
	// know what's coming up next
	//
	get_next_vid_in_playlist: function()
		{
			return vp2.__VIDS[vp2.last_played_playlist] 
				? (vp2.__VIDS[vp2.last_played_playlist][vp2.last_played_n + 1] 
					? vp2.__VIDS[vp2.last_played_playlist][vp2.last_played_n + 1] 
					: null) 
				: null;
		},



	//
	// get_datestamp -- make pretty like
	//
	get_datestamp: function(timestamp)
		{
			var now = new Date();
			var oneday = 60 * 60 * 24 * 1000; // in millis
			
			var out = '';
			
			var d = new Date();
			d.setTime(timestamp * 1000);
			
			if ((now.getTime() - timestamp * 1000) < (oneday * 5)) {
				// within the past five days
				if (now.getDate() == d.getDate()) {  // today!
					out = 'Today';
				} else {
					now.setHours(12);
					now.setTime(now.getTime() - oneday);
					if (now.getDate() == d.getDate()) { // yesterday!
						out = 'Yesterday';
					} else {
						var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 
									'Thursday', 'Friday', 'Saturday'];
						out = days[d.getDay()];
					}
				}
			} else {
			/* � � � � � � � � � �var months = [ �'January', 'February', 'March', 'April',�
								'May', 'June', 'July', 'August', 'September',
								'October', 'November', 'December' ];*/
				var months = [  'Jan', 'Feb', 'Mar', 'Apr', 
								'May', 'Jun', 'Jul', 'Aug', 'Sep',
								'Oct', 'Nov', 'Dec' ];
				out = months[d.getMonth()] + ' ' + d.getDate();
				
				if ((now.getTime() - timestamp * 1000) < (oneday * 120)) {
					// no need for year-- within the past 120 days
				} else {
					out += ", " + d.getFullYear();
				}
			}
			
			out += ' - ';
			
			var h = d.getHours();  // 0 - 23
			if (h == 0 || h == 12) out += "12";
			else if (h < 12) out += h;
			else out += (h - 12);
			
			var m = d.getMinutes();
			out += ":" + (m < 10 ? '0' : '') + m;
			out += (h < 12 ? 'am' : 'pm');
			
			return out;
		},
	
	
	//
	// tweenToWhich
	//
	tweenToWhich: function(n, otherTime)
		{
			if (vp2.current_vid_list == n) return;  // already here ... !
		
			if (vp2.is_firefox && vp2.current_vid_list != null) $('vid_thumb_list_' + vp2.current_vid_list).setStyle('overflow', 'hidden');
			
			vp2.current_vid_list = n;
			var tajmaut=setTimeout("vp2.tweenToWhich_real(" + n + ", " + otherTime + ")",1);  // delay for a brief moment; for browser compat.
		},




	// 
	// tweenToWhich_real
	//
	tweenToWhich_real: function(n, otherTime)
		{
		
			var tweenTime = 400;
			if (otherTime) tweenTime = otherTime;
		
				var holder = $('vid_thumb_lists');
				var which = $('vid_thumb_list_' + n);
				
		
				var holder_left = holder.getLeft();
				var need_left = holder_left - which.getLeft();
		
				if (holder_left != need_left)
				{
					var on_complete_func = function() {};
		
					if (vp2.is_firefox)
					{
						on_complete_func = function() {
							$('vid_thumb_list_' + vp2.current_vid_list).setStyle('overflow', 'auto');
						};
					}
		
					new Fx.Style(holder, 'left', 
							{duration: tweenTime, 
							transition: Fx.Transitions.Cubic.easeOut
							,onComplete: on_complete_func
							}).start(need_left);
							
					which.scrollTop = 0;
				}
				
		
		
				//
				// now move the highlighter for the tab.
				
				holder = $('vid_sections');
				which = $('vs_' + n);
				holder_left = holder.getLeft();
				need_left = which.getLeft() - holder_left;
				need_width = which.offsetWidth;
				need_height = holder.offsetHeight;
				
				var highlighter = $('vs_highlighter');
				
				if (highlighter.getLeft() != need_left)
				{
					new Fx.Style(highlighter, 'left', 
						{duration: tweenTime, 
						transition: Fx.Transitions.Cubic.easeOut
						}).start(need_left);
				}
				
				if (highlighter.width != need_width)
				{
					new Fx.Style(highlighter, 'width', 
						{duration: tweenTime, 
						transition: Fx.Transitions.Cubic.easeOut
						}).start(need_width);
				}
		
				highlighter.setStyle('height', need_height);
		},
	
	
	//
	// hideRelatedStuffBox
	//
	hideRelatedStuffBox: function()
		{
			if (vp2.isHidingRelatedStuff)
				return;
				
			vp2.isHidingRelatedStuff = true;
			
			if (vp2.is_firefox) 
			{
				$('vp_related_stuff' + (vp2.next_vp_related_stuff + 1) % 2).setStyle('overflow', 'hidden');
				$('vp_related_stuff' + (vp2.next_vp_related_stuff) % 2).setStyle('overflow', 'hidden');
			}
			
			var tajmaut=setTimeout("vp2.hideRelatedStuffBox_real()",1);  // delay for a brief moment; for browser compat.
		},

	
	//
	// hideRelatedStuffBox_real
	//
	hideRelatedStuffBox_real: function()
		{
			new Fx.Style($('vp_related_stuff'), 'width', {duration: 500, transition: 
				Fx.Transitions.Cubic.easeOut, onComplete: vp2.doneHidingRelatedStuff}).start(0);
		
		
		
			$('vp_story_info0').setStyle ('width', '570px');
			$('vp_story_info1').setStyle ('width', '570px');
			
		},
	


	//
	// showNextRelatedStuff
	//
	showNextRelatedStuff: function()
		{
			if (vp2.isHidingRelatedStuff)
			{
				vp2.readyForNextRelatedStuff = true;
				return;
			}
		
			var innerH = $('vp_related_stuff' + vp2.next_vp_related_stuff).innerHTML;
			if (!innerH || innerH.indexOf('empty') == 0) 
			{
				return;
			}
		
			new Fx.Style($('vp_related_stuff'), 'width', {duration: 500, transition: 
				Fx.Transitions.Cubic.easeOut, onComplete: vp2.doneHidingRelatedStuff}).start(268);
			
			$('vp_story_info0').setStyle ('width', '292px');
			$('vp_story_info1').setStyle ('width', '292px');
			
			$('vp_related_stuff' + vp2.next_vp_related_stuff).setStyle('display', 'block');
			vp2.next_vp_related_stuff = (vp2.next_vp_related_stuff + 1) % 2;
			$('vp_related_stuff' + vp2.next_vp_related_stuff).setStyle('display', 'none');
		
			vp2.readyForNextRelatedStuff = false;
		
		},



	
	//
	// doneHidingRelatedStuff -- called after the tween is complete
	//
	doneHidingRelatedStuff: function()
		{
			vp2.isHidingRelatedStuff = false;
			if (vp2.readyForNextRelatedStuff)
			{
				vp2.showNextRelatedStuff();
			}
			else
			{
				if (vp2.is_firefox) $('vp_related_stuff' + (vp2.next_vp_related_stuff + 1) % 2).setStyle('overflow', 'auto');
			}
		},





	//
	// process_video_collections
	//
	process_video_collections: function(VCs)
		{
			var was_empty = vp2.next_vid_section_num == 0;
		
			video_collection_divs = [];
		
			for (var i = 0; i < VCs.length; i++)
			{
				vp2.process_video_collection(VCs[i]);
			}
			
			if (was_empty)
			{
				var holder = $('vid_thumb_lists');
				var which = $('vid_thumb_list_' + (vp2.next_vid_section_num - 1));
				holder.setStyle('left', holder.getLeft() - (which.getLeft() + which.offsetWidth));
				
				var highlighter = $('vs_highlighter');
				highlighter.setStyle('width', 1);
				
				which = $('vs_' + (vp2.next_vid_section_num - 1));
				highlighter.setStyle('left', which.getLeft() + which.offsetWidth);
				
				vp2.tweenToWhich(0, 1500);
			}
		},



	//
	// process_video_collection
	//
	process_video_collection: function(obj)
		{
			var name = obj['name'];
			var vids_array_in = obj['videos'];
			var suppress_onclick = obj['suppress_onclick'];
			var vids_array_out = [];
		
			var ne;
			var pre_existed = false;
		
			if(!vids_array_in) return;  //Empty Collection?
			
			if (vp2.__VIDS[name]) 
			{
				ne = $(video_collection_divs[name]);
				pre_existed = true;
			}
			else
			{
				var id = 'vid_thumb_list_' + vp2.next_vid_section_num;
		
				ne = new Element('div', {'class': 'vid_thumb_list_box', 'id': 'vid_thumb_list_' + vp2.next_vid_section_num,
				'styles': {'overflow-x': 'hidden', 'overflow-y': vp2.is_firefox ? 'hidden' : 'auto', 'left': ''+(vp2.next_vid_section_num * $('vid_thumb_box').offsetWidth) + 'px'}
						});
		
				video_collection_divs[name] = id;
			}
		
		
			var html = '';
		
			for (var i = 0; i < vids_array_in.length ; i++)
			{
				if (vids_array_in[i]['title'])  // hack to confirm it's really an object!
				{
					// 
					if (name == 'Playlist' && !suppress_onclick)
					{
						html += '<div class="vid_thumb" onClick="vp2.play_vid(\'' + name + '\',' +
							i + ', false);"><div class="vid_thumb_img_box"><img s' + 'rc="' +
							vids_array_in[i].largeThumbnail + '" /></div>';
						html += '<div id="vid_thumb_banner_' + i + '" class="vid_thumb_banner"></div>';
						html += '<div class="vid_thumb_text_box"><span class="headline">' +
						vids_array_in[i].title + '</span></div></div>';
					}
					else if(!suppress_onclick)
					{
						html += '<div class="vid_thumb" onClick="vp2.play_vid(\'' + name + '\',' +
							i + ', true);"><div class="vid_thumb_img_box"><img s' + 'rc="' +
							vids_array_in[i].largeThumbnail + '" /></div>';
						html += '<div class="vid_thumb_text_box"><span class="headline">' +
						vids_array_in[i].title + '</span></div></div>';
					}
					else
					{
						html += '<div class="vid_thumb"><a href="'+ vids_array_in[i].videoURL +'"><div class="vid_thumb_img_box"><img s' + 'rc="' +
							vids_array_in[i].largeThumbnail + '" /></div>';
						html += '<div class="vid_thumb_text_box"><span class="headline">' +
						vids_array_in[i].title + '</span></div></a></div>';
					}
		
					
						
					vids_array_out.push(vids_array_in[i]);
				}
			}
			
			vp2.__VIDS[name] = vids_array_out;
			
			ne.setHTML(html);
			
			if (!pre_existed)
			{
				ne.inject('vid_thumb_lists_inner');
		
				name = name.replace('_', ' ');
			
				ne = new Element('span', {'id': 'vs_' + vp2.next_vid_section_num});
			
				html = "<a onClick='vp2.tweenToWhich(" + vp2.next_vid_section_num + ");'>" +
					name + "</a>";
		
				ne.setHTML(html).inject('vid_sections_inner');
			}
		
		
			vp2.next_vid_section_num++;
		},


	
	//
	// play_video_obj
	//
	play_video_obj: function(obj)
		{
			vp2.which_vid = obj;
			vp2.last_played_playlist = null;
			vp2.reload_playlist = true;
			vp2.do_play_vid();
		},


	//
	// emailThis
	//
	emailThis: function(assetID) 
		{
			window.open('/apps/email_to_friend/email_to_friend/?id_asset=' + assetID, 'popupwin1', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=625,height=400,left=100,top=100');    
		},

	
	// 
	// rateThis
	//
	rateThis: function(assetID) 
		{
			window.open('/apps/rate_asset/rate_asset/?id_asset=' + assetID, 'popupwin2', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=625,height=400,left=100,top=100');    
		},


	//
	// setWMVURL(url) -- called when it is time to start the WMP
	//
	setWMVURL: function(url)
		{
			var blank = false;
			var o;
		
			if (blank)        o = '<object id="Player" height=240 width=320 ';
		//    else        o = '<object id="Player" height=280 width=310 ';
			else        o = '<object id="Player" height=354 width=576 ';
				
		
			if (navigator.userAgent.toLowerCase().indexOf('safari') != -1 
					|| navigator.userAgent.toLowerCase().indexOf('msie') != -1) 
					o += 'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" '; 
			else 
					o += 'classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" '; 
		
				
			o += 'standby="Loading Windows Media Player components..." ';
			o += 'type="application/x-oleobject" ';
			o += 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">';
		
			o += '<param name="URL" value="' + url + '">';
		
			if (blank)        o += '<param name="uiMode" value="none">';
			else        o += '<param name="uiMode" value="mini">';
			
			if (blank)        o += '<param name="ShowStatusBar" value="False">';
			else        o += '<param name="ShowStatusBar" value="True">';
			
			o += '<param name="ShowControls" value="False">';
			o += '<param name="autoStart" value="True">';
			o += '<param name="stretchToFit" value="True">';
		
			if (blank)        
				o += '<embed height=240 width=320 type="application/x-mplayer2" s' + 'rc="' + url + '" name="Player" ';
			else
				o += '<embed height=354 width=576 type="application/x-mplayer2" s' + 'rc="' + url + '" name="Player" ';
		
		
		
			if (blank)        
				o += 'showstatusbar="0" showdisplay="0" uiMode="none" showcontrols="0" showtracker="0" stretchtofit="1">';
			else
				o += 'showstatusbar="1" showdisplay="0" uiMode="mini" showcontrols="0" showtracker="0" stretchtofit="1">';
				
				
			o += '</embed>';
			o += '</object>';
		
		
			$('LayerWMP').setHTML(o);
		
			$('LayerWMP').setStyle('visibility', 'visible');
			$('LayerVidPlayer').setStyle('visibility', 'hidden');
		
			return;
		},
	

	//
	// ShutDownWMV() -- called when it is time to shut down the WMP
	//
		ShutDownWMV: function() {
			$('LayerWMP').setHTML('<br />');
			$('LayerWMP').setStyle('visibility', 'hidden');
			$('LayerVidPlayer').setStyle('visibility', 'visible');
		
			return;
		},
	
	
	//
	// changeAd(ad_url) -- called from big VP to change ad
	//
		changeAd: function(adurl) {
			load_new_ad(adurl);
			//alert('changeAd Called ' + adurl);
		}



};
