
(function($){$.fn.wslide=function(h){h=jQuery.extend({width:150,height:150,pos:1,col:1,effect:'swing',fade:false,horiz:false,autolink:true,duration:1500},h);function gogogo(g){g.each(function(i){var a=$(this);var e=a.attr('id');if(e==undefined){e='wslide'+i}$(this).wrap('<div class="wslide-wrap" id="'+e+'-wrap"></div>');a=$('#'+e+'-wrap');var b=a.find('ul li');var f=h.effect;if(jQuery.easing.easeInQuad==undefined&&(f!='swing'||f!='normal')){f='swing'}var g=h.width;var j=h.height;function resultante(a){var b=a;b=b.split('px');b=b[0];return Number(b)}var k=g-(resultante(b.css('padding-left'))+resultante(b.css('padding-right')));var l=j-(resultante(b.css('padding-top'))+resultante(b.css('padding-bottom')));var m=h.col;if(h.horiz){m=Number(b.length+1)}var n='';var o=Math.ceil(Number(b.length)/m);a.css('overflow','hidden').css('position','relative').css('text-align','left').css('height',j+'px').css('width',g+'px').css('margin','0').css('padding','0');a.find('ul').css('position','absolute').css('margin','0').css('padding','0').css('width',Number((m+0)*g)+'px').css('height',Number(o*j)+'px');b.css('display','block').css('overflow','hidden').css('float','left').css('height',l+'px').css('width',k+'px');b.each(function(i){var b=a.offset();var c=$(this).offset();$(this).attr('id',e+'-'+Number(i+1)).attr('rel',Number(c.left-b.left)+':'+Number(c.top-b.top));n+=' <a href="#'+e+'-'+Number(i+1)+'">'+Number(i+1)+'</a>'});if(typeof h.autolink=='boolean'){if(h.autolink){a.after('<div class="wslide-menu" id="'+e+'-menu">'+n+'</div>')}}else if(typeof h.autolink=='string'){if($('#'+h.autolink).length){$('#'+h.autolink).html(n)}else{a.after('<div id="#'+h.autolink+'">'+n+'</div>')}}var p='#'+e+'-';var q="";$('a[href*="'+p+'"]').click(function(){$('a[href*="'+q+'"]').removeClass("wactive");$(this).addClass("wactive");var b=$(this).attr('href');b=b.split('#');b='#'+b[1];q=b;var c=$(b).attr('rel');c=c.split(':');var d=c[1];d=-d;c=c[0];c=-c;if(h.fade){a.find('ul').animate({opacity:0},h.duration/2,f,function(){$(this).css('top',d+'px').css('left',c+'px');$(this).animate({opacity:1},h.duration/2,f)})}else{a.find('ul').animate({top:d+'px',left:c+'px'},h.duration,f)};return false});if(h.pos<=0){h.pos=1}$('a[href$="'+p+h.pos+'"]').addClass("wactive");var r=$('a[href*="'+p+'"]:eq('+Number(h.pos-1)+')').attr('href');r=r.split('#');r='#'+r[1];q=r;var s=$(r).attr('rel');s=s.split(':');var t=s[1];t=-t;s=s[0];s=-s;a.find('ul').css('top',t+'px').css('left',s+'px');})}gogogo(this);return this}})(jQuery);

;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
var static_server = 'http://static.losacordes.com/'

function getTrack(artista, titulo) {
	if ( (artista + titulo).length > 37) {
		artista = artista.substr(0, 15)
		if ( (artista + titulo).length > 37) {
			titulo = titulo.substr(0, titulo.length - ( (artista + titulo).length - 37) )
		}
	}
	return artista + " - <span class=\"faixa\">" + titulo + "</span>"
}


