//var tmpInterval = false;
$(document).ready(function(){
	if(!window.opera){
		$("a#bookmark_link").click(function(event){
			event.preventDefault();
			var url = this.href;
			var title = this.title;
			if (window.sidebar) {
				window.sidebar.addPanel(title, url,"");
			} else if( window.external ) {
				window.external.AddFavorite( url, title);
			} else {
				alert('Infelizmente seu navegador não suporta esse tipo de ação.\nPor favor, adicione aos favoritos manualmente.');
		}
		});
	}
//	$("#q_suggest").autocomplete("/ajax.php", {cacheLength: 0, selectFirst: false});
	$("a.ouvir_musica").bind("click",function(event){
		event.preventDefault();
		event.stopPropagation();
		var form_tmp = $(document.createElement("form")).attr("action",unescape($(this).attr("href"))).attr("id","frm_tmp").attr("method","POST");
		var tmp_hid1 = $(document.createElement("input")).attr("type","hidden").val($(this).attr("v")).attr("name","v");
		var tmp_hid2 = $(document.createElement("input")).attr("type","hidden").val($(this).attr("vq")).attr("name","vq");
		form_tmp.css("display","none").append(tmp_hid1).append(tmp_hid2);
		$("body").append(form_tmp);
		$("#frm_tmp").submit();
		return false;
	});
//	$("#loading_results").hide();
//	$("#results_wrap").fadeIn();
//	tmpInterval = window.setInterval("$(\"iframe, #foot\").css(\"position\",\"relative\")",500);
//	window.setTimeout("window.clearInterval(tmpInterval)", 5000);
});
function removeSpecials(/*string*/ s){
	while(s.match(/[á|é|í|ó|ú|à|è|ì|ò|ù|ã|ĩ|õ|ũ|ä|ë|ï|ö|ü|â|ê|î|ô|û|ç|ý|ÿ]/)) {
		s = s.replace(" ","-").replace(/[á|à|ã|ä|â]/,"a").replace(/[é|è|ë|ê]/,"e")
			 .replace(/[í|ì|ĩ|ï|î]/,"i").replace(/[ó|ò|õ|ö|ô]/,"o").replace(/[ú|ù|ũ|ü|û]/,"u")
			 .replace(/[ç]/,"c").replace(/[ý|ÿ]/,"y").replace(/[\[|\]|\(|\)|\{|\}]/," ");
	}
	while (s.match(/[^a-zA-Z0-9\-]/i)) {s = s.replace(/[^a-zA-Z0-9\-]/i,"");}
	return s;
}
function submitBusca(){
	var q = $("#q_suggest").val().toLowerCase();
	if(q != ""){
		while (q.search(" ") >= 0){ q = q.replace(" ", "-"); }
		while (q.search('/') >= 0){ q = q.replace('/', ''); }
		q = q.toLowerCase();
		q = removeSpecials(q);
		$("#form_busca").attr("action", "/busca/"+q);
		return true;
	}
	return false;
}

