	//Search parameter
	if(par_s == false)
		var search = '';
	else
		search = '&s='+search;

	//Tag parameter
	if(par_t == false)
		var tag = '';
	else
		tag = '&t='+tag;

	//Blog parameter
	if(par_b == false)
		var blog = '';
	else
		blog = '&b='+blog;
		
	if(set == 1)
		{
			var advanced = '';
			var string = ["all_words", "exact_words", "any_words", "none_words", "tag", "band", "album", "year", "country", "genre", "category", "start_date", "end_date", "blog_in", "blog_out", "clicks", "comments"];
			for(var i = 0; i < 17; i++)
				{
					if(adv[i] != '' && adv[i] != 'undefined')
						advanced += '&'+string[i]+'='+adv[i];
				}
		}
	else
		var advanced = '';

/*
* Source: http://codigofonte.uol.com.br/codigo/js-dhtml/browser/adicionar-aos-favoritos-no-ie,-mozilla-firefox-e-opera
*/
function addFav(url, title){
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}


//search, tag , blog, adv-search e root serão definidos no javascript do html
$(document).ready(function()
	{
		/*
		* Source: http://www.queness.com/post/309/create-a-digg-style-post-sharing-tool-with-jquery
		*/
		var ShareIt = function()
			{
					//grab all the anchor tag with rel set to shareit
					$('a[rel$=shareit], #shareit-box').mouseenter(function() {		
						
						//get the height, top and calculate the left value for the sharebox
						var height = $(this).height();
						var top = $(this).offset().top;
						
						//get the left and find the center value
						var left = $(this).offset().left + ($(this).width() /2) - ($('#shareit-box').width() / 2);		
						
						//grab the href value and explode the bar symbol to grab the url and title
						//the content should be in this format url|title
						var value = $(this).attr('href').split('|');
						
						//assign the value to variables and encode it to url friendly
						var field = value[0];
						var url = encodeURIComponent(value[0]);
						var title = encodeURIComponent(value[1]);
						var id = encodeURIComponent(value[2]);
						
						//assign the height for the header, so that the link is cover
						$('#shareit-header').height(height);
						
						//display the box
						$('#shareit-box').show();
						
						//set the position, the box should appear under the link and centered
						$('#shareit-box').css({'top':top, 'left':left});
						
						//assign the url to the textfield
						$('#shareit-field').val(field);
						
						//Setup the bookmark media url and title
						$('a[rel$=shareit-print]').attr('href', 'javascript:window.print()');
						$('a[rel$=shareit-mail]').attr('href', 'mailto:?subject=' + title + '&body=' + url);
						$('a[rel$=shareit-fav]').attr('href', 'javascript:addFav("' + url + '", "' + title + '")');
						$('a[rel$=shareit-rss]').attr('href', root + 'feed/rss/?id=' + id);
						$('a[rel$=shareit-delicious]').attr('href', 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + url + '&title=' + title);
						$('a[rel$=shareit-digg]').attr('href', 'http://digg.com/submit?phase=2&amp;url=' + url + '&amp;title=' + title);
						$('a[rel$=shareit-stumbleupon]').attr('href', 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title);
						$('a[rel$=shareit-twitter]').attr('href', 'http://twitter.com/home?status=' + title + '%20-%20' + url);
						$('a[rel$=shareit-facebook]').attr('href', 'http://www.facebook.com/share.php?u=' + url + '&t=' + title);
						$('a[rel$=shareit-google]').attr('href', 'http://www.google.com/bookmarks/mark?op=edit&bkmk=' + url + '&title=' + title);
						$('a[rel$=shareit-orkut]').attr('href', 'http://promote.orkut.com/preview?nt=orkut.com&tt=' + title + '&du=' + url);
						$('a[rel$=shareit-technorati]').attr('href', 'http://technorati.com/faves?add=PERMALINK' + url);
						$('a[rel$=shareit-friendfeed]').attr('href', 'http://www.friendfeed.com/share?title=' + title + '&link=' + url);
						$('a[rel$=shareit-linkedin]').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&source=metal4share');
						$('a[rel$=shareit-reddit]').attr('href', 'http://reddit.com/submit?url=' + url + '&title=' + title);
						$('a[rel$=shareit-yahoo]').attr('href', 'http://bookmarks.yahoo.com/toolbar/savebm?u=' + url + '&t=' + title + '&opener=bm&ei=UTF-8');
						$('a[rel$=shareit-live]').attr('href', 'https://favorites.live.com/quickadd.aspx?marklet=1&url=' + url + '&title=' + title);
					});

					//onmouse out hide the shareit box
					$('#shareit-box').mouseleave(function () {
						$('#shareit-field').val('');
						$(this).hide();
					});
					
					//hightlight the textfield on click event
					$('#shareit-field').click(function () {
						$(this).select();
					});
					
					//Set rel=external links to open in new window
					$(function() {
							$('a[rel^=external]').click( function() {
								window.open(this.href);
								return false;
							});
					});
			}
		
		
		var loadContent = function(target)
			{
				$(target).click(function() 
					{
						var current = $(this);
						var current_parent = $(this).parent();
						var current_type = $(current_parent).parent().attr('id');
						
						//Seleciona os seletores atuais
						var foo = [];				
						$('.current a').each(function(i, selected){
							foo[i] = $(selected).attr('id');
						});
						var sort = foo[1];
						var cat = foo[2];
						
						//Seleciona a página
						var page = $(this).html();
						if(page.match(/[0-9]/))
							page = '&page='+page;
						else
							page = '';
						
						//Marca item atual
						$(current_parent).addClass("current");
						
						//Seletor de abas (sortion)
						if(current_type == 'content-sortion')
							{
								$('#content-sortion li').each(function(i, selected){
									if($(selected).html() != $(current_parent).html())
										{
											$(selected).removeClass("current");
											
										}
								});
								
								sort = $(current).attr('id');
							}
						
						//Seletor de abas (categories)
						if(current_type == 'content-categories')
							{
								$('#content-categories li').each(function(i, selected){
									if($(selected).html() != $(current_parent).html())
										{
											$(selected).removeClass("current");
											
										}
								});
								
								cat = $(current).attr('id');
							}
							
						//Alteração do título
						if(par_s == false && par_t == false && par_b == false && advanced == '')
							{
								//Título
								var text = '';
								if(sort == 'recent')
									text += 'Last';
								else if(sort == 'today')
									text += 'Top today';
								else if(sort == 'alltime')
									text += 'Top all time';
								else
									text += 'Top last '+sort;
								
								if(cat == 'all')
									text += ' albums, videos, discogs';
								else if(cat == 'discography')
									text += ' discographies';
								else
									text += ' '+cat+'s';
								
								$("#content-title").html('<h1>'+text+'</h1>');
								//document.getElementById('content-title').innerHTML = '<h1>'+text+'</h1>';
							}

						//Posiciona janela
						if($(current_parent).attr('id') == 'pagenavi')
							document.getElementById('content-header').scrollIntoView();
						
						//Inicia Loader
						$("#content-posts").html('<div id="load"></div><img id="load_img" src="' + root + 'layout/images/loadingAnimation.gif" alt="Loading..." />');
						$("#load").css({"height": $("#content").height() + 18, "width": $("#content").width() + 19,"top": $("#content").position().top, "left": $("#content").position().left});

						$("#load").fadeTo(0, 0.3, function () {
							$("#load").fadeIn();
							$("#load").css("background-color","#000000");
						});

						//Carrega o conteúdo
						$.ajax(
							{
								type: "GET",
								url: root + "content/",
								data: 'sort=' + sort + '&cat=' + cat + page + tag + search + blog + advanced,
								cache: false,
								success: function(html)
									{
										//Fecha Loader
										$("#load, #load_img").fadeOut(200);
										
										//Insere conteúdo na div
										$("#content-posts").html(html);
										
										//Recarrega onclick para pagenavi
										loadContent("#pagenavi a");
										
										//Recarrega ShareIt
										ShareIt();
									}
							});
						return false;
					});
			}
			
		var sidebarLoader = function(target)
			{
				$(target).click(function() 
					{
						var div = $(this).parent().parent();
						var href = $(this).attr('href');
						
						$(div).html('<h3><span>Top Blogs</span></h3><img style="margin:40px 0 11px 38px;" src="' + root + 'layout/images/loadingAnimation.gif" alt="Loading..." />');
						
						$.ajax(
							{
								type: "GET",
								url: href,
								cache: false,
								success: function(html)
									{
										//Insere conteúdo na div
										$(div).html(html);
										
										sidebarLoader(target);
									}
							});
						return false;
					});
			}
			
		//Carrega onclick para todos elementos
		loadContent("#content-sortion li a, #content-categories li a, #pagenavi a");
		
		//Carrega ShareIt
		ShareIt();
		
		sidebarLoader('#top-blogs .sidebar-period a');
		sidebarLoader('#popular-tags .sidebar-period a');
		
		
	});