;(function($) {

	$.fn.fixPNG = function() {
		return this.each(function () {
			var image = $(this).css('backgroundImage');

			if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
				image = RegExp.$1;
				$(this).css({
					'backgroundImage': 'none',
					'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=" + ($(this).css('backgroundRepeat') == 'no-repeat' ? 'crop' : 'scale') + ", src='" + image + "')"
				}).each(function () {
					var position = $(this).css('position');
					if (position != 'absolute' && position != 'relative')
						$(this).css('position', 'relative');
				});
			}
		});
	};

	var elem, opts, busy = false, imagePreloader = new Image, loadingTimer, loadingFrame = 1, imageRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i;
	var isIE = ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 8);

	$.fn.fancybox = function(settings) {
		settings = $.extend({}, $.fn.fancybox.defaults, settings);

		var matchedGroup = this;

		function _initialize() {
			elem = this;
			opts = settings;

			_start();

			return false;
		};

		function _start() {
			if (busy) return;

			if ($.isFunction(opts.callbackOnStart)) {
				opts.callbackOnStart();
			}

			opts.itemArray		= [];
			opts.itemCurrent	= 0;

			if (settings.itemArray.length > 0) {
				opts.itemArray = settings.itemArray;

			} else {
				var item = {};

				if (!elem.rel || elem.rel == '') {
					var item = {href: elem.href, title: elem.title};

					if ($(elem).children("img:first").length) {
						item.orig = $(elem).children("img:first");
					}

					opts.itemArray.push( item );

				} else {
					
					var subGroup = $(matchedGroup).filter("a[rel=" + elem.rel + "]");

					var item = {};

					for (var i = 0; i < subGroup.length; i++) {
						item = {href: subGroup[i].href, title: subGroup[i].title};

						if ($(subGroup[i]).children("img:first").length) {
							item.orig = $(subGroup[i]).children("img:first");
						}

						opts.itemArray.push( item );
					}

					while ( opts.itemArray[ opts.itemCurrent ].href != elem.href ) {
						opts.itemCurrent++;
					}
				}
			}

			if (opts.overlayShow) {
				if (isIE) {
					$('embed, object, select').css('visibility', 'hidden');
				}

				$("#fancy_overlay").css('opacity', opts.overlayOpacity).show();
					

			}

			_change_item();
		};

		function _change_item() {
			$("#fancy_right, #fancy_left, #fancy_close, #fancy_title").hide();

			var href = opts.itemArray[ opts.itemCurrent ].href;
			if(href==undefined || href == ''){href = opts.url}

			if (href.match(/#/)) {
				var target = window.location.href.split('#')[0]; target = href.replace(target, ''); target = target.substr(target.indexOf('#'));

				_set_content('<div id="fancy_div">' + $(target).html() + '</div>', opts.frameWidth, opts.frameHeight);

			} else if (href.match(imageRegExp)) {
				imagePreloader = new Image; imagePreloader.src = href;

				if (imagePreloader.complete) {
					_proceed_image();

				} else {
					$.fn.fancybox.showLoading();

					$(imagePreloader).unbind().bind('load', function() {
						$(".fancy_loading").hide();

						_proceed_image();
					});
				}

			 } else if (href.match("iframe") || elem.className.indexOf("iframe") >= 0) {
				_set_content('<iframe id="fancy_frame" onload="$.fn.fancybox.showIframe()" name="fancy_iframe' + Math.round(Math.random()*1000) + '" frameborder="0" hspace="0" src="' + href + '"></iframe>', opts.frameWidth, opts.frameHeight);

			} else {
				$.get(href, function(data) {
					_set_content( '<div id="fancy_ajax">' + data + '</div>', opts.frameWidth, opts.frameHeight );
				});
			}
		};

		function _proceed_image() {
			if (opts.imageScale) {
				var w = $.fn.fancybox.getViewport();

				var r = Math.min(Math.min(w[0] - 36, imagePreloader.width) / imagePreloader.width, Math.min(w[1] - 60, imagePreloader.height) / imagePreloader.height);

				var width = Math.round(r * imagePreloader.width);
				var height = Math.round(r * imagePreloader.height);

			} else {
				var width = imagePreloader.width;
				var height = imagePreloader.height;
			}

			_set_content('<img alt="" id="fancy_img" src="' + imagePreloader.src + '" />', width, height);
		};

		function _preload_neighbor_images() {
			if ((opts.itemArray.length -1) > opts.itemCurrent) {
				var href = opts.itemArray[opts.itemCurrent + 1].href;

				if (href.match(imageRegExp)) {
					objNext = new Image();
					objNext.src = href;
				}
			}

			if (opts.itemCurrent > 0) {
				var href = opts.itemArray[opts.itemCurrent -1].href;

				if (href.match(imageRegExp)) {
					objNext = new Image();
					objNext.src = href;
				}
			}
		};

		function _set_content(value, width, height) {
			busy = true;

			var pad = opts.padding;

			if (isIE) {
				$("#fancy_content")[0].style.removeExpression("height");
				$("#fancy_content")[0].style.removeExpression("width");
			}

			if (pad > 0) {
				width	+= pad * 2;
				height	+= pad * 2;

				$("#fancy_content").css({
					'top'		: pad + 'px',
					'right'		: pad + 'px',
					'bottom'	: pad + 'px',
					'left'		: pad + 'px',
					'width'		: 'auto',
					'height'	: 'auto'
				});

				if (isIE) {
					$("#fancy_content")[0].style.setExpression('height',	'(this.parentNode.clientHeight - 20)');
					$("#fancy_content")[0].style.setExpression('width',		'(this.parentNode.clientWidth - 20)');
				}

			} else {
				$("#fancy_content").css({
					'top'		: 0,
					'right'		: 0,
					'bottom'	: 0,
					'left'		: 0,
					'width'		: '100%',
					'height'	: '100%'
				});
			}

			if ($("#fancy_outer").is(":visible") && width == $("#fancy_outer").width() && height == $("#fancy_outer").height()) {
				$("#fancy_content").fadeOut("fast", function() {
					$("#fancy_content").empty().append($(value)).fadeIn("normal", function() {
						_finish();
					});
				});

				return;
			}

			var w = $.fn.fancybox.getViewport();

			var itemLeft	= (width + 36)	> w[0] ? w[2] : (w[2] + Math.round((w[0] - width - 36) / 2));
			var itemTop		= (height + 50)	> w[1] ? w[3] : (w[3] + Math.round((w[1] - height - 50) / 2));

			var itemOpts = {
				'left':		itemLeft,
				'top':		itemTop,
				'width':	width + 'px',
				'height':	height + 'px'
			};

			if ($("#fancy_outer").is(":visible")) {
				$("#fancy_content").fadeOut("normal", function() {
					$("#fancy_content").empty();
					$("#fancy_outer").animate(itemOpts, opts.zoomSpeedChange, opts.easingChange, function() {
						$("#fancy_content").append($(value)).fadeIn("normal", function() {
							_finish();
						});
					});
				});

			} else {

				if (opts.zoomSpeedIn > 0 && opts.itemArray[opts.itemCurrent].orig !== undefined) {
					$("#fancy_content").empty().append($(value));

					var orig_item	= opts.itemArray[opts.itemCurrent].orig;
					var orig_pos	= $.fn.fancybox.getPosition(orig_item);

					$("#fancy_outer").css({
						'left':		(orig_pos.left - 18) + 'px',
						'top':		(orig_pos.top  - 18) + 'px',
						'width':	$(orig_item).width(),
						'height':	$(orig_item).height()
					});

					if (opts.zoomOpacity) {
						itemOpts.opacity = 'show';
					}

					$("#fancy_outer").animate(itemOpts, opts.zoomSpeedIn, opts.easingIn, function() {
						_finish();
					});

				} else {

					$("#fancy_content").hide().empty().append($(value)).show();
					$("#fancy_outer").css(itemOpts).fadeIn("normal", function() {
						_finish();
					});
				}
			}
		};

		function _set_navigation() {
			if (opts.itemCurrent != 0) {
				$("#fancy_left, #fancy_left_ico").unbind().bind("click", function(e) {
					e.stopPropagation();

					opts.itemCurrent--;
					_change_item();

					return false;
				});

				$("#fancy_left").show();
			}

			if (opts.itemCurrent != ( opts.itemArray.length -1)) {
				$("#fancy_right, #fancy_right_ico").unbind().bind("click", function(e) {
					e.stopPropagation();

					opts.itemCurrent++;
					_change_item();

					return false;
				});

				$("#fancy_right").show();
			}
		};

		function _finish() {
			_set_navigation();

			_preload_neighbor_images();

			$(document).keydown(function(e) {
				if (e.keyCode == 27) {
					$.fn.fancybox.close();
					$(document).unbind("keydown");

				} else if(e.keyCode == 37 && opts.itemCurrent != 0) {
					opts.itemCurrent--;
					_change_item();
					$(document).unbind("keydown");

				} else if(e.keyCode == 39 && opts.itemCurrent != (opts.itemArray.length - 1)) {
 					opts.itemCurrent++;
					_change_item();
					$(document).unbind("keydown");
				}
			});

			if (opts.centerOnScroll) {
				$(window).bind("resize scroll", $.fn.fancybox.scrollBox);
			} else {
				$("div#fancy_outer").css("position", "absolute");
			}

			if (opts.hideOnContentClick) {
				$("#fancy_wrap").click($.fn.fancybox.close);
			}

			$("#fancy_overlay, #fancy_close").bind("click", $.fn.fancybox.close);

			$("#fancy_close").show();

			if (opts.itemArray[ opts.itemCurrent ].title !== undefined && opts.itemArray[ opts.itemCurrent ].title.length > 0) {
				$('#fancy_title div').html(opts.itemArray[ opts.itemCurrent ].title);
				$('#fancy_title').show();
			}

			if (opts.overlayShow && isIE) {
				$('embed, object, select', $('#fancy_content')).css('visibility', 'visible');
			}

			if ($.isFunction(opts.callbackOnShow)) {
				opts.callbackOnShow();
			}

			busy = false;
		};

		return this.unbind('click').click(_initialize);
	};

	$.fn.fancybox.scrollBox = function() {
		var pos = $.fn.fancybox.getViewport();

		$("#fancy_outer").css('left', (($("#fancy_outer").width()	+ 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - $("#fancy_outer").width()	- 36)	/ 2)));
		$("#fancy_outer").css('top',  (($("#fancy_outer").height()	+ 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - $("#fancy_outer").height()	- 50)	/ 2)));
	};

	$.fn.fancybox.getNumeric = function(el, prop) {
		return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
	};

	$.fn.fancybox.getPosition = function(el) {
		var pos = el.offset();

		pos.top	+= $.fn.fancybox.getNumeric(el, 'paddingTop');
		pos.top	+= $.fn.fancybox.getNumeric(el, 'borderTopWidth');

		pos.left += $.fn.fancybox.getNumeric(el, 'paddingLeft');
		pos.left += $.fn.fancybox.getNumeric(el, 'borderLeftWidth');

		return pos;
	};

	$.fn.fancybox.showIframe = function() {
		$(".fancy_loading").hide();
		$("#fancy_frame").show();
	};

	$.fn.fancybox.getViewport = function() {
		return [$(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
	};

	$.fn.fancybox.animateLoading = function() {
		if (!$("#fancy_loading").is(':visible')){
			clearInterval(loadingTimer);
			return;
		}

		$("#fancy_loading > div").css('top', (loadingFrame * -40) + 'px');

		loadingFrame = (loadingFrame + 1) % 12;
	};

	$.fn.fancybox.showLoading = function() {
		clearInterval(loadingTimer);

		var pos = $.fn.fancybox.getViewport();

		$("#fancy_loading").css({'left': ((pos[0] - 40) / 2 + pos[2]), 'top': ((pos[1] - 40) / 2 + pos[3])}).show();
		$("#fancy_loading").bind('click', $.fn.fancybox.close);

		loadingTimer = setInterval($.fn.fancybox.animateLoading, 66);
	};




	$.fn.fancybox.close = function() {
		busy = true;

		//$(imagePreloader).unbind();
		
		$("#fancy_overlay, #fancy_close").unbind();
		

		if (opts.hideOnContentClick) {
			$("#fancy_wrap").unbind();
			

		}

		$("#fancy_close, .fancy_loading, #fancy_left, #fancy_right, #fancy_title").hide();
		

		if (opts.centerOnScroll) {
			//$(window).unbind("resize scroll");
			

		}

		__cleanup = function() {
			
			$("#fancy_overlay, #fancy_outer").hide();

			if (opts.centerOnScroll) {
				//$(window).unbind("resize scroll");
				
			}

			if (isIE) {
				$('embed, object, select').css('visibility', 'visible');
				
			}

			if ($.isFunction(opts.callbackOnClose)) {
				opts.callbackOnClose();
				
			}

			busy = false;
		};

		if ($("#fancy_outer").is(":visible") !== false) {
			if (opts.zoomSpeedOut > 0 && opts.itemArray[opts.itemCurrent].orig !== undefined) {
				

				var orig_item	= opts.itemArray[opts.itemCurrent].orig;
				var orig_pos	= $.fn.fancybox.getPosition(orig_item);

				var itemOpts = {
					'left':		(orig_pos.left - 18) + 'px',
					'top': 		(orig_pos.top  - 18) + 'px',
					'width':	$(orig_item).width(),
					'height':	$(orig_item).height()
				};

				if (opts.zoomOpacity) {
					
					itemOpts.opacity = 'hide';
				}

				$("#fancy_outer").stop(false, true).animate(itemOpts, opts.zoomSpeedOut, opts.easingOut, __cleanup);
				


			} else {
				$("#fancy_outer").stop(false, true).fadeOut("fast", __cleanup);
				

			}

		} else {
			__cleanup();
			

		}
		return false;
		
	};


	$.fn.fancybox.build = function() {
		var html = '';

		html += '<div id="fancy_overlay"></div>';

		html += '<div id="fancy_wrap">';

		html += '<div class="fancy_loading" id="fancy_loading"><div></div></div>';

		html += '<div id="fancy_outer">';

		html += '<div id="fancy_inner">';

		html += '<div id="fancy_close"></div>';

		html +=  '<div id="fancy_bg"><div class="fancy_bg fancy_bg_n"></div><div class="fancy_bg fancy_bg_ne"></div><div class="fancy_bg fancy_bg_e"></div><div class="fancy_bg fancy_bg_se"></div><div class="fancy_bg fancy_bg_s"></div><div class="fancy_bg fancy_bg_sw"></div><div class="fancy_bg fancy_bg_w"></div><div class="fancy_bg fancy_bg_nw"></div></div>';

		html +=  '<a href="javascript:;" id="fancy_left"><span class="fancy_ico" id="fancy_left_ico"></span></a><a href="javascript:;" id="fancy_right"><span class="fancy_ico" id="fancy_right_ico"></span></a>';

		html += '<div id="fancy_content"></div>';

		html +=  '<div id="fancy_title"></div>';

		html += '</div>';

		html += '</div>';

		html += '</div>';

		$(html).appendTo("body");

		$('<table cellspacing="0" cellpadding="0" border="0"><tr><td class="fancy_title" id="fancy_title_left"></td><td class="fancy_title" id="fancy_title_main"><div></div></td><td class="fancy_title" id="fancy_title_right"></td></tr></table>').appendTo('#fancy_title');
		if (isIE) {
			$("#fancy_inner").prepend('<iframe class="fancy_bigIframe" scrolling="no" frameborder="0"></iframe>');
			$("#fancy_close, .fancy_bg, .fancy_title, .fancy_ico").fixPNG();
		}
	};

	$.fn.fancybox.defaults = {
		padding				:	10,
		imageScale			:	true,
		zoomOpacity			:	false,
		zoomSpeedIn			:	0,
		zoomSpeedOut		:	0,
		zoomSpeedChange		:	300,
		easingIn			:	'swing',
		easingOut			:	'swing',
		easingChange		:	'swing',
		frameWidth			:	425,
		frameHeight			:	355,
		overlayShow			:	true,
		overlayOpacity		:	0.3,
		hideOnContentClick	:	true,
		centerOnScroll		:	true,
		itemArray			:	[],
		callbackOnStart		:	null,
		callbackOnShow		:	null,
		callbackOnClose		:	null,
		url					:	null
	};

	$(document).ready(function() {
		$.fn.fancybox.build();
	});

})(jQuery);







