function BrightcovePlayer( data ){

	// set initialization vars
	this.container_id = (data.container_id != undefined) ? data.container_id : 'brightcove_player';
	this.swf_path = (data.swf_path != undefined) ? data.swf_path : "swf/bc_player.swf";

	this.genre = (data.genre != undefined) ? data.genre : 'all';
	this.type = (data.type != undefined) ? data.type : 'all';
	this.artist = (data.artist != undefined) ? data.artist : 'all';

	this.proxy_path = (data.proxy_path != undefined && data.proxy_path) ? data.proxy_path : '/bc_proxy.php';	

	this.is_artist_player = (data.is_artist_player != undefined) ? data.is_artist_player : false;
	this.is_popup = (data.is_popup != undefined) ? data.is_popup : false;
	this.popup_path = (data.popup_path != undefined) ? data.popup_path : false;

	this.active_color = (data.active_color != undefined) ? data.active_color : "#FF0000";	// default black
	this.inactive_color = (data.inactive_color != undefined) ? data.inactive_color : "#FFCC00";	// default black
	this.icon_on_color = (data.icon_on_color != undefined) ? data.icon_on_color : "#00FF00";	// default black
	this.icon_off_color = (data.icon_off_color != undefined) ? data.icon_off_color : "#CCCCCC";	// default black
	this.bar_bg_color = (data.bar_bg_color != undefined) ? data.bar_bg_color : "#FFFFFF";	// default black


	this.bc_video = null;

	this.loading = true;

	this.page_number = (data.page_number != undefined) ? data.page_number : 0;
	this.page_size = (data.page_size != undefined) ? data.page_size : 1000;

	this.videos = undefined;
	this.vid_id = data.vid_id ? data.vid_id : 0;
	this.playlist_id = data.playlist_id ? data.playlist_id : '9417876001';
	this.playlist = new BCPlaylist();

	this.play_first = data.vid_id ? data.vid_id : false;

	// add markup to bc_player_container area
	this.init();
	// query & update player
	this.refresh();

}

// FLASH CALLBACKS
BrightcovePlayer.prototype.flashMovieLoaded = function(){ this.bc_video.flashLoaded(); }
BrightcovePlayer.prototype.playNext = function(){ this.playVideo( this.playlist.nextVideo() ); }

// BUTTON ACTIONS
BrightcovePlayer.prototype.setGenre = function( genre ){ this.genre = genre.trim(); this.artist = 'all'; }
BrightcovePlayer.prototype.setType = function( type ){ this.type = type.trim(); }
BrightcovePlayer.prototype.setArtist = function( artist ){ this.artist = artist.trim(); }
BrightcovePlayer.prototype.toggleRandom = function(){ this.playlist.toggleRandom(); }

BrightcovePlayer.prototype.launchStandalone = function(){
  video = this.playlist.getCurrentVideo();
  window.open(this.popup_path + "?bc_id=" + video['id'],"bc_standalone","status=0, toolbar=0, menubar=0, location=0, height=595, width=460");
  this.bc_video.pause();
}
BrightcovePlayer.prototype.cropPlaylistBy = function( letter ){
  jQuery('#bc_no_videos_found').hide();
  if( letter == 'all' ){
	jQuery("#bc_playlist_tracks table tr").show();
	this.playlist.cropBy('all');
  }else{
	found_results = false;
	this.playlist.cropBy(letter);
	jQuery("#bc_playlist_tracks table tr").each( function(){
	  name = jQuery(this).children("td:eq(1)").children("a").html();
	  if( name.toLowerCase().trim().substring(0,1) == letter.toLowerCase().trim().substring(0,1) ){
		jQuery(this).show();
		found_results = true;
	  }else{
		jQuery(this).hide();
	  }
	});
	if( !found_results ) this.noVideosFound();
  }
}
BrightcovePlayer.prototype.noVideosFound = function(){
  jQuery('#bc_no_videos_found').show();
}
BrightcovePlayer.prototype.showPlaylist = function(){
  if( this.is_popup ){
	// hide player, show playlist
	jQuery(".bc_title").css({visibility:"hidden"});
	// hide flash
	if( jQuery.browser.msie ){
	  jQuery("div.bc_playlist").prepend("<iframe src='' class='hideFlash' />");
	}
	jQuery("#bc_swfplayer").css({visibility:"hidden"});
	jQuery("div.bc_playlist").show();
  }else{
	jQuery("div.bc_playlist").slideDown('slow');
  }
}
BrightcovePlayer.prototype.hidePlaylist = function(){
  if( this.is_popup ){
	jQuery("#bc_swfplayer_wrap").css({zIndex:"1"});
	jQuery(".bc_title").css({visibility:"visible"});
	jQuery("#bc_swfplayer").css({visibility:"visible"});
	jQuery("div.bc_playlist").slideUp('fast'); 
  }else{
	jQuery("div.bc_playlist").slideUp('medium');
  }
}

