$(document).ready(function(){
	
	/* TABS */
	$.fn.tabs = function(){
		return this.click(function(){
			$(this).addClass('ativo').siblings().removeClass('ativo');
			var tgt = $(this).find('a:first').attr('href');
			$(tgt).show().siblings('.box').hide();
			return false;
		});
	}
		
	/* tabs sidebar */
	$('#info_local').hide();
	$('#info li').tabs();
	
	/* hover menus IE6 */
	if ($.browser.msie && $.browser.version < 7){
	$('#nav li').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
	};
	
	$('#form-busca :submit').click(function(){
		var query = $('#inp-buscar').val();
		location.hash = '#busca{'+query+'}';
		$.getJSON('http://ajax.googleapis.com/ajax/services/search/web?callback=?',{
			v: '1.0',
			q: 'site:www.brjbank.com.br ' + query,
			lr: location.search.slice(-3) == '/en' ? 'lang_en' : 'lang_pt'
		}, function(data){
			var texto = /\/en/.test(location.href) ? 'Results for' : 'Resultados para';
			var $res = $('<ul/>').appendTo( $('#section > .content').empty().append('<h2>'+texto+' "'+query+'"</h2>') );
			$.each(data.responseData.results, function(){
				$('<li/>')
					.append( $('<a/>').text( this.titleNoFormatting ).attr('href', this.unescapedUrl) )
					.append( $('<p/>').html( this.content ) )
					.appendTo( $res );
			});
		});
		return false;
	});
	
	// busca + history
	var busca;
	if (busca = location.hash.match(/busca{([\w\s]+)}/)){
		$('#inp-val').val( busca[1] )
		$('#form-busca :submit').click();
	}
	
});

if ( ~~(Math.random()*2) )
	$(window).load(function(){
		$.get('/cotacao/update.php');
	});