function fillTypes()
{
	tps = 'v,a,k,e,t,b,d,h,f,i'.split(',');txs = 'video lección,acordes,piano,acordes simplificados,tablaturas,bajo,batería,armónicas,flauta,cavaco'.split(',');mls = '12,12,32,63,110,138,164,197,177,205'.split(',')
	for (n = 0; n < 10; n ++)
		eval ("$('.t" + tps[n] + "').mouseover(function(){$(this).siblings('div').html('" + txs[n] + "').css({'margin-left':" + mls[n] + ",'clear':'left'})}).mouseout(function(){$(this).siblings('div').html('')})")


		
}
function min(x,y) {
	return (x < y? x : y)
	}
function removeLatest(n)
{
	$.get('ajax.asp', 'acao=remove_latest&p=' + n, function(r){
	buildLatest()
	})
}
function getIco(tipo)
{
	var getIco
	tipo = tipo.split('/')[0]
	switch (tipo)
	{
		case 'chords':
			getIco = "peqcifra"
			break
		case "tabs":
			getIco = "peqtab"
			break
		case "bass":
			getIco = "peqbaixo"
			break
		case "drums":
			getIco = "peqbateria"
			break
		case "harmonics":
			getIco = "peqgaita"
			break
		case "flute":
			getIco = "peqflauta"
			break
		case "cavaco":
			getIco = "peqcavaco"
			break
		case "videos":
			getIco = "video"
			break
	}
	return getIco
}
function buildLatest()
{
	var lts = GetCookie('eclatest')
	html = ''
	if (lts != null)
	{
		arrLatest = lts.split('*@*')
		for (var n = 0; n < arrLatest.length; n ++)
		{
			if (arrLatest[n] > ' ')
			{
				arrLatestSong = arrLatest[n].replaceAll('+', ' ').split('|@|')
				html += '<span style="float: right; margin-right: 4px;"><a href="javascript:removeLatest('+ n +')"><img src="images/icons/trash.png" width="16" height="16" alt="remover"></a></span>'
				html += '<a href="' + arrLatestSong[0] + '/' + arrLatestSong[3] + '"><img src="' + static_server + 'images/icons/' + getImg(arrLatestSong[0]) + '.png"width="19"height="19" />'
				html += getTrack(arrLatestSong[1], arrLatestSong[2]) + '</a>'
			}
		}
	}
	else
	{
		html = 'Usted no ha accedido a cualquier tablatura.'
	}
	$("#tablvcontainer1").html(html)


}
jQuery.fn.floatButtons = function(opts) {

	sizeLess = opts.sizeless
	sizePlus = opts.sizeplus
	left = opts.left
	distance = opts.distance



	return this.each(function(){
	


	//		$(this).children().attr('rel', $(this).children().width() + ',' + $(this).children().height())
//	$(this).attr('rel').split(',')[1]
	x1 = $(this).children().width()
	y1 = $(this).children().height()
	t1 = parseInt(((y1 * (100 + sizePlus)/100 - y1 * (100 - sizeLess)/100)) /2 * -1)
	l1 = parseInt(((x1 * (100 + sizePlus)/100 - x1 * (100 - sizeLess)/100)) /2 * -1)
	
	$(this).children().removeAttr('width').removeAttr('height').css({width:  (x1 * (100 - sizeLess)/100), height: (y1 * (100 - sizeLess)/100)  })
	
			element = $(this);
		
			$(this)		
			.after("<span></span>").next()
			.css({'position':'absolute', 'left': left})
			.html('<a href="' + element.attr('href') + '">' + element.html() + "</a>")
			
			.children().children()
.css({opacity: .8})
	.mouseout(function(){
		$(this).animate({
		height: parseInt(y1 * (100 - sizeLess)/100),
		width: parseInt(x1 * (100 - sizeLess)/100),
		marginTop: 0,
		//marginLeft: 0,
		opacity: .8
		}, 'fast')

    }).mouseover(function(){
		$(this).stop().animate({
		height: parseInt(y1 * (100 + sizePlus)/100),
		width: parseInt(x1 * (100 + sizePlus)/100),
		marginTop: t1,
		//marginLeft: l1,
		opacity: 1
		}, 'fast')
    })			
			
			.parent().parent().prev().remove()

;
			left += distance



	})
	}