BrightcovePlayer.prototype.refresh = function(){
  var bc_cache = this;
  and_tags = '';
  and_tags += (this.genre == 'all') ? '' : 'genre:' + this.genre + ',';
  and_tags += (this.type == 'all') ? '' : 'type:' + this.type + ',';
  and_tags += (this.artist == 'all') ? '' : 'name:' + this.artist;
  if( and_tags != '' ){
	// make ajax/JSON request to our proxy
	jQuery.getJSON(this.proxy_path,
				{
					command:"find_videos_by_tags",
					and_tags:and_tags,
					page_size:this.page_size,
					page_number:this.page_number,
					get_item_count:'true',
					fields:"name,id,referenceId,tags,thumbnailURL"
				}, function(data){
					// set bc_videos	
					bc_cache.videos = data.items;
					bc_cache.organizeVideos();
					bc_cache.playlist.setVideos( bc_cache.videos );
					// refresh/redraw player data
					bc_cache.redraw();
				}
	);
  }else{
	or_tags = 'genre:rock,genre:pop,genre:urban,genre:indie';
	// make ajax/JSON request to our proxy
	jQuery.getJSON(this.proxy_path,
				{
					command:"find_videos_by_tags",
					or_tags:or_tags,
					page_size:this.page_size,
					page_number:this.page_number,
					get_item_count:'true',
					fields:"name,id,referenceId,tags,thumbnailURL"
				}, function(data){
					// set bc_videos	
					bc_cache.videos = data.items;
					bc_cache.organizeVideos();
					bc_cache.playlist.setVideos( bc_cache.videos );
					// refresh/redraw player data
					bc_cache.redraw();
				}
	); 
  }
}

