$(document).ready(function() {

	// External links
	
	$('a').each(function() {
		if($(this).attr('rel') == 'external') {
			$(this).click(function() {
				window.open($(this).attr('href'));
				return false;
			});
		}
	});

	// Initialize
	
	scrollbars.initialize();
	menus.initialize();
	flyouts.initialize();
	if(!$('#editform').length) playlist.initializeViewable();
	else playlist.initializeEditable();
	
	// Hide unopened tabs 
	
	$('#right-container .scrollbar').each(function() {
		if(!$(this).hasClass('selected')) $(this).hide();									  
	});
	
	// Campaign text tabs
	
	tabs.add('#text-tabs a', '#text-areas .scrollbar');
	
	// Flash
	
	flashScript.isReady = true;

});

// Scrollbars

var scrollbars = {
	scrollSpeed: 10,
	initialize: function() {
		$('.scrollbar').each(function() {
			scrollbars.addScroll($(this));
		});
		$(document).mousedown(function() {
			if(scrollbars.focused) {
				scrollbars.focused = null;
				window.onmousewheel = document.onmousewheel = '';
				if(window.removeEventListener)
					window.removeEventListener('DOMMouseScroll', scrollbars.wheel, false);
			}
		}).mouseup(function() {
			scrollbars.stoploop();
		});
	},
	addScroll: function(x) {
		var content = x.html();
		x.css('overflow', 'hidden').html(
			'<div class="scrollbar-content">' + content + '</div>' +
			'<div class="scrollbar-control">' +
			'<div class="scrollbar-up"></div>' +
			'<div class="scrollbar-track">' +
			'<div class="scrollbar-handle"></div></div>' +
			'<div class="scrollbar-down"></div></div>'
		);
		x.find('div').attr('unselectable', 'on');
		x.find('.scrollbar-track:first').height(x.height() - 18);		
		x.append('<div id="__temp"></div>');
		$('#__temp').css({
			position: 'absolute',
			left: -9999,
			width: x.find('.scrollbar-content').width()
		}).html(content);
		var viewable = x.height() - 12;
		var height = $('#__temp').height();
		var percent = (viewable / height) * viewable;
		var size = viewable - percent;
		if(size < 0) size = 0;
		var resize = Math.round(viewable - size);
		if(resize < 12) resize = 12;
		var handle = x.find('.scrollbar-handle:first');
		var track = x.find('.scrollbar-track:first');
		$(handle).height(resize);
		if(resize + 4 > track.height()) size = 0;
		if(size == 0) x.find('.scrollbar-control:first').remove();
		var maxScroll = $(track).height() - (resize + 2);
		$(handle).mousedown(function(event) {
			var targetHandle = $(this);
			var targetContent = $(this).parent().parent().parent().find('.scrollbar-content:first');
			var targetStart = event.clientY - parseInt($(this).css('marginTop'));
			$(document).unbind('mousemove').mousemove(function(event) {
				var offsetHandle = event.clientY - targetStart;
				if(offsetHandle < 0) offsetHandle = 0;
				if(offsetHandle > maxScroll) offsetHandle = maxScroll;
				$(targetHandle).css({marginTop: offsetHandle});
				var offsetPercent = offsetHandle / maxScroll;
				var offsetRange = height - viewable;
				var offsetContent = 0 - (offsetPercent * offsetRange);
				$(targetContent).css({marginTop: offsetContent});
			}).mouseup(function() {
				$(document).unbind('mousemove');
			});
			return false;
		});
		var scrollTimer = null;
		x.find('.scrollbar-up:first').mousedown(function() {
			scrollbars.direction = 'up';
			scrollbars.target = $(this).parent().parent().find('.scrollbar-content:first');
			scrollbars.startloop();
		});
		x.find('.scrollbar-down:first').mousedown(function() {
			scrollbars.direction = 'down';
			scrollbars.target = $(this).parent().parent().find('.scrollbar-content:first');
			scrollbars.startloop();
		});
		$('.scrollbar').mouseup(function() {
			if($(this).find('.scrollbar-control').length) {
				scrollbars.focused = $(this).find('.scrollbar-content:first');
				window.onmousewheel = document.onmousewheel = scrollbars.wheel;
				if(window.addEventListener) {
					window.addEventListener('DOMMouseScroll', scrollbars.wheel, false);
				}
			}
		});
		$('#__temp').remove();	
	},
	startloop: function() {
		this.timer = setInterval("scrollbars.doloop()", 10);
		this.offset = parseInt($(this.target).css('marginTop')) || 0;
		this.maximum = $(this.target).height() - $(this.target).parent().height();
	},
	doloop: function() {
		if(this.direction == 'up') this.offset = this.offset + this.scrollSpeed;
		else this.offset = this.offset - this.scrollSpeed;
		var maxneg = 0 - this.maximum;
		if(this.offset >= 0) this.offset = 0;
		if(this.offset <= maxneg) this.offset = maxneg;
		$(this.target).css({marginTop: this.offset});
		var track = $(this.target).parent().height() - 20;
		var handle = $(this.target).parent().find('.scrollbar-handle:first').height();
		var top = (-this.offset / this.maximum) * (track - handle);
		$(this.target).parent().find('.scrollbar-handle:first').css({marginTop: top});
	},
	stoploop: function() {
		if(this.timer) clearInterval(this.timer);
	},
	wheel: function(event) {
		var delta = 0;
		if(!event) event = window.event;
		if(event.wheelDelta) {
			delta = event.wheelDelta / 120;
			if (window.opera) delta = -delta;
		}
		else if(event.detail) delta = -event.detail / 3;
		if(delta) scrollbars.wheelHandler(delta);
		if(event.preventDefault) event.preventDefault();
		event.returnValue = false;
	},
	wheelHandler: function(delta) {
		if(scrollbars.focused) {
			scrollbars.target = scrollbars.focused;
			scrollbars.offset = parseInt($(scrollbars.target).css('marginTop')) || 0;
			scrollbars.maximum = $(scrollbars.target).height() - $(scrollbars.target).parent().height();
			if(delta < 0) scrollbars.direction = 'down';
			else scrollbars.direction = 'up';
			scrollbars.doloop();
		}
	}
}