function closeModal()
{
	//parent.$.fn.fancybox.close()
	$("#fancy_overlay, #fancy_close").unbind();
	$("#fancy_wrap").unbind();
	$("#fancy_close, .fancy_loading, #fancy_left, #fancy_right, #fancy_title").hide();
	$(window).unbind("resize scroll");
	$("#fancy_overlay, #fancy_outer").hide();
	$('div[id^=fancy]').remove()
	setTimeout('$.fn.fancybox.build()', 1000)

}
function closeCombo(index)
{
	$('.abc li >div:eq(' + index + ')').css({height:0,display:'none'})
}
function hideJHint()
{
	$('div [rel=JHint]').hide()
	//obj.style.display = 'none'
}
var isP, idM
var startClose,lastCmbOpened = -1;
var animation = false;
var timeJHint;
var interval;
var cursorY;
var cursorX;
var timeStartBaloon;
var baloonMO = false;
function startBaloon(cod, x, y, w)
{
	
	clearInterval(interval)
	interval = setTimeout('openBaloon(' + cod + ', ' + x + ', ' + y + ', ' + w + ')',300)
	
}
function closeBaloon(cod)
{
	$('.baloon').fadeOut(); //css(display, 'none')

}
function openBaloon(cod, x, y, w)
{
	if (!baloonMO) return
	addX =  $('.interior').position().left  
	scrollY = document.documentElement.scrollTop
	//if (scrollY
	posY = (cursorY - scrollY)


	//$.get("ajax.asp?acao=get_baloon&p=" + cod, "", 
	
	
	
	
			$.ajax({
		type: "GET",
		url: "http://servidor/losacordes/arquivos/baloon/_" + cod + ".txt",
		dataType: "text",
		cache:true,
		success: 
		function(r) {
			
			
			if (posY > $(window).height()/2)
				{	
				
					$('.baloon').fadeIn().css({
						top: y + 200 ,
						left:x + 170 + addX + w
					
					})
					$('.baloon>img:last').css('display', 'block')
					$('.baloon>img:first').css('display', 'none')
				}
				else
				{
					$('.baloon').fadeIn().css({
						top: y + 440 ,
						left:x + 170 + addX + w
					
					})
					$('.baloon>img:first').css('display', 'block')
					$('.baloon>img:last').css('display', 'none')
			
				
				}			
			
			
			//$('.baloon').attr('rel', cod)
			$('.inner_baloon').html(r)
			
			}
			
			
			}
		);
	
	
	

}

