 /* @description: Anima a barra de busca @usage: scrollBg(element); */ function scrollBg() { searchBarCurrent -= searchBarStep; if (searchBarCurrent == searchBarRPos) { searchBarCurrent = 0; } $('#q').css("background-image", "url(" + images + "searchBar.png)"); $('#q').css("background-position",searchBarCurrent+"px 0"); } /* @description: Inicia ou pausa a animação da barra de buscas @usage: animateSearchBar (); */ function animateSearchBar (stop) { if (!stop) { searchBarCurrent = 0; clearTimeout(searchBarTimer); searchBarTimer = setInterval("scrollBg()", searchBarSpeed); } else { clearTimeout(searchBarTimer); $('#q').css("background-image", "url(" + images + "fields.png)"); } } /* @description: Pega os veículos para a suggestion box @usage: getVehicleNames(); */ function getVehicleNames () { $.ajax ({ type : "POST", url : ajaxCall + 'names', data : 'token=' + token, dataType	: "json", success : function (callBack) { if (callBack && callBack != 'token_error') { $('input#q').jsonSuggest(callBack, { maxResults : 8, onSelect : suggestCallBack }); } } }); } /* @description: Carrega um HTML contendo textos de páginas @usage: textBox('sobre', 640, 480); */ function textBox (page, width, height) { if (!width) width = 800; if (!height) height	= 300; if (page) { if (!pageTimer) { pageTimer = true; $.ajax ({ type : "POST", url : ajaxCall + 'textbox', data : 'token=' + token + '&page=' + page, dataType	: "html", error : function (XMLHttpRequest, textStatus) { showMessage ('Ocorreu um erro do servidor ao abrir esta p&aacute;gina. Poderia tentar novamente?', true); }, success : function (callBack) { switch (callBack) { case 'token_error': document.location = root + 'f=xmlhttperror'; break; case 'page_not_found': showMessage ('Desculpe, mas a p&aacute;gina acessada est&aacute; temporariamente indispon&iacute;vel!', true); break; default: $('#content').html(callBack); $.blockUI( { fadeIn: 0, fadeOut: 0, focusInput: true, message: $('#textBox'), overlayCSS: { backgroundColor: '#ffffff', backgroundImage: 'url(' + images + 'overlay.png)', opacity: 0.7, cursor: 'default' }, css: { width: width + 'px', height: height + 'px', left: '50%', top: '50%', marginLeft: '-' + (width/2) + 'px', marginTop: '-' + (height/2) + 'px', border: '10px solid #a1ba00', backgroundColor: '#ffffff', cursor: 'auto', textAlign: 'left' } }); break; } pageTimer = false; } }); } } else { showMessage('Ocorreu um erro ao abrir esta p&aacute;gina. Por favor, tente novamente mais tarde!'); } } /* @description: Inicia o processo de busca @usage: startSearch('FIAT PALIO'); */ function startSearch (query) { var total = 0; var HTMLoutput = ""; var url = ""; var nome = ""; var foto = ""; var valor = ""; var opcionais = ""; var extra = ""; var descricao = ""; var telefone = ""; var hash = location.hash; hash = hash.replace(/^.*#/, ''); if (query) { if (!w8server) { $('#q').attr('value', query); w8server = true; animateSearchBar (); $.unblockUI(); $.ajax ({ type : "POST", url : ajaxCall + 'search', data : 'token=' + token + '&q=' + query, dataType	: "json", error : function (XMLHttpRequest, textStatus) { showMessage ('Ops! Poderia tentar novamente?', true); animateSearchBar (true); unlockerTimeout = setTimeout('unlocker ()', 1000); }, success : function (callBack) { if (callBack.results && callBack.results != 'none') { total = callBack.results.length; if (total) { HTMLoutput = ""; $('#info').html('Encontrado(s) <b>' + total + ' ve&iacute;culo(s)</b> para <b>&quot;' + query + '&quot;</b>'); for (var i in callBack.results) { if (callBack.results[i].foto) foto = root + callBack.results[i].zid + '/photos/' + callBack.results[i].foto + '_mini.jpg'; else foto = images + 'blank.png'; if (callBack.results[i].valor) valor = currency + ' ' + callBack.results[i].valor; else valor = 'Confira!'; if (callBack.results[i].opcionais) opcionais = callBack.results[i].opcionais; else opcionais = ''; if (callBack.results[i].descricao) descricao = callBack.results[i].descricao; else descricao = ""; url = root + callBack.results[i].zid + '/veiculo/' + callBack.results[i].id; nome = '<span>' + callBack.results[i].nome + '</span> ' + callBack.results[i].ano; extra = '<a href="' + callBack.results[i].site + '" target="_blank" style="font-weight: bold; color: #666;">' + callBack.results[i].empresa + '</a>'; HTMLoutput += '<li id="car_' + callBack.results[i].id + '" class="box">'; HTMLoutput += '<div class="image"><a href="' + url + '" target="_blank"><img src="' + foto + '" border="0" width="80" height="60" title="Ver detalhes" alt="Clique para ver mais detalhes" /></a></div>'; HTMLoutput += '<div class="nome"><a href="' + url + '" target="_blank" title="Ver detalhes">' + nome + ' ' + opcionais + '</a></div>'; HTMLoutput += '<div class="valor"><a href="' + url + '" target="_blank" title="Ver detalhes">' + valor + '</a></div>'; HTMLoutput += '<div class="revenda">' + extra + '</div>'; HTMLoutput += '</li>'; HTMLoutput += '<li class="spacer">&nbsp;</li>'; } if (!disableAnimation) { $("#search").animate ({ top: '0%', marginTop: '0px' }, { duration: 500 }); $("#beta").fadeOut(); $("#search").queue(function () { $(this).dequeue(); $('#results').show(); $('#bottom').show(); $('#resultsPlace').html(HTMLoutput); document.location = '#' + query; $('#q').attr('value', unescape(query)); $('#info').fadeIn(); $(".image img, .nome a").tooltip ({ track: true, delay: 0, showURL: false, fade: 100 }); disableAnimation = true; }); } else { $('#results').show(); $('#bottom').show(); $('#resultsPlace').html(HTMLoutput); document.location = '#' + query; $('#q').attr('value', unescape(query)); $('#info').fadeIn(); $(".image img, .nome a").tooltip ({ track: true, delay: 0, showURL: false, fade: 100 }); disableAnimation = false; } } else { $('#results').hide(); $('#bottom').hide(); $('#info').hide(); $('#resultsPlace').html(""); disableAnimation = true; } } else { $('#results').hide(); $('#bottom').hide(); $('#info').hide(); $('#resultsPlace').html("");; showMessage ('Nenhum ve&iacute;culo encontrado com a palavra \'' + query + '\'.<br />Tente ser menos espec&iacute;fico em sua busca!<br /><button class="buttons2" onclick="$.unblockUI(); $(\'#q\').focus();">Fechar</button>'); disableAnimation = true; } unlockerTimeout = setTimeout('unlocker ()', 1000); animateSearchBar (true); if (callBack.noresults) { showMessage ('Nenhum ve&iacute;culo encontrado com a palavra \'' + query + '\'.<br />Tente ser menos espec&iacute;fico em sua busca!<br />Que tal dar uma olhada nas sugest&otilde;es abaixo?<br /><br /><button class="buttons2" onclick="$.unblockUI(); $(\'#q\').focus();">Fechar</button>'); } } }); } } else { $('#results').hide(); $('#bottom').hide(); $('#resultsPlace').html(""); } } /* @description: Exibe mensagens de avisos no topo @usage: showMessages('Mensagem de erro'); */ function showMessage (msg, error) { if (msg) { var bgcolor = ""; $('#messageText').html(msg); if (error) bgcolor = '#bf0000'; else bgcolor = '#a1ba00'; $.blockUI ({ message: $('#message'), fadeIn: 800, fadeOut: 800, showOverlay: false, centerX: true, centerY: 0, css: { width: '800px', top: '20px', left: '50%', border: 'none', marginLeft: '-400px', padding: '10px', backgroundColor: '#666666', opacity: .9, color: '#fff', textAlign: 'center', cursor: 'default', fontWeight: 'bold' } }); } } /* @description: Funções adicionais */ function suggestCallBack (item) {startSearch ($('#q').val()); $('#q').focus();} function unlocker () {clearTimeout(unlockerTimeout); w8server = false;} 
