function installMusicBoxSearchPlaceholder()
{
	Event.observe('mb-search','focus', function(event)
	{
		if(this.value == 'faixa, álbum, banda ou artista')
		{
			this.value = '';	
		}
	});
	
	Event.observe('mb-search','blur', function(event)
	{
		if(this.value == '')
		{
			this.value = 'faixa, álbum, banda ou artista';	
		}
	});
}


/* mb news nav */
var _mbActive = 1;

function installNewsNav()
{
	
	Event.observe('prev-new','click', function(event)
	{
		goNextNew(1);
	});
	
	Event.observe('next-new','click', function(event)
	{
		goPrevNew(1);
	});
	
	$$('.mb-news .pages a').each(function(s, index)
	{
		s.observe('click',function()
		{
			goToNew(index + 1);
		});
	});
}

var newsMoving = false;
function goPrevNew(difference)
{
	if(_mbActive == 3 || newsMoving)
		return;
	
	newsMoving = true;
	var distance = 612;
	if(!difference)
		_mbActive += 1;
	else
	{
		distance = 612 * difference;
		_mbActive += difference;
	}
	
	new Effect.Move('mb-news-slider', {
				x: -distance,y :0,
				afterFinish: function()
				{
					$$('.pages a').each(function(s) {
						s.removeClassName('on');
					});
					$$('.pages a')[_mbActive-1].addClassName('on');
					newsMoving = false;
				}
	});
}

function goNextNew(difference)
{
	if(_mbActive == 1 || newsMoving)
		return;
	
	newsMoving = true;
	var distance = 612;
	if(!difference)
		_mbActive -= 1;
	else
	{
		distance = 612 * difference;
		_mbActive -= difference;
	}
	
	new Effect.Move('mb-news-slider', {
				x: distance,y:0,
				afterFinish: function()
				{
					$$('.pages a').each(function(s) {
						s.removeClassName('on');
					});
					$$('.pages a')[_mbActive-1].addClassName('on');
					newsMoving = false;
				}
	});
}

function goToNew(index)
{
	if(index < _mbActive)
	{
		goNextNew((index - _mbActive) * - 1);
	}
	else if(index > _mbActive)
	{
		goPrevNew(index - _mbActive);
	}
}
/* /mb news nav */


function playlistHpResize()
{
	var list = 555;
	var width = 0;
	$$('#playlist-slider ul').each(function(s, index)
	{
		width += list;
	});
	document.getElementById('playlist-slider').style.width = width + "px";
}

/* playlists hp */
var totalPlaylists = 0;
var activePlaylist = 1;
var playlistWidth = 555;
function installPlaylistsHP()
{
	$$('#playlist-slider ul').each(function(s, index)
	{
		totalPlaylists += 1;
	});
	
	document.getElementById('playlist-slider').style.width = (playlistWidth * totalPlaylists) + 'px';
	
	Event.observe('playlist-prev','click', function(event)
	{
		goNextPlaylist();
	});
	
	Event.observe('playlist-next','click', function(event)
	{
		goPrevPlaylist();
	});
}

var plMoving = false;
function goPrevPlaylist()
{
	if(plMoving || activePlaylist >= totalPlaylists)
		return;
	
	plMoving = true;

	new Effect.Move('playlist-slider', {
				x: -playlistWidth,y :0,
				afterFinish: function()
				{
					plMoving = false;
					activePlaylist++;
				}
	});
}

function goNextPlaylist()
{
	if(plMoving || activePlaylist == 1)
		return;
	
	plMoving = true;
		
	new Effect.Move('playlist-slider', {
				x: playlistWidth,y:0,
				afterFinish: function()
				{
					plMoving = false;
					activePlaylist--;
				}
	});
}
/* /playlists hp */


/* recommended HP */
function recommendedHpResize()
{
	var list = 153;
	var width = 0;
	$$('#mb-recommended-slider li').each(function(s, index)
	{
		width += list;
	});
	document.getElementById('mb-recommended-slider').style.width = width + "px";
}

/* /recommended HP */


//mb-recommended-nav-left

var totalRecommendations = 0;
var activeRecommendation = 1;
var recommendationWidth = 612;
function installRecommendedHP()
{
	
	$$('#mb-recommended-slider li').each(function(s, index)
	{
		totalRecommendations += 1;
	});
	
	totalRecommendations = Math.ceil(totalRecommendations / 4);
	
	Event.observe('mb-recommended-nav-left','click', function(event)
	{
		goNextRecommendation();
	});
	
	Event.observe('mb-recommended-nav-right','click', function(event)
	{
		goPrevRecommendation();
	});
}

var recMoving = false;
function goPrevRecommendation()
{
	if(recMoving || activeRecommendation >= totalRecommendations)
		return;
	
	recMoving = true;

	new Effect.Move('mb-recommended-slider', {
				x: -recommendationWidth,y :0,
				afterFinish: function()
				{
					recMoving = false;
					activeRecommendation++;
				}
	});
}

function goNextRecommendation()
{
	if(recMoving || activeRecommendation == 1)
		return;
	
	recMoving = true;
		
	new Effect.Move('mb-recommended-slider', {
				x: recommendationWidth,y:0,
				afterFinish: function()
				{
					recMoving = false;
					activeRecommendation--;
				}
	});
}


function installMBRelated() {
	if ($('mb-related-top')) {
	
		buttons = $$('div.mb-search-buttons a');
		if (buttons.length == 0)
			return;
		
		buttons[0].addClassName('off');
		tmp = buttons[0].readAttribute('href').split('#');	
		$('mb-related-' + tmp.pop()).show();
		
		buttons.each(function(s) {
			s.observe('click', installMBRelatedClick);
		});
		
		$('mb-related-top').show();
	}
}


function installMBRelatedClick(event) {
	Event.stop(event);

	var element = event.element();
	if (element.hasClassName('off') == true)
		return;
	
	buttons = $$('div.mb-search-buttons a');
	buttons.each(function(s) {
		s.removeClassName('off');
	});
	element.addClassName('off');
	
	$$('div.mb-related').each(function(s) {
		s.hide();
	}); 

	tmp = element.readAttribute('href').split('#');	
	$('mb-related-' + tmp.pop()).show();
	
}