function fancyResize(x, y)
{
$("#fancy_outer").animate({'width': x, 'height': y});
}
function getImg(path)
{
	path = path.split("/")
	switch (path[0])
	{
		case 'acordes':
			return 'peqcifra';break;
		case 'piano':
			return 'peqteclado';break;
		case 'tablaturas':
			return 'peqtab';break;
		case 'tablaturas-bajo':
			return 'peqbaixo';break;
		case 'tablaturas-bateria':
			return 'peqbateria';break;
		case 'flauta':
			return 'peqflauta';break;
	} 
	
}
function setPremium(status) {
	isP = status
}

var cacheSB = new Array();
var lastSb = 0;
function showSongbook(id)
{
	if (cacheSB['songbook' + id] == undefined){
		$('#songbook'+id).html('<img src="' + static_server + 'images/wait.gif" />')
		$.get('ajax2.asp', 'acao=build_songbook&p=' + id, function(r){
			$('#songbook'+id).html(r).show(100)
			$('#songbook'+lastSb).hide(100)
			lastSb = id
			cacheSB['songbook' + id] = r
		})
	}
	else
	{
		if (id != lastSb) {
		$('#songbook'+id).html(cacheSB['songbook' + id])
			$('#songbook'+lastSb).hide(100)
			$('#songbook'+id).show(100)
			lastSb = id
		}
	}
	
}
function buildSongbooks(str, login)
{
	var html = '';
	if (str > '')
	{
	str = str.split('|~|')
	for (var n = 0; n < str.length; n ++)
	{
		if (str[n] > ''){
			strItems = str[n].split('|@|')
			html += '<div class="lista" id="songbook_' + strItems[0] + '">' +
			'<img src="' + static_server + 'images/songbook' + (strItems[1].substr(0,1) == "S" ? "2" : "") + '.png" width="32" height="32" class="icon" align="left" /> ' +
		  '<a href="javascript:showSongbook(' + strItems[0] + ')" style="text-decoration: none;">' + strItems[2] + '</a>' +
		  '<b>' + strItems[4] + '</span> canciones - ' + (strItems[1].substr(1,1) == "S" ? "público" : "privado") + 
		  (strItems[1].substr(0,1) == "S" ? " - compart." : "") + '</b> <div id="songbook' + strItems[0] + '"></div></div>'
	  	}
	}
	}
	else
	{
		html = "Debe estar registrado para acceder a sus songbooks"
	}
	$("#tablvcontainer2").css('overflow','auto').html(html)
}

function doLogin()
{
$.get('ajax2.asp', 'acao=do_area_login', function(r){
	isP = r.isP
	if (r.logged == 'true')
	{
		isLoggedIn = true
		if (r.avatar == '') {
			meuavatar='images/profile_nophoto.gif'
		} else {
			meuavatar='http://www.cifras.com.br/arquivos/fotos_usuarios/' + r.avatar
		}
		html = '<div class="logado" align="center"><a href="profile/' +  r.login + '"><img src="' + meuavatar + '" width="80" height="80" /></a>¡Hola, <a href="profile/' +  r.login + '">' +  r.login + '</a>!' + 
        '<a href="edit-profile.htm"><img src="images/bt_edit.png" alt="editar mi perfil" width="86" height="30" /></a> <a href="login.htm?cod=logout"><img src="images/bt_logout.png" alt="salir" width="86" height="30" /></a></div>'
		if (r.isP == 'N')
		$('#areasignup').html('upgrade: <a href="upgrade-premium.htm" class="btn"><img src="images/bt_premium.png" alt="Premium" width="94" height="25" /></a>')
		else
		{
			$("#menufree").clone().removeAttr('id').attr('id', 'mfree').insertAfter("#menupremium")
			$("#menufree").remove()
			$('a[href=upgrade-premium.htm]').remove()		
		}
	}
	else
	{
		html = '<form action="login.htm" method="post"><div class="login"> apodo: <input name="_login" type="text" class="form" size="15" />' +
		'<a href="login.htm?f=true"><span style="font-size:11px; text-decoration: none!important; font-style: normal; float: right">¿olvidó?</span></a>contraseña: <input name="_senha" type="password" class="form" size="15" />' +
		'<div align="center" style="margin-top: 25px;"> <input type="image" src="images/bt_enter.png" width="85" height="30" alt="entrar" /> ' +
		'<p style="margin-top: 25px; margin-bottom: 2px;">¿sin cuenta?</p><p><a href="signup-free.htm" style="font-size: 16px; font-style: normal;"><b>¡regístrate ahora!</b></a></p></div></div></form>'
		$('#areasignup').html('regístrate: <a href="signup-free.htm" style="margin-left: 7px; margin-right: 5px;" class="btn"><img src="images/bt_free.png" alt="Grátis" width="46" height="25" /></a><a href="signup-free.htm?premium" class="btn"><img src="images/bt_premium.png" alt="Premium" width="94" height="25" /></a>')
		

	}
	$('#arealogin').html(html)
}, "json")

}
$(document).ready(initGlobal);