// Menus

var menus = {
	initialize: function() {
		$('.menu-trigger').click(function() {
			$('.select-menu div').hide();
			$(document.body).click(function() {
				$('.select-menu div').hide().css('height', 'auto');
			});
			var menu = $(this).parent().find('div:first');
			if(menu.find('a').length) {
				menu.css('marginTop', -99999).show();
				if(menu.height() > 120) menu.css({ height: 120, overflow: 'auto' });			
				menu.css('marginTop', -1);
			}
			return false;
		});
	}
}

// Tabs

var tabs = {
	add: function(a, b) {
		$(a).click(function() {
			tabs.change(a, b, this);	
			this.blur();
			return false;
		});
	},
	change: function(a, b, c) {
		$(a).parent().removeClass('selected');
		$(b).hide().removeClass('selected');
		var e = c.href.substring(c.href.indexOf('#'), c.href.length);
		$(e).show().addClass('selected');
		$(c).parent().addClass('selected');
	}
}


// Playlist

var playlist = {
	viewable: 11,
	itemWidth: 68,
	items: 10,
	index: 0,
	getId: function(e) {
		if($(e).length) {
			var href = $(e).attr('href');
			var id = href.substring(href.indexOf('#') + 1, href.length);
			return parseInt(id);
		}
		else return false;
	},
	initializeViewable: function() {
		if($('#playlist-labels').length) this.viewable = 10;
		var row1 = $('#playlist-content div').eq(0).find('a').length || 0;
		var row2 = $('#playlist-content div').eq(1).find('a').length || 0;
		var row3 = $('#playlist-content div').eq(2).find('a').length || 0;
		var largest = row1 > row2 ? row1 : row2;
		largest = largest > row3 ? largest : row3;
		if(largest > playlist.viewable) $('#playlist').addClass('scroll-enabled');
		this.maximum = largest * playlist.itemWidth;
		this.campaign = $('#text-container').length ? false : true;
		if(this.campaign) this.offset = playlist.itemWidth * playlist.items;
		else this.offset = playlist.itemWidth * playlist.viewable;
		this.current = 0;
		this.intro = $('#text-container').html() || '';
		this.started = false;
		this.storeDefaultText = $('#playlist-bar .left:first').html();
		$('#playlist-content a').click(function() {
			playlist.started = true;
			if(flyouts.current) flyouts.collapse(flyouts.current);
			$('.select-menu div').hide().css('height', 'auto');
			var id = playlist.getId($(this));
			if(!playlist.campaign) {
				var selIndex = 0;
				$('#playlist-content a').each(function(idx) {
					if(playlist.getId($(this)) == id) selIndex = idx + 1;
				});
				playlist.advance(0, false, selIndex);
			}
			else {
				$('#playlist-content a').removeClass('selected');
				$(this).addClass('selected');	
			}
			flashPlayer('player').goto(id);
			playlist.flyouts(id);
			return false;
		});
		$('#controls-start').click(function() {
			playlist.started = true;
			playlist.advance(1, true);
			return false;
		});
		$('#play-all-ads').click(function() {
			flashScript.playAllAds();
			return false;
		});
		playlist.buttons();
	},
	initializeEditable: function() {
		this.listorder = [];
		this.descriptions = enteredText.length ? enteredText : [];
		this.animating = false;
		this.temp = '<a class="temp"></a>';
		this.offset = playlist.itemWidth * playlist.viewable;
		this.campaign = false;
		this.current = 0;
		this.editing = playlist.getId($('#playlist-content a:first')) || null;
		this.storeDefaultText = $('#playlist-bar .left:first').html();
		$('#commercial-pool .resource a').click(function() {
			var id = playlist.getId($(this));
			if($(this).hasClass('button-add')) {
				playlist.editing = id;
				$(this).removeClass('button-add').addClass('button-remove').html('Remove from Playlist');
				var src = $(this).parent().parent().find('img:first').attr('src');
				var title = $(this).parent().find('strong:first').html();
				$('#playlist-content div:first').append('<a href="#' + id
				+ '" class="media"><img src="' + src + '" alt="' + title + '" /></a>');
				$('#commercial-desc').val(playlist.descriptions[parseInt(id)] || '');
				$('#edit-commercial-info img:first').attr('src', src);
				$('#edit-commercial-info strong:first').html(title);
				$('#remove-commercial').show();
				var off = Math.floor($('#playlist-content a').length / (playlist.viewable + 1));
				off = -off * (playlist.viewable * playlist.itemWidth);
				playlist.current = off;
				$('#playlist-content').animate({'marginLeft': off}, function(){ playlist.order(); });
			}
			else playlist.removeItem(id);
			playlist.order();
			return false;
		});
		$('#remove-commercial').click(function() {
			if(playlist.editing) playlist.removeItem(playlist.editing);
			return false;
		});
		$('#commercial-desc').blur(function() {
			playlist.descriptions[parseInt(playlist.editing)] = $('#commercial-desc').val();						
		});
		$('#save-playlist').click(function() {
			playlist.save();
			return false;
		});
		playlist.order();
	},
	removeItem: function(id) {
		$('#playlist-content a').each(function() {
			if(playlist.getId($(this)) == id) $(this).remove();
		});
		$('#commercial-pool a').each(function() {
			if(playlist.getId($(this)) == id)
				$(this).removeClass('button-remove').addClass('button-add').html('Add to Playlist');
		});
		var off = Math.floor($('#playlist-content a').length / (playlist.viewable + 1));
		off = -off * (playlist.viewable * playlist.itemWidth);
		if(parseInt($('#playlist-content').css('marginLeft')) < off) {
			playlist.current = off;
			$('#playlist-content').animate({'marginLeft': off}, function() { playlist.order(); });
		}
		if(playlist.editing == id) {
			$('#edit-commercial-info img:first').attr('src', '/images/global/blank.gif');
			$('#edit-commercial-info strong:first').html('');
			$('#remove-commercial').hide();
			playlist.editing = null;
		}
	},
	buttons: function() {
		if($('#playlist').hasClass('scroll-enabled')) {
			var off = playlist.current;
			if(off == 0) $('#playlist-left').css({
				'background': 'url(/images/global/arrow-left-disabled.gif) center center no-repeat',
				'cursor': 'default'
			});
			else $('#playlist-left').css({
				'background': 'url(/images/global/arrow-left.gif) center center no-repeat',
				'cursor': 'pointer'
			});
			if(off - playlist.offset <= -playlist.maximum) $('#playlist-right').css({
				'background': 'url(/images/global/arrow-right-disabled.gif) center center no-repeat',
				'cursor': 'default'
			});
			else $('#playlist-right').css({
				'background': 'url(/images/global/arrow-right.gif) center center no-repeat',
				'cursor': 'pointer'
			});
		}
		$('#playlist-left').unbind('click').click(function() {
			if($('#playlist').hasClass('scroll-enabled')) {
				var off = playlist.current + playlist.offset;
				if(off > 0) off = 0;
				playlist.current = off;
				$('#playlist-content').animate({'marginLeft': off});
				playlist.buttons();
			}
			return false;
		});
		$('#playlist-right').unbind('click').click(function() {
			if($('#playlist').hasClass('scroll-enabled')) {
				var off = playlist.current - playlist.offset;
				if(off <= -playlist.maximum) off = playlist.current;
				playlist.current = off;
				$('#playlist-content').animate({'marginLeft': off});
				playlist.buttons();
			}
			return false;
		});
		$('#playlist-content a').unbind('hover').hover(function() {
			$('#playlist-bar .left:first').html($(this).attr('title'));
		}, function() {
			$('#playlist-bar .left:first').html(playlist.storeDefaultText);										
		});
	},
	advance: function(i, v, j, p) {
		if(j) playlist.index = parseInt(j);
		else playlist.index = playlist.index + i;
		if(playlist.index > 0) {
			$('#playlist-controls').html('<a href="#" id="controls-back">BACK</a>')
			.append('<a href="' + document.location.href + '" id="controls-restart">START OVER</a>')
			.append('<a href="#" id="controls-next">NEXT</a>');
			if($.browser.mozilla && navigator.userAgent.indexOf('Windows') > -1) {
				$('#controls-next').css('padding-top', '0');
				$('#controls-back').css('padding-top', '0');
				$('#controls-restart').css('padding-top', '0');
			}
			$('#controls-back').click(function() {
				playlist.advance(-1, true);
				return false;
			});
			$('#controls-next').click(function() {
				playlist.started = true;
				playlist.advance(1, true);
				return false;
			});
			var id = playlist.getId($('#playlist-content a').eq(playlist.index - 1));
			$('#text-container').html($('#description-' + id).html());
			scrollbars.addScroll($('#text-container'));
			if(playlist.index == $('#playlist-content a').length) $('#controls-next').hide();
		}
		else {
			playlist.started = false;
			$('#playlist-controls').html('<a href="#" id="controls-start">START</a>');
			$('#controls-start').click(function() {
				playlist.started = true;
				playlist.advance(1, true);
				return false;
			});
			$('#text-container').html(playlist.intro);
			var id = playlist.getId($('#playlist-content a').eq(playlist.index));
		}
		if(v) flashPlayer('player').goto(id);	
		playlist.flyouts(id);
		$('#playlist-content a').removeClass('selected').eq(playlist.index - 1).addClass('selected');
		var off = Math.floor(playlist.index / (playlist.viewable + 1));
		off = -off * (playlist.viewable * playlist.itemWidth);
		$('#playlist-content').animate({'marginLeft': off});
	},
	flyouts: function(id) {
		$.getJSON('/commercials/ajax/' + id, function(data) {
			flashScript.curatorial = false;
			if(data.title) {
				$('#curatorial-text h4:first').html('"' + data.title + '"');
			}
			if(data.curatorial_text) {
				$('#curatorial-text .scrollbar:first').html(data.curatorial_text);
				scrollbars.addScroll($('#curatorial-text .scrollbar:first'));
			}
			if(data.transcript) {
				$('#transcript-text .scrollbar:first').html(data.transcript);
				scrollbars.addScroll($('#transcript-text .scrollbar:first'));
			}
			if(data.credits) {
				$('#credit-text .scrollbar:first').html(data.credits);
				scrollbars.addScroll($('#credit-text .scrollbar:first'));
			}
			if(data.share) {
				$('#share-text .scrollbar:first').html(data.share);
				scrollbars.addScroll($('#share-text .scrollbar:first'));
			}
			if($('#related-items').length) {
				var commercials = '';
				var menuImg = '/images/global/menu-commercials-disabled.gif';
				if(data.commercials) {
					for(var i in data.commercials) {
						commercials += '<a href="' + data.commercials[i][0] + '">'
						+ data.commercials[i][1] + '</a>';
					}
					menuImg = '/images/global/menu-commercials.gif';
				}
				$('#related-items .menu-trigger').eq(0).find('img:first').attr('src', menuImg);
				$('#related-commercials').html(commercials);
				var playlists = '';
				var menuImg = '/images/global/menu-playlists-disabled.gif';
				if(data.playlist_activities) {
					for(var i in data.playlist_activities) {
						playlists += '<a href="' + data.playlist_activities[i][0] + '">'
						+ data.playlist_activities[i][1] + '</a>';
					}
					menuImg = '/images/global/menu-playlists.gif';	
				}
				$('#related-items .menu-trigger').eq(1).find('img:first').attr('src', menuImg);
				$('#related-playlists').html(playlists);
			}
		});		
	},
	order: function() {
		var items = $('#playlist-content a').length;
		playlist.maximum = items * playlist.itemWidth;
		playlist.buttons();
		if(items > playlist.viewable)
			$('#playlist').addClass('scroll-enabled');
		else $('#playlist').removeClass('scroll-enabled');
		$('#playlist-content a').each(function() {
			$(this).attr('unselectable', 'on').find('img').attr('unselectable', 'on');
		}).unbind('mousedown').mousedown(function(event) {
			$('#playlist-content .selected').removeClass('selected');
			$(this).addClass('selected');
			playlist.descriptions[playlist.editing] = $('#commercial-desc').val();
			playlist.editing = playlist.getId($(this));
			$('#edit-commercial-info img:first').attr('src', $(this).find('img').attr('src'));
			$('#edit-commercial-info strong:first').html($(this).find('img').attr('alt'));
			$('#commercial-desc').val(playlist.descriptions[playlist.editing] || '');
			$('#remove-commercial').attr('href', '#' + playlist.editing).show();
			playlist.clone = $(this).clone(true);
			playlist.active = $(this).css({
				left: Math.round(event.clientX - (playlist.itemWidth / 2))
			}).removeClass('media').addClass('media-drag').after(playlist.temp);
			var l = null;
			var m = playlist.itemWidth;
			var w = $(window).width();
			var p = playlist.active.parent().parent().parent().width();
			var media = $(playlist.active.parent()).find('.media');
			playlist.scrolling = false;
			$(document).unbind('mousemove').mousemove(function(event) {
				var ml = parseInt(playlist.active.parent().parent().css('marginLeft')) || 0;
				var xo = Math.round(event.clientX - (playlist.itemWidth / 2));
				var x = xo - ((w / 2) - (p / 2)) - m;
				var o = 0;
				var i = (Math.round((p / m) - ((p - x) / m)) + o) - 1;
				if(i >= media.length) i = media.length - 1;
				if(i != l) {
					$('#playlist .temp').remove();
					var off = Math.round(-ml / m) - o;
					var io = i + off;
					if(io > -1) {
						if(io > media.length) media.eq(media.length - 1).after(playlist.temp);
						else media.eq(io).after(playlist.temp);
					}
					else media.eq(0).before(playlist.temp);
					l = i;
				}
				if(((i - o < -1) &&  (ml != 0)) || (i - o >= playlist.viewable - 1)) {
					if(!playlist.scrolling) {
						playlist.scrolling = true;
						playlist.direction = (i - o < -1) ? 'left' : 'right';
						$('#playlist .temp').remove();
						if(playlist.direction == 'right') {
							$('#playlist-content').find('.media:last').after(playlist.temp);
							var off = playlist.current - playlist.offset;
							if(off < -playlist.maximum) off = playlist.current;
							playlist.current = off;
							$('#playlist-content').animate({'marginLeft': off});
						}
						else {
							$('#playlist-content').find('.media:first').before(playlist.temp);
							var off = playlist.current + playlist.offset;
							if(off > 0) off = 0;
							playlist.current = off;
							$('#playlist-content').animate({'marginLeft': off});
						}
					}
				}
				else {
					playlist.scrolling = false;
					clearTimeout(playlist.moveTimer);	
				} 
				playlist.active.css('left', xo);
			});
			$(document).unbind('mouseup').mouseup(function(event) {
				$(document).unbind('mousemove').unbind('mouseup');
				playlist.scrolling = false;
				clearTimeout(playlist.moveTimer);
				var t = $('#playlist .temp');
				if(playlist.active.parent().find('.media').length > 0) {
					t.after(playlist.clone);
					t.remove();
					playlist.active.remove();
					playlist.order();
				}
				else {
					t.remove();
					playlist.active.after(playlist.clone);
					playlist.active.remove();
				}
			});
			return false;
		});	
	},
	save: function() {
		$('#playlist-fields').html('');
		if(!$('#playlist-name').val().length) {
			alert('Please give your playlist a title before saving...');	
		}
		else if($('#playlist-content a').length) {
			$('#playlist-content a').each(function(i) {
				var id = playlist.getId($(this));
				var desc = playlist.descriptions[id] || '';
				$('#playlist-fields').append('<input type="hidden" name="commercials[' + i + '][id]" value="' + id + '" />');
				$('#playlist-fields').append('<textarea name="commercials[' + i + '][description]">' + desc + '</textarea>');
			});
			$('#editform').submit();
		}
		else alert('Add at least one commercial to your playlist before saving...');
	}
}


// Flyouts

var flyouts = {
	width: 370,
	initialize: function() {
		$('.close-button a').click(function() {
			var target = $(this).parent().parent();
			flyouts.collapse(target);
			return false;									
		});
		flyouts.current = null;
	},
	expand: function(x) {
		$('#flyouts').width(flyouts.width);
		if(flyouts.current) {
			flyouts.current.removeClass('open');
			flyouts.current.animate({'marginLeft': -flyouts.width})
		}
		x.animate({'marginLeft': 0}, 'slow');
		flyouts.current = x;
	},
	collapse: function(x) {
		x.removeClass('open');
		x.animate({'marginLeft': -flyouts.width}, 'slow', 
			function(){ if(!$('#flyouts .open').length) $('#flyouts').width(1); });
		flyouts.current = null;
   		flashPlayer('player').unhilite();
	}
}

// Flash player interaction

function flashPlayer(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) return window[movieName]
    else return document[movieName]
}

var flashScript = {
	toggleFlyout: function(x) {
		var id = '#' + x;
		var pos = 'up';
		if(!$(id).hasClass('open')) {
			flyouts.expand($(id).addClass('open'));
			pos = 'down';
		}
		else {
			$('.flyout').removeClass('open');
			flyouts.collapse($(id));
		}
		return pos;
	},
	reportStart: function() {
		if(!playlist.campaign && !playlist.started) {
			playlist.advance(1, false);
			playlist.started = true;
		}
	},
	getNext: function() {
		if(!playlist.campaign && playlist.index < $('#playlist-content a').length) {
			playlist.index ++;
			var id = playlist.getId($('#playlist-content a').eq(playlist.index - 1));
			playlist.advance(0, false, playlist.index);
			return id;
		}
		else return "false";
	},
	getLast: function() {
		if(!playlist.campaign && playlist.index > 0) {
			playlist.index --;
			var id = playlist.getId($('#playlist-content a').eq(playlist.index - 1));
			playlist.advance(0, false, playlist.index);
			return id;
		}
		else return "false";
	},
	getFirst: function() {
		if(!playlist.campaign && playlist.index > 0) {
			playlist.index = 1;
			var id = playlist.getId($('#playlist-content a').eq(0));
			playlist.advance(0, false, playlist.index);
			return id;
		}
		else return "false";
	},
	saveCommercial: function(id) {
		$.get('/commercials/ajax/save/' + id, function(data) {
			var text = '<p>Sorry, something went wrong. Try again later.</p>';
			if(data == 'success' || data == 'saved') {
				text = '<p>This commercial can now be accessed in the<br />';
				text += '<a href="/commercials/saved">Saved Commercials</a> section.</p>';
				text += '<p>You can also create playlists of saved commercials in <br />';
				text += 'the <a href="/commercials/playlists">Playlists section.</a></p>';
			}
			else if(data == 'login') {
				text = '<p>To save ads you must be a registered user.</p>';
				text += '<p><a href="/register">Register now</a> ';
				text += '&nbsp;|&nbsp; <a href="/signin">Sign in</a></p>';
			}
			$('#save-text .scrollbar:first').html(text);
			scrollbars.addScroll($('#curatorial-text .scrollbar:first'));
			flashScript.toggleFlyout('save-text');	
		});			
	},
	playAllAds: function() {
		playlist.started = true;
		playlist.advance(0, true, 1, true);
	}
}