BrightcovePlayer.prototype.organizeVideos = function(){
  videos = this.videos;
  //if( this.genre == 'all' && this.type == 'all' && this.artist == 'all' && videos.length > 0 && this.vid_id == 0 ){
	jQuery.ajaxSetup({async:false});
	bc_cache = this;
	jQuery.getJSON(this.proxy_path,
				{
					command:"find_playlist_by_id",
					playlist_id:bc_cache.playlist_id,
					fields:"videoIds"
				}, function(data){
					vids = [];
					for(i=0;i<data.videoIds.length;i++){
					  for(j=0;j<bc_cache.videos.length;j++){
						if( data.videoIds[i] == bc_cache.videos[j]['id'] ){
						  vids[vids.length] = bc_cache.videos[j];
						}
					  }
					}
					//if( !bc_cache.is_artist_player ){
					//  bc_cache.play_first = data.videoIds[0];
					//}else{
					// 
					//}
					if(vids.length > 0){
					  bc_cache.play_first = bc_cache.vid_id ? bc_cache.vid_id : vids[0]['id'];
					}
					bc_cache.videos = vids;
				}
	);
	jQuery.ajaxSetup({async:true});
  //}
  first_exists = false;
  for(i=0; i<videos.length; i++){
	if( this.play_first == videos[i]['id'] ) first_exists = true;
	  name = videos[i]['name'];
	  if(name.match(":")){
		name_parts = name.split(":");
		videos[i]['artist'] = name_parts[0].trim().replace(/[""]/g,'');
		videos[i]['song'] = name_parts[1].trim().replace(/[""]/g,'');
	  }else if(name.match(" by ")){
		name_parts = name.split(" by ");
		videos[i]['artist'] = name_parts[1].replace(/[""]/g,'');
		videos[i]['song'] = name_parts[0].replace(/[""]/g,'');
	  }else{
		videos[i]['artist'] = name.replace(/\"(.)*\"/,'');
		videos[i]['song'] = name.replace( videos[i]['artist'], '' ).replace(/[""]/g,'');
	  }
  }
  if( !first_exists ) this.play_first = false;
  if( !this.is_artist_page ){
	this.videos.sort( bcSortByArtist );
  }else{
	this.videos.sort( bcSortBySong );
  }
  function bcSortByArtist(a,b){	x = a['artist'].toLowerCase(); y = b['artist'].toLowerCase(); return ((x<y) ? -1 : ((x>y) ? 1 : 0)); }
  function bcSortBySong(a,b){ x = a['song'].toLowerCase(); y = b['song'].toLowerCase(); return ((x<y) ? -1 : ((x>y) ? 1 : 0)); }
}
BrightcovePlayer.prototype.redraw = function(){

  if( this.loading ){
	if( this.videos.length > 0 ){ //|| !this.is_artist_player ){
	  jQuery('#bc_player_wrap').show();
	}
  }

  jQuery(".bc_alphabet a.bc_selected").removeClass("bc_selected");
  jQuery(".bc_alphabet a:first").addClass("bc_selected");

  var playlist='	<div id="bc_no_videos_found">There are no videos that match your criteria</div>';
  playlist+='		<table>';
  for(i=0; i<this.videos.length; i++){
	if( i%2 == 0 ){
	  playlist+='		 <tr class="bc_playlist_alternate" id="bc_vid_' + this.videos[i]['id'] + '">';
	}else{
	  playlist+='		 <tr class="" id="bc_vid_' + this.videos[i]['id'] + '">';
	}
	playlist+='				<td style="width:19px; padding-left:0px;">';
	playlist+='					<a href="javascript:void(0);" onclick="bc_player.playVideo(\'' + this.videos[i]['id'] + '\');" class="bc_play_icon"></a>';
	playlist+='				</td>';
	playlist+='				<td style="width:165px; border-left:1px solid black;">';
	playlist+='					<a href="javascript:void(0);" onclick="bc_player.playVideo(\'' + this.videos[i]['id'] + '\');">';
	playlist+='					' + this.videos[i]['artist'];
	playlist+='					</a>';
	playlist+='				</td>';
	playlist+='				<td style="border-left:1px solid black;">' + this.videos[i]['song'] + '</td>';
	//	if( this.is_artist_page ){
	//playlist+='				<td style="border-left:1px solid black;"></td>';
	//	}else{
	//	  playlist+='				<td style="border-left:1px solid black;"><a href="javascript:void(0)" onclick="bc_player.setArtist(\'' + this.videos[i]['artist'] + '\'); bc_player.refresh();">more...</a></td>';
	//	}
	playlist+='			</tr>';
  }
  playlist+='		</table>';
  jQuery("#bc_playlist_tracks").html(playlist);

  // if no videos, display message
  if( this.videos.length == 0 ){
	  this.noVideosFound();
	  return;
  }

  jQuery("#bc_playlist_tracks table tr").hover( function(){
	jQuery(this).addClass("bc_playlist_hover");
  }, function(){
	jQuery(this).removeClass("bc_playlist_hover");
  });
  if( this.play_first ){
	this.playVideo( this.play_first );
	this.loading = false;
  }else if( this.loading ){
	this.playVideo( this.vid_id );
	this.loading = false;
  }else{
	this.showPlaylist();
	if( jQuery("#bc_vid_" + this.bc_video.getCurrentVideoId()) ){
	  jQuery("#bc_vid_" + this.bc_video.getCurrentVideoId()).addClass("bc_playlist_playing");
	}
  }
}

BrightcovePlayer.prototype.playVideo = function(vid_id){
  if( vid_id ){
	this.playlist.setCurrentVideo( vid_id );
  }
  video = this.playlist.getCurrentVideo();
  if( !video ){
	this.playlist.setCurrentVideo(false);
	this.playlist.setCurrentVideo( this.playlist.nextVideo() );
	video = this.playlist.getCurrentVideo();
  }
  jQuery('.bc_title').html(video['artist'] + ' : <span>' + video['song'] + '</span>');
  //this.queueVideoInterval = setInterval( "bcvid_cache.loadVideo(" + this.vid_id + ");", 1000 );
  this.bc_video.loadVideo( video['id'] );
  jQuery("#bc_playlist_tracks table tr").removeClass('bc_playlist_playing');
  jQuery("#bc_vid_" + video['id']).addClass("bc_playlist_playing");
  if( this.is_popup ){
	this.hidePlaylist();
  }
}

/* Constructor
 * - writes html to the page
 */
BrightcovePlayer.prototype.init = function(){

	jQuery( '#' + this.container_id ).append('<div id="bc_player_wrap"></div>');
	this.container_id = 'bc_player_wrap';

  if( !this.is_artist_player ){
	// HTML FOR GENRE MENU
	var genres='';
	genres+='					<div class="bc_topper">&nbsp;<\/div>';
	genres+='					<div class="bc_genres">';
	genres+='						<a href="javascript:void(0);" onclick="bc_player.setGenre(\'all\'); bc_player.refresh(); bc_player.showPlaylist();" class="bc_button bc_genre bc_genre_selected">All<\/a>';
	genres+='						<div class="bc_spacer">&nbsp;<\/div>';
	genres+='						<a href="javascript:void(0);" onclick="bc_player.setGenre(\'rock\'); bc_player.refresh();bc_player.showPlaylist();" class="bc_genre bc_button">Rock<\/a>';
	genres+='						<div class="bc_spacer">&nbsp;<\/div>';
	genres+='						<a href="javascript:void(0);" onclick="bc_player.setGenre(\'indie\'); bc_player.refresh();bc_player.showPlaylist();" class="bc_genre bc_button">Indie\/Alt<\/a>';
	genres+='						<div class="bc_spacer">&nbsp;<\/div>';
	genres+='						<a href="javascript:void(0);" onclick="bc_player.setGenre(\'pop\'); bc_player.refresh();bc_player.showPlaylist();" class="bc_genre bc_button">Pop<\/a>';
	genres+='					<\/div>	';
	genres+='					<div class="bc_topper_2"> <\/div>';
	jQuery( '#' + this.container_id ).append(genres);
  }

  // HTML FOR TYPES
  var types='';
  types+='					<div class="bc_types">';
  types+='						<a href="javascript:void(0);" onclick="bc_player.setType(\'all\'); bc_player.refresh();bc_player.showPlaylist();;" class="bc_type bc_type_selected bc_button" style="width: 107px;">All<\/a>';
  types+='						<div class="bc_spacer"> <\/div>';
  types+='						<a href="javascript:void(0);" onclick="bc_player.setType(\'official\'); bc_player.refresh();bc_player.showPlaylist();;" class="bc_type bc_button">Official Videos<\/a>';
  types+='						<div class="bc_spacer"> <\/div>';
  types+='						<a href="javascript:void(0);" onclick="bc_player.setType(\'live\'); bc_player.refresh();bc_player.showPlaylist();;" class="bc_type bc_button">Live Videos<\/a>';
  types+='						<div class="bc_spacer"> <\/div>';
  types+='						<a href="javascript:void(0);" onclick="bc_player.setType(\'other\'); bc_player.refresh();bc_player.showPlaylist();;" class="bc_type bc_button">Other Videos<\/a>';
  types+='					<\/div>	';
  jQuery( '#' + this.container_id ).append(types);

  // INSERT SWF
  jQuery( "#" + this.container_id ).append('<div id="bc_swfplayer_wrap"><div id="bc_swfplayer"></div></div>');
  this.bc_video = new BCVideo({swf_path:this.swf_path,container_id:"bc_swfplayer",activecolor:this.active_color,inactive_color:this.inactive_color,icon_on_color:this.icon_on_color,icon_off_color:this.icon_off_color,bar_bg_color:this.bar_bg_color});

  jQuery( '#' + this.container_id ).append('<div class="bc_title"><\/div>');

  // HTML FOR OPTIONS
  var options='';
  options+='					<div class="bc_options">';
  options+='					<a href="javascript:void(0);" onclick="bc_player.showPlaylist(\'all\');" class="bc_option bc_button bc_toggle" style="width: 150px;">Browse Videos<\/a>';
  options+='					<div class="bc_spacer"> <\/div>';
  options+='					<a href="javascript:void(0);" onclick="bc_player.toggleRandom();" class="bc_option bc_button bc_toggle" style="width: 121px;">Random<\/a>';
  options+='					<div class="bc_spacer"> <\/div>';
	/*
  options+='					<a href="javascript:void(0);" onclick="bc_player.showEmbed();" class="bc_option bc_button">Embed<\/a>';
  options+='					<div class="bc_spacer" style="background:white;"> <\/div>';
	*/
  if( this.is_popup ){
	options+='					<a href="javascript:void(0);" onclick="bc_player.showPlaylist();" class="bc_option bc_button" style="width: 165px;">View Playlist<\/a>';
  }else{
	options+='					<a href="javascript:void(0);" onclick="bc_player.launchStandalone();" class="bc_option bc_button" style="width: 165px;">Launch Standalone<\/a>';
  }
  options+='					<\/div>	';

  // HTML FOR PLAYLIST
  var playlist='';
  if( this.is_popup ){
	playlist+='					<div class="bc_playlist" style="position:absolute; left:0px; top:0px; zIndex:1000; width:440px; height:394px;">';
  }else{
	playlist+='					<div class="bc_playlist" style="">';
  }
  playlist+='						<a href=\'javascript:void(0);\' class=\'bc_playlist_close\' onclick=\'bc_player.hidePlaylist();\'>^^ close<\/a>';
  playlist+='						<div id="bc_playlist_head">';
  playlist+='							<table>';
  playlist+='								<tr>';
  playlist+='									<td style=\'width:15px; padding-left:4px;\'><\/td>';
  playlist+='									<td style=\'width:165px; border-left:1px solid black;\'>Name<\/td>';
  playlist+='									<td style=\'border-left:1px solid black;\'>Song<\/td>';
	//  playlist+='									<td style=\'border-left:1px solid black;\'>More<\/td>';
  playlist+='								<\/tr>';
  playlist+='							<\/table>';
  playlist+='						<\/div>';
  if( this.is_popup ){
	playlist+='						<div id="bc_playlist_tracks" style="height:290px;">';
  }else{
	playlist+='						<div id="bc_playlist_tracks">';
  }
  playlist+='						<\/div>';

  // HTML FOR ALPHABET
  var alpha='';
  alpha+='					<div class=\'bc_alphabet\'>';
  alpha+='						<a href="javascript:void(0);" onclick="bc_player.cropPlaylistBy(\'all\');" class="bc_selected">all<\/a>';
  var alphabet = 'abcdefghijklmnopqrstuvwxyz';
  for(i=0;i<26;i++){
	alpha+='						<a href="javascript:void(0);" onclick="bc_player.cropPlaylistBy(\'' + alphabet.substring(i,i+1) + '\');" >' + alphabet.substring(i,i+1) + '<\/a>';
  }
  alpha+='					<\/div>';

  playlist+=alpha+'					<\/div>';
  if( this.is_popup ){
	jQuery( '#bc_swfplayer_wrap' ).prepend(playlist);
	jQuery( '#' + this.container_id ).append(options);
  }else{
	jQuery( '#' + this.container_id ).append(options);
	jQuery( '#' + this.container_id ).append(playlist);
  }

	jQuery("a.bc_genre").click( function(){
	  jQuery("a.bc_genre_selected").addClass("bc_genre").removeClass("bc_genre_selected");
	  jQuery(this).removeClass("bc_genre");
	  jQuery(this).addClass("bc_genre_selected");
	});
	jQuery("a.bc_type").click( function(){
	  jQuery("a.bc_type_selected").addClass("bc_type").removeClass("bc_type_selected");
	  jQuery(this).removeClass("bc_type").addClass("bc_type_selected");
	});
	jQuery("a.bc_toggle").toggle( function(){
	  jQuery(this).removeClass("bc_option").addClass("bc_option_selected");
	}, function(){
	  jQuery(this).removeClass("bc_option_selected").addClass("bc_option");
	});
	jQuery(".bc_alphabet a").click( function(){
	  jQuery(".bc_alphabet a.bc_selected").removeClass("bc_selected");
	  jQuery(this).addClass("bc_selected");
	});


}



function BCVideo( data ){

  this.vid_id = data.vid_id ? data.vid_id : 0;
  this.swf_path = data.swf_path ? data.swf_path : "swf/bc_player.swf";
  this.container_id = data.container_id ? data.container_id : 'bc_player';
  this.queueVideoInterval = 0;
  this.flashReady = false;

	this.active_color = (data.active_color != undefined) ? data.active_color : "#000000";	// default black
	this.inactive_color = (data.inactive_color != undefined) ? data.inactive_color : "#000000";	// default black
	this.icon_on_color = (data.icon_on_color != undefined) ? data.icon_on_color : "#000000";	// default black
	this.icon_off_color = (data.icon_off_color != undefined) ? data.icon_off_color : "#000000";	// default black
	this.bar_bg_color = (data.bar_bg_color != undefined) ? data.bar_bg_color : "#000000";	// default black

  bcvid_cache = this;

  // add in the swf player

  var flashvars = {};
  flashvars.active_color = "0x" + this.active_color.substring(1);
  flashvars.inactive_color = "0x" + this.inactive_color.substring(1);
  flashvars.icon_on_color = "0x" + this.icon_on_color.substring(1);
  flashvars.icon_off_color = "0x" + this.icon_off_color.substring(1);
  flashvars.bar_bg_color = "0x" + this.bar_bg_color.substring(1);

  var params = {wmode:"opaque",allowfullscreen:"true"};
  swfobject.embedSWF(this.swf_path, this.container_id, "440", "359", "9.0.18",null,flashvars,params);

  // play the first video
  if( this.vid_id > 0 ){
	//this.queueVideoInterval = setInterval( "bcvid_cache.loadVideo(" + this.vid_id + ");", 1000 );
  }

  BCVideo.prototype.flashLoaded = function(){
	this.flashReady = true;
  }

  BCVideo.prototype.loadVideo = function( vid_id ){

	if( vid_id == this.vid_id ){
	  if( this.flashReady == false ){
		return;
	  }

	  swfVideo = ( jQuery.browser.msie ? window[this.container_id] : document[this.container_id] );
	  if( swfVideo.loadNewVid ){
		swfVideo.loadNewVid( vid_id );
		this.vid_id = vid_id;
		clearInterval( this.queueVideoInterval );
	  }
	}else{
	  this.vid_id = vid_id;
	  this.queueVideoInterval = setInterval( "bcvid_cache.loadVideo(" + vid_id + ");", 1000 );
	}
  }

  BCVideo.prototype.getCurrentVideoId = function(){
	return this.vid_id;
  }

  BCVideo.prototype.play = function(){
	swfVideo = ( jQuery.browser.msie ? window[this.container_id] : document[this.container_id] );
	if( swfVideo.playVideo ){
	  swfVideo.playVideo();
	}
  }

  BCVideo.prototype.pause = function(){
	swfVideo = ( jQuery.browser.msie ? window[this.container_id] : document[this.container_id] );
	if( swfVideo.pauseMovie ){
	  swfVideo.pauseMovie();
	}
  }
}

function BCPlaylist( data ){

  this.sequential_videos = false;
  this.random_videos = false;

  this.current_videos = false;

  this.cropLetter = false;
  this.cropField = 'artist';

  this.random_play = false;
  this.current_video_id = false;

}
BCPlaylist.prototype.cropBy = function(letter,field){
  this.cropField = (field != undefined) ? field : 'artist';
  this.cropLetter = (letter == 'all') ? false : letter;
  if( this.cropLetter ){
	vids = this.random_play ? this.random_videos : this.sequential_videos;
	this.current_videos = [];
	for(i=0; i<vids.length; i++){
	  if( vids[i][this.cropField].toLowerCase().substring(0,1) == this.cropLetter.toLowerCase().substring(0,1) ){
		this.current_videos[ this.current_videos.length ] = vids[i];
	  }
	}
  }else{
	this.current_videos = this.random_play ? this.random_videos.slice() : this.sequential_videos.slice();
  }
}
BCPlaylist.prototype.setVideos = function(videos){
	this.sequential_videos = videos;
	this.random_videos = videos.slice();
	if( videos.length > 0 ){
	// shuffle the vids
	for( var j,x,i = this.random_videos.length; i; j = parseInt(Math.random() * i), x = this.random_videos[--i], this.random_videos[i] = this.random_videos[j], this.random_videos[j] = x);
	if( this.random_play ){
	  this.current_videos = this.random_videos.slice();
	  this.current_video_id = this.random_videos[0]['id'];
	}else{
	  this.current_videos = this.sequential_videos.slice();
	  this.current_video_id = this.sequential_videos[0]['id'];
	}
	}
}
BCPlaylist.prototype.toggleRandom = function(){
  this.random_play = !this.random_play;
  if( this.random_play ){
	this.current_videos = this.random_videos.slice();
  }else{
	this.current_videos = this.sequential_videos.slice();
  }
  this.cropBy( this.cropLetter, this.cropField );
}
BCPlaylist.prototype.getCurrentVideo = function(){
	for(i=0; i<this.sequential_videos.length; i++){
	  if( this.sequential_videos[i]['id'] == this.current_video_id ){
		return this.sequential_videos[i];
	  }
	}
	return false;
}
BCPlaylist.prototype.setCurrentVideo = function(vid_id){
	this.current_video_id = vid_id;
}
BCPlaylist.prototype.nextVideo = function(){
	if( !this.current_video_id ){
	  i=0;
	  this.current_video_id = this.current_videos[0]['id'];
	  return this.current_videos[0]['id'];
	}else{
	  for(i=0; i<this.current_videos.length; i++){
		if( this.current_videos[i]['id'] == this.current_video_id ){
		  next_vid_index = i+1;
		  if( next_vid_index < this.current_videos.length ){
			this.current_video_id = this.current_videos[next_vid_index]['id'];
			return this.current_videos[next_vid_index]['id'];
		  }
		}
	  }
	  // if we didn't find another video, start over
	  if( this.current_videos.length > 0 ){
		this.current_video_id = false;
		return this.nextVideo();
	  }
	}
}

String.prototype.trim = function(){
  return this.replace(/^\s+|\s+$/g,"");
}