function initGlobal(){



	$("#cmbresults").wslide({width:400,height:330,horiz:true,autolink:'cmbresults_nav',duration:300})
	$('.combao').css({'display':'none', 'visibility':'visible'})
	//$('.nav_opt li[rel]>a:first-child').css({'padding-bottom':7, 'padding-top':7})
	$('#cmbresults li table td p a[rel]').doBaloon(-130, -260, 0, true) 
	
	$('.alpha').mouseover(
		function ()
		{
			$(this).animate({'opacity':1}, 'fast')
		
		}
	
	).mouseout(
		function ()
		{
			$(this).animate({'opacity':0.8}, 'fast')
		
		}
	).css({'opacity':0.8, 'cursor':'pointer'})


doLogin()


$("<div></div>").addClass("baloon").css({'z-index':1000, 'display': 'none', 'position':'absolute'}).appendTo("body")
$('.baloon').html('<div class="inner_baloon"></div><img style="display:none" src="images/st_balloon_down.png" alt="more details" width="98" height="20" id="st_down" /><img style="display:none" src="images/st_balloon_up.png" alt="more details" width="98" height="20" id="st_up" />')


	$('.baloon').mouseenter(
		function(){
			clearInterval(timeStartBaloon)
		}
	).mouseleave(
		function(){
			closeBaloon(); //$(this).attr('rel'))
		}
	)
	

  $().mousemove(function(e){
      cursorY = e.pageY 
      cursorX = e.pageX 
   });



	/************************
	 CONSTRUIR ABA
	*************************/
var aba2 = 0;
function buildAba(y, n, imgAba, color, html, top)
{
	$("<div></div>").attr("id", "tablv" + n).addClass('tablv').bind('mouseleave', function(){$("#tablvimg" + n).css('opacity',0.7);$('#tablv' + n).animate({left: -282}, 'fast',function(){
		$(this).css('z-index',100 + n)
		if (top == false && n == 3)
		{
			$('#tablv3').css({top: 464})
			$('#tablvimg3').css({'position':'relative','top':0})
		}

	}) }).css({left:-282, top: y, 'z-index':100 + n}).appendTo("body")

	if (top == false)
	{
		$('#tablv' + n).append("<img src='" + static_server + "images/tab_lv_down_red.gif'width='282'height='7'><br clear='all'>")
		$("<div></div>").css({'float':'left', width: 270, height: 280, 'border-bottom': 'solid 2px #' + color,'border-right': 'solid 2px #' + color, 'font-size':'8pt'}).attr("id", "tablvcontainer" + n).addClass('tablvcontainer').appendTo("#tablv" + n)
	}
	else
		$("<div></div>").css({'float':'left', width: 270, height: 280, 'border-top': 'solid 2px #' + color,'border-right': 'solid 2px #' + color, 'font-size':'8pt'}).attr("id", "tablvcontainer" + n).addClass('tablvcontainer').appendTo("#tablv" + n)


	$("<div></div>").css({'float':'right', opacity:0.7}).attr("id", "tablvimg" + n).appendTo("#tablv" + n)
	/*if (top == false)
	{
		$('#tablvimg' + n).css({'position':'relative','top':170})
	}*/
	
		
	$("#tablvimg" + n).html("<img src='" + static_server + imgAba + "'width='21'height='110'>").click(
		function(){
			$(this).css({opacity:1})
			if (n==2 && aba2 == 0)
			{
				$("#tablvcontainer2").html('espere, cargando songbooks...<br><br><img src="' + static_server + 'images/wait2.gif" />')
				$.get('ajax2.asp', 'acao=build_songbooks', function(r){
					buildSongbooks(r.sb, r.login)
					aba2 = 1
				}, 'json')
			}
		
		
			if($('#tablv' + n).position().left < 0)
			{
				if (top == false && n == 3)
				{
					$('#tablv3').css({top: 281})
					$('#tablvimg3').css({'position':'relative','top':182})
				}

				$('#tablv' + n).animate({left: 0}, 'fast').css('z-index',3000)
			}
			else
			{
				$('#tablv' + n).animate({left: -282}, 'fast').css('z-index',100 + n)
				$(this).css({opacity:0.7})
			}
		}
	).css('cursor','pointer')
	if (top) $('#tablvimg' + n).after("<br clear=all><img src='" + static_server + "images/tab_lv_down.gif'width='282'height='7'><br clear=all>")
	$("#tablvcontainer" + n).css({'padding':5}).html(html).addClass('chord_extra')
}

	buildAba(229, 1, 'images/tab_lv1.png', '96AEBE', '', true)
	buildLatest()

	buildAba(349, 2, 'images/tab_lv2.png', '96AEBE', '', true)
	
	html = '<div class="addthis_toolbox"><div class="two_column"><div class="column1"><a class="addthis_button_email">Email</a></div><div class="column2"><a class="addthis_button_favorites">Favoritos</a></div><div class="clear"></div><div class="top"></div>' +
        '<div class="column1"><a class="addthis_button_twitter">Twitter</a><a class="addthis_button_facebook">Facebook</a><a class="addthis_button_live">Live</a><a class="addthis_button_delicious">Delicious</a><a class="addthis_button_myspace">MySpace</a><a class="addthis_button_friendster">Friendster</a></div>' +
        '<div class="column2"><a class="addthis_button_orkut">Orkut</a><a class="addthis_button_stumbleupon">Stumble</a><a class="addthis_button_digg">Digg</a><a class="addthis_button_google">Google</a><a class="addthis_button_reddit">Reddit</a><a class="addthis_button_linkedin">LinkedIn</a></div>' +
        '<div class="clear"></div><div class="addthis_more"><a class="addthis_button_expanded">Mais Opções</a></div></div></div>'
		
	buildAba(464, 3, 'images/tab_lv3.png', 'a82927', html, false)
	doLogin()

	var e;	// Elemento

	
	/************************
	 EFEITO BOTOES
	*************************/
	$(".btn").mouseover(function(){$(this).animate({opacity:0.6}, 100);}).mouseout(function(){$(this).animate({opacity:1.0}, 100);});
	
	$(".bt_play, .bt_play_big").mouseover(function(){$(this).animate({opacity:1.0}, 100);}).mouseout(function(){$(this).animate({opacity:0.6}, 100);});
	
	/************************
	 COMBAO
	*************************/
	$(".nav_opt li").mouseenter(function(){
		$("#" + $(this).attr("rel")).show()
	});
	$(".nav_opt li").mouseleave(function(){
		$("#" + $(this).attr("rel")).hide()
	});	
	

	
	/************************
	 SEARCH
	*************************/
	$("#cmbSearchDiv, #cmbSearchInDiv").mouseleave(
							function() {
			var i;
			i = $("#" + this.id.replace('Div','') + " img").attr("src");
			if(i.indexOf("st.png") > 0){
				$("#" + this.id.replace('Div','') + " img").attr("src", "images/st3.png");
				$("#" + this.id.replace('Div','') + " img").attr("alt", "Menos");
			}
			else{
				$("#" + this.id.replace('Div','') + " img").attr("src", "images/st.png");
				$("#" + this.id.replace('Div','') + " img").attr("alt", "Más");
			}
								$(this).slideUp(200);
								}	  											   
	)
	$("#cmbSearch, #cmbSearchIn").click(
		function(){
			var i;
			i = $("#" + this.id + " img").attr("src");
			if(i.indexOf("st.png") > 0){
				$("#" + this.id + " img").attr("src", "images/st3.png");
				$("#" + this.id + " img").attr("alt", "Menos");
			}
			else{
				$("#" + this.id + " img").attr("src", "images/st.png");
				$("#" + this.id + " img").attr("alt", "Más");
			}
			$("#" + this.id + "Div").slideToggle(200);
		}
	)
	$(".menu a").click(
		function(){
			$("#" + this.rel + "Opt").text(this.title);
			/*if(this.rel=="cmbSearch") $("#search_type").attr("value", this.text);
			if(this.rel=="cmbSearchIn") $("#search_in").attr("value", this.text);*/
			$("#" + this.rel).click();
		}
	)
	$('img[alt=Buscar]').click(
		function()
		{

			if ($(this).attr('rel') == 'adv_search')
			{
			if ($("#adv_search").val() == '¿Qué estás buscando?' || $("#adv_search").val() == '') return false
			url = 'search-' + $("input[name='range']:checked").val() + '/' + escape($("#adv_search").val())
			if ($("#ch_inst span").text() != 'instrument')
			{
				url += '/show-' + $("#ch_inst span").text()
				hasInst = true
			}
			else
			hasInst = false
			if ($("#ch_lev span").text() != 'level')
				url += (hasInst ? '_' : '/') + 'plus-' + $("#ch_lev span").text()        
			}
			else
			{
			var buscaem;
			var buscamostrar;
			switch ($("#cmbSearchOpt").text()) {
				case "todo":
				buscaem="todo"
				break;
				case "artistas":
				buscaem="artistas"
				break;
				case "álbumes":
				buscaem="albumes"
				break;
				case "compositores":
				buscaem="compositores"
				break;
				case "títulos":
				buscaem="songs"
				break;
				case "parte":
				buscaem="parte"
				break;
				default:
				buscaem="todo"
			}
			switch ($("#cmbSearchInOpt").text()) {
				case "todo":
				buscamostrar="todo"
				break;
				case "acordes":
				buscamostrar="acordes"
				break;
				case "tablaturas":
				buscamostrar="tablaturas"
				break;
				case "bajo":
				buscamostrar="tablaturas-bajo"
				break;
				case "bateria":
				buscamostrar="tablaturas-bateria"
				break;
				case "armónica":
				buscamostrar="armonics"
				break;
				case "flauta":
				buscamostrar="flauta"
				break;
				default:
				//buscamostrar=$("#cmbSearchOpt").text()
				alert($("#cmbSearchInOpt").text());
			}
			if ($("#search").val() == '¿Qué estás buscando?' || $("#search").val() == '') return false
			
			url = 'busqueda-' + buscaem + '/' + escape($("#search").val())
			url += (buscamostrar != 'todo' ? '/show-' + buscamostrar : '')
			}
			window.location.href = url
		}	
	).css('cursor','pointer')
	
	/************************
	 LETRAS
	*************************/
	$(".abc li").mouseover(function(){
		//$('.abc li >div:eq(' + $('.abc li').index(this) + ')').stop().animate({height:'50px'},{queue:false, duration:200})
		//clearInterval(startClose)
		closeCombo(lastCmbOpened)
		lastCmbOpened = $('.abc li').index(this)
		
		$('.abc li >div:eq(' + lastCmbOpened + ')').css({height:50,display:'block'})
	});
	$(".abc li").mouseout(function(){
		//$('.abc li >div:eq(' + $('.abc li').index(this) + ')').stop().animate({height:'0px'},{queue:false, duration:50})
		clearInterval(startClose)
		startClose = setTimeout('closeCombo(' + $('.abc li').index(this)  + ')', 2000)
		
	});
	
}
// ************************************************
// AUTOCOMPLETE ***********************************
// ************************************************
$(document).ready(function(){

	
	$('#search')
	.keydown(
		function(event)
		{
			autoCompleteKeyPressed = event.keyCode
			
			if (autoCompleteKeyPressed == 40) overAutoComplete('down', false)
			if (autoCompleteKeyPressed == 38) overAutoComplete('up', false)
			if (autoCompleteKeyPressed == 34) overAutoComplete('down', true)
			if (autoCompleteKeyPressed == 33) overAutoComplete('up', true)
			
			if (autoCompleteKeyPressed == 13)
			{
				if (itemAutoComplete > -1)
				window.location.href= '/' + (arrAutoComplete[itemAutoComplete + 1]).split(" | ")[0]
				else
				$('img[rel=search]').click()
				
			
			}
			
		}
	)
	.keyup(function (event) {
		

		if (searchAutoComplete != $('#search').val())
		{
			searchAutoComplete  = $('#search').val()
			if (searchAutoComplete == '')
			{
				$('#autocompletebox').css({'display': 'none'})
				$('#autocomplete').html('')
				arrAutoComplete = new Array()
				lastValidAutoCompleteArray = new Array;
			}
			else
			startAutoComplete()
		}
	})


	})
