	// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
	function pageload(hash){
		//alert("pageload: "	 + hash);
		// hash doesn't contain the first # character.
		if(hash){
			// restore ajax loaded state
			if($.browser.msie) {
				// jquery's $.load() function does't work when hash include special characters like åäö.
				hash = encodeURIComponent(hash);
			}
			var myuri = location.hash;
			var myURI = myuri.split('#');
			var myurl = decodeURI(myURI[1]);
			//console.log(myurl);
			$('#quicktabs-itens ul li').each(function(){
				var $a = $('a',this);
				//console.log($a.text() + '==' + myurl);
				if($a.text() == myurl){
					$a.click();
					return;		
				}
			});
			$("#load").load(hash + ".html");
		} else {
			// start page
			$("#load").empty();
		}
	}
	
	$(document).ready(function(){
		// Initialize history plugin.
		// The callback is called at once by present location.hash. 
		$.historyInit(pageload, 'histoty_html.html');
		
		// set onlick event for buttons
		$("a[rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a neconw page. 
			// pageload is called at once. 
			// hash don't contain "#", "?"
			$.historyLoad(hash);
			return false;
		});
		
		
		// Search field label
		$("#edit-search-block-form-1").attr({ value: "Pesquisar", style: "color:#CCC;" });
		
		$("#edit-search-block-form-1").focus(function(){
			//
			if( $(this).attr('value') == "Pesquisar" )
				$(this).attr({ value: "", style: "color:#999;" });
		});
		
		$("#edit-search-block-form-1").blur(function(){
			//
			if( $(this).attr('value') == "" )
				$(this).attr({ value: "Pesquisar", style: "color:#CCC;" });
		});
		
		// Sets the main block's background image
		$('#block-views-Destaque-block_1').attr({ style: "background-image: url(" + $('div#tabs--1 div.views-field-field-image-fid span.field-content').text() + ");" });
		
		// Change the main block's background image
		$('a[href=#tabs--1]').click(function() {
			$('#block-views-Destaque-block_1').attr({ style: "background-image: url(" + $('div#tabs--1 div.views-field-field-image-fid span.field-content').text() + ");" });
		});
		
		$('a[href=#tabs--2]').click(function() {
			$('#block-views-Destaque-block_1').attr({ style: "background-image: url(" + $('div#tabs--2 div.views-field-field-image-fid span.field-content').text() + ");" });
		});
		
		$('form input.form-text:first').focus();
		$('body.page-institucional div.filefield-file:first').attr({ style: "border: none !important;" });
		
		$('a[href=#tabs--1]').click(function() {
											 $('#tabs--1').attr({ style: "display: block !important;" });
											 $('#tabs--2').attr({ style: "display: none !important;" });
											 });
		
		$('a[href=#tabs--2]').click(function() {
											 $('#tabs--2').attr({ style: "display: block !important;" });
											 $('#tabs--1').attr({ style: "display: none !important;" });
											 });
		
		$('#node-6 h2 a, #node-7 h2 a, #node-8 h2 a').click(function(){ return false; });
	});

$(function(){
	$('#quicktabs-itens ul li a').click(function(){
		location.hash = $(this).text();
	});
	
	//nao esta usando o carousel no momento entao desabilita
	/*
	$("#slider .item-list").jCarouselLite({
	    btnNext: "#slider #next",
	    btnPrev: "#slider #prev"
	});
	*/
	/* 
	coloquei a classe padrão do Drupal
	basta customizar uma classe de erro no css e trocar o nome da classe nessa variavel
	var classe_erro = 'error';
	var msg_padrao = 'O campo deve ser preenchido.';
	var msg_email = 'O email digitado não é válido.';
	var msg_only_numbers = 'Digite apenas números';
	$('#webform-client-form-40').validate({
		rules: {
			'submitted[informacoes_da_empresa][codigo_good_card]': {required: true},
			'submitted[informacoes_da_empresa][nome_fantasia]': {required: true},
			'submitted[informacoes_de_contato][nome_do_contato]':{required: true},
			'submitted[informacoes_de_contato][email]': {required: true, email:true},
			'submitted[informacoes_de_contato][telefone]': {required: true,digits:true},
			'submitted[informacoes_de_contato][prefere_proposta_por]': {required: true},
		},
		messages: {
			'submitted[informacoes_da_empresa][codigo_good_card]': {required: msg_padrao},
			'submitted[informacoes_da_empresa][nome_fantasia]': {required: msg_padrao},
			'submitted[informacoes_de_contato][nome_do_contato]': {required: msg_padrao},
			'submitted[informacoes_de_contato][email]': {required: msg_padrao, email: msg_email},
			'submitted[informacoes_de_contato][telefone]': {required: msg_padrao,digits: msg_only_numbers},
			'submitted[informacoes_de_contato][prefere_proposta_por]': {required: msg_padrao},
		},
		highlight: function(element, errorClass){
			$(element).addClass(classe_erro);
			$(element).prev().addClass(classe_erro);
		},
		unhighlight: function(element, errorClass){
			$(element).removeClass(classe_erro);
			$(element).prev().removeClass(classe_erro);
		},
		errorPlacement: function(error, element){
			if($(element).attr('name') == 'submitted[informacoes_de_contato][prefere_proposta_por]'){
				error.appendTo(element.parent('label').parent('div').parent('div').prev('label'));
			}else{
				error.appendTo(element.prev());
			}
		},
		errorElement: 'strong',
		submitHandler: function(form){
			$(form).submit();
		});
	});
	 */
});