/*
jQuery.fn.floatButtons = function(startDistance, sizeWidth) {
	return this.each(function(){
			element = $(this);
			$(this)
			.after("<span></span>").next()
			.css({'position':'absolute', left: startDistance})
			.html('<a href="#">' + element.html() + "</a>")
			.prev().remove();
			startDistance += sizeWidth



	})
	}*/

jQuery.fn.doBaloon = function(l, t, parent, cursorx, cursory) {
	
		return this.each(function(){
		
	$(this).bind('mouseover',
	function(){
		baloonMO = true
		if (parent != undefined)
		{
			var strParent = ''
			for (var n = 1; n <= parent; n ++)
			{
				strParent += '.parent()'
			}
			parent2 = eval('$(this)' + strParent + '.position().top')
			//parent = eval('$(this).parent().parent().parent().position().top')
		}
		else
		{
			parent2 = $(this).position().top
		}
		var y = parent2 + t
		clearInterval(timeStartBaloon)
		if (cursorx) 
		{
			res = $(document).width()
			x = cursorX + l - $(this).width() - (res > 980 ? (res - 980) / 2 : 0)
		}
		else
			x = $(this).position().left + l

		startBaloon($(this).attr('rel'), x, y, $(this).width() )
	
	}
	).bind('mouseout',
	function(){
		baloonMO = false
		clearInterval(timeStartBaloon)
		//closeBaloon($(this).attr('rel'))
		timeStartBaloon = setTimeout('closeBaloon(' + $(this).attr('rel') + ')', 2000)
	
	}
	)
	
			})
	
	}
	
	
jQuery.fn.JHint = function(size, style, color) {
	//cont = 0
	return this.each(function(){
		
		elem = $(this).css({'width':'auto', 'white-space': 'nowrap'})
		if (elem.width() > size) 
		{
				
			
				str = elem.html()
				strOriginal = str
				while (elem.width() > size)
				{
					str = str.substr(0, str.length -1)
					elem.html(str)
				}
				elem.html('<div rel="JHint" style="margin-top:0px;position:absolute;background-color:#' + color + ';z-index:200;display:none">' + strOriginal + '</div>' + str + '...').attr('rel', strOriginal).mouseenter(
				function()
				{
					clearInterval(timeJHint)
					//$('#JHint').html('<a style="font-style:normal;text-decoration:none" href="' + $(this).attr('href') + '"><font style="' + style + '">' + $(this).attr('rel') + '</font></a>').css({top:$(this).position().top, left: $(this).position().left}).show()
					hideJHint()
					$(this).children().show()
					
					//$('#JHint').html('<a style="font-style:normal;text-decoration:none" href="' + $(this).attr('href') + '"><font style="' + style + '">' + $(this).attr('rel') + '</font></a>').css({top:100, left: 100}).show()
					timeJHint = setTimeout('hideJHint()', 2000)
				})
		
			

		}

		
	});
};	
	
	

function overAutoComplete(direction, isPage)
{
	if (direction == 'down')
	{


		$('#autocomplete a:eq(' + itemAutoComplete + ')').attr('class', 'autocompleteout') //.css({'color':'#000','background-color':'#FFF'})
		if (isPage)
			itemAutoComplete += 10;
		else
			itemAutoComplete ++;
		
		if (itemAutoComplete >= totalItemsAutoComplete-2) itemAutoComplete = totalItemsAutoComplete-2
		
		
		$('#autocomplete a:eq(' + itemAutoComplete + ')').attr('class', 'autocompleteover') //.css({'color':'#FFF','background-color':'#000099'})
		
		posItem = $('#autocomplete a:eq(' + itemAutoComplete + ')').position().top + $('#autocomplete').position().top
		if (posItem > 126)
		{	
			$('#autocompletebox').scrollTop($('#autocomplete a:eq(' + itemAutoComplete + ')').position().top - 126)
		}
		
		
	}
	else
	{
		//
		$('#autocomplete a:eq(' + itemAutoComplete + ')').attr('class', 'autocompleteout') //.css({'color':'#000','background-color':'#FFF'})
		if (isPage)
			itemAutoComplete -= 10;
		else
			itemAutoComplete --;
		if (itemAutoComplete <= 0) itemAutoComplete = 0;
		$('#autocomplete a:eq(' + itemAutoComplete + ')').attr('class', 'autocompleteover') //   .css({'color':'#FFF','background-color':'#000099'})
		
		posItem = $('#autocomplete a:eq(' + itemAutoComplete + ')').position().top + $('#autocomplete').position().top
		//if (itemAutoComplete > 8)
		if (posItem < 0)
		{	
		
			//$('#autocompletebox').css('top', $('#autocomplete').position().top + (posItem * -1) )
			$('#autocompletebox').scrollTop($('#autocomplete a:eq(' + itemAutoComplete + ')').position().top )
		}


		
	}
	



}
var arrAutoComplete = new Array();
var totalItemsAutoComplete;
var itemAutoComplete = -1;
var startTime;
var searchAutoComplete = '';
var autoCompleteKeyPressed;
var lastValidAutoCompleteArray = new Array;
var lastValidKeywordLength
var arrACCache = new Array()
function startAutoComplete()
{
	clearInterval(startTime)
	startTime = setTimeout('fillAutoComplete()', 100)

}


function fillAutoComplete()
{
	txt = $('#search').val()



	if (autoCompleteKeyPressed == 8 && txt.length > lastValidKeywordLength)
	{ 
		//$('#temp').val(lastValidAutoCompleteArray)
		arrAutoComplete = lastValidAutoCompleteArray.join('\n').split('\n')
		fillDivAutoComplete('', true)
	
	}

	//else
		//totalItemsAutoComplete = 141

	if (
		(txt.length == 1 && totalItemsAutoComplete > 140) ||
		(txt.length == 2 && totalItemsAutoComplete > 70) ||
		(txt.length == 3 && totalItemsAutoComplete > 70) ||
		(txt.length == 4 && totalItemsAutoComplete > 70) || 
		totalItemsAutoComplete == undefined ||
		(autoCompleteKeyPressed == 8 && txt.length <= lastValidKeywordLength)
	)
	{
		if (arrACCache[$('#search').val()] == undefined)
		{
		//alert('AJAX ' + txt.length + ' - ' + totalItemsAutoComplete)
		$.ajax({
		type: "GET",
		url: "/losacordes/arquivos/autocomplete/artistas/" + $('#search').val().substr(0, 1) + "/_" + txt + ".txt",
		dataType: "text",
		cache:true,
		success: function(txt) {
			fillDivAutoComplete(txt, false)

			$('#autocompletebox').scrollTop(0)

			},
		error: function ()
		{
			/*arrAutoComplete = new Array()		
			fillDivAutoComplete('', true)*/
			$('#autocomplete').html('')
			totalItemsAutoComplete = 0
			itemAutoComplete = -1			
		}
			
		});
		}
		else
			if (arrACCache[$('#search').val()] != '')
			{
				//alert(arrACCache[$('#search').val()])
				arrAutoComplete = arrACCache[$('#search').val()].join('\n').split('\n')
				//alert('ARRAY CACHE:\n\n' + arrAutoComplete) 
				fillDivAutoComplete('', true)
			}
		
		
	}
	else
	{
		
		if (arrACCache[$('#search').val()] != undefined) 
			arrAutoComplete = arrACCache[$('#search').val()].join('\n').split('\n')
		//alert('ARRAY CACHE 2:\n\n' + arrACCache[$('#search').val()]) 
		// filtra a partir do array atual
		filterDivAutoComplete()
	
	}
}
function filterDivAutoComplete()
{
	//alert('filtrando...' + $('#search').val())
	for (nn = arrAutoComplete.length - 1; nn > 0; nn--)
	{
		if (arrAutoComplete[nn].toLowerCase().indexOf($('#search').val().toLowerCase())==-1   )
			arrAutoComplete.splice(nn,1)
	}
	fillDivAutoComplete('', true)
}
function fillDivAutoComplete(txt, isFiltered)
{
	if (!isFiltered)
	{
		arrAutoComplete = new Array();
		arrACCache[$('#search').val()] = txt.split('\n')

		arrAutoComplete = txt.split('\n')
		
		
		lastValidAutoCompleteArray = txt.split('\n')
		//alert('setou ' + $('#search').val())
		//$('#lastValidAutoCompleteArray1').val(lastValidAutoCompleteArray)
		
		lastValidKeywordLength = $('#search').val().length
		
		//$('#lastValidKeywordLength').val(lastValidKeywordLength)
	}
	html = ''
	totalItemsAutoComplete = arrAutoComplete.length
	itemAutoComplete = -1
	for (n = 1; n < arrAutoComplete.length; n ++)
	{
		arrLine = arrAutoComplete[n].split('|')
		html += '<a href="' + arrLine[0] + '">' + doNegrito(arrLine[1],$('#search').val())  + '</a>'
	
	}
	//if (html > '')	
	$('#autocompletebox').css({'display': 'block'})
	$('#autocomplete').html(html)

}

function doNegrito(T1,T2){
	var pos = 0;
	//var v = T2 //.strip_tags();
	v	  = T2.split(' ');
	for(var n in v){
		pos = T1.toLowerCase().indexOf(v[n].toLowerCase());
		if (pos != -1 && v[n].length > 1){
			t = T1.substring(0, pos);
			t += '<b>' + T1.substring(pos, pos + v[n].length) + '</b>';
			T1 = t + T1.substring(pos + v[n].length);
		}
	}
	return T1;
}
function closeAutoComplete()
{
	
	$('#autocompletebox').fadeOut('fast')
}
function openAutoComplete()
{
	if ($('#search').val() == "¿Qué estás buscando?") $('#search').val('')
	//alert('OPEN \n\n' + arrAutoComplete)
	if (arrAutoComplete.length > 0) $('#autocompletebox').fadeIn('fast')
}

// funcoes gerais

String.prototype.replaceAll = function(de, para){
    var str = this;
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
  }
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal (j);
      }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
  return null;
  }

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  }
  
  
  
  

