$j = jQuery;
/* Botões do lightbox */
$j(document).ready(function () {
$j("#lightbox .btn_close").click(function () {
$j("#lightbox").fadeOut(500);
});
$j("#lightbox .bg_lightbox").click(function () {
$j("#lightbox").fadeOut(500);
});
});
/* ================== */
/* Chama o lightbox */
$j(document).ready(function () {
$j("a[rel='galeria_imagens']").click(function (event) {
event.preventDefault();
var href = $j(this).attr("href"),
title = $j(this).attr("title");
openLightbox(href, title);
});
});
/* Função abrir lightbox */
openLightbox = function (href, title) {
if (href) {
var img = '
';
$j("#lightbox .img").html(img);
if (title) $j("#lightbox p").html(title); else $j("#lightbox p").html('');
$j("#lightbox").show();
$j("#lightbox .content img").load(function() {
$img = $j("#lightbox .content img");
$img_container = $j("#lightbox .content");
$img_height = $img.height();
$img_height = "-" + Math.round($img_height / 2);
$img_container.animate({marginTop : $img_height}, 0);
});
}
}
/* ===================== */
/* Funções para a busca */
busca_autocomplete = function () {
var f = $j("#form_search"),
s = $j("#form_search_s"),
t = document.getElementById('form_search_s'),
x = $j("#form_search_s"),
p = x.position(),
a = $j("#autocomplete_search_results_container");
a.css('left', p.left + 'px');
a.css('top', (p.top + x.outerHeight(true)) + 'px');
try { busca_autocomplete_XMLHTTP.abort(); } catch (e) {}
if(s.val() == t.defaultValue || s.val().length < 3) {
busca_show_results_container(false);
} else {
busca_autocomplete_XMLHTTP = $j.ajax( { type: "POST",
url: "busca_autocomplete.php",
data: f.serialize(),
dataType: "html",
beforeSend: function () {
busca_show_results_container(true, '
');
},
success: function (HTML) {
busca_show_results_container(true, HTML);
}
} );
}
}
busca_autocomplete_timeout = null;
busca_autocomplete_timeout_set = function () {
busca_autocomplete_timeout = setTimeout("busca_autocomplete()", 1000);
}
busca_autocomplete_timeout_cancel = function () {
try {
clearTimeout(busca_autocomplete_timeout);
} catch (e) {
}
}
busca_show_results_container = function (mostra, HTML) {
var a = $j("#autocomplete_search_results_container");
mostra ? a.fadeIn() : a.fadeOut();
if (HTML && HTML.length) a.html(HTML);
}
$j(document).ready(function () {
/* Safely inject CSS3 and give the search results a shadow */
var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
$j("#autocomplete_search_results_container").css(cssObj);
/* ======================================================= */
/* Fade out the suggestions box when not active */
$j("#form_busca_s").blur(function () { setTimeout('busca_show_results_container(false)', 100); });
/* ============================================ */
});
/* ==================== */
/* Funções para cadastro de e-mail no newsletter */
newsletter_form_envia_hide_timeout = null;
newsletter_form_envia_aviso = function (HTML, timeout) {
var d = $j("#newsletter_resposta");
try { clearTimeout(newsletter_form_envia_hide_timeout); } catch (e) {}
d.show();
d.html(HTML);
if (timeout) newsletter_form_envia_hide_timeout = setTimeout('$j("#newsletter_resposta").hide()', 3000);
}
newsletter_form_envia = function () {
var f = document.getElementById("newsletter_form");
if ($j('#newsletter_resposta').css('display') != 'block') {
if (f.nome.value == f.nome.defaultValue) {
newsletter_form_envia_aviso('Preencha o campo "Nome" corretamente', true);
} else {
$j.ajax( { type: "POST",
url: "newsletter_cadastra.php",
data:$j("#newsletter_form").serialize(),
dataType: "html",
beforeSend: function () { newsletter_form_envia_aviso('Enviando dados...', false); },
success: function (HTML) { newsletter_form_envia_aviso(HTML, true); }
} );
}
} else {
alert('Aguarde o processamento dos dados...');
}
}
/* ============================================= */
/* Funções para cadastro de e-mail no visita */
visita_form_envia_hide_timeout = null;
visita_form_envia_aviso = function (HTML, timeout) {
var d = $j("#visita_resposta");
try { clearTimeout(visita_form_envia_hide_timeout); } catch (e) {}
d.show();
d.html(HTML);
if (timeout) visita_form_envia_hide_timeout = setTimeout('$j("#visita_resposta").hide()', 10000);
}
visita_form_envia = function () {
var f = document.getElementById("visita_form");
if ($j('#visita_resposta').css('display') != 'block') {
if (f.email.value == f.email.defaultValue) f.email.value = '';
if (f.nome.value == f.nome.defaultValue) visita_form_envia_aviso('Preencha o campo "Nome" corretamente', true);
else if (f.fone.value == f.fone.defaultValue) visita_form_envia_aviso('Preencha o campo "Fone" corretamente', true);
else if (f.cidade.value == f.cidade.defaultValue) visita_form_envia_aviso('Preencha o campo "Cidade" corretamente', true);
else if (f.estado.value == f.estado.defaultValue) visita_form_envia_aviso('Preencha o campo "Estado" corretamente', true);
else {
$j.ajax( { type: "POST",
url: "visita_post.php",
data:$j("#visita_form").serialize(),
dataType: "html",
beforeSend: function () { visita_form_envia_aviso('Enviando dados...', false); },
success: function (HTML) { visita_form_envia_aviso(HTML, true); }
} );
}
} else {
alert('Aguarde o processamento dos dados...');
}
}
/* ============================================= */
/* Funções para cadastro de e-mail no cadastro_cliente */
cadastro_cliente_form_envia_hide_timeout = null;
cadastro_cliente_form_envia_aviso = function (HTML, timeout) {
var d = $j("#cadastro_cliente_resposta");
try { clearTimeout(cadastro_cliente_form_envia_hide_timeout); } catch (e) {}
d.show();
d.html(HTML);
if (timeout) cadastro_cliente_form_envia_hide_timeout = setTimeout('$j("#cadastro_cliente_resposta").hide()', 3000);
}
cadastro_cliente_form_envia = function () {
var f = document.getElementById("form_register_client");
if ($j('#cadastro_cliente_resposta').css('display') != 'block') {
$j.ajax( { type: "POST",
url: "cadastro_cliente_post.php",
data: $j("#form_register_client").serialize(),
dataType: "html",
beforeSend: function () { cadastro_cliente_form_envia_aviso('Enviando dados...', false); },
success: function (HTML) { cadastro_cliente_form_envia_aviso(HTML, true); }
} );
} else {
alert('Aguarde o processamento dos dados...');
}
}
/* ============================================= */
/* Funções para cadastro de e-mail no contato */
contato_form_envia_hide_timeout = null;
contato_form_envia_aviso = function (HTML, timeout) {
var d = $j("#contato_resposta");
try { clearTimeout(contato_form_envia_hide_timeout); } catch (e) {}
d.show();
d.html(HTML);
if (timeout) contato_form_envia_hide_timeout = setTimeout('$j("#contato_resposta").hide()', 3000);
}
contato_form_envia = function (f) {
if ($j('#contato_resposta').css('display') != 'block') {
if (f.nome.value == f.nome.defaultValue) contato_form_envia_aviso('Preencha o campo "Nome" corretamente', true);
else if (f.email.value == f.email.defaultValue) contato_form_envia_aviso('Preencha o campo "E-mail" corretamente', true);
else if (f.fone.value == f.fone.defaultValue) contato_form_envia_aviso('Preencha o campo "Fone" corretamente', true);
else if (f.mensagem.value == f.mensagem.defaultValue) contato_form_envia_aviso('Preencha o campo "Mensagem" corretamente', true);
else {
$j.ajax( { type: "POST",
url: "contato_post.php",
data: $j(f).serialize(),
dataType: "html",
beforeSend: function () { contato_form_envia_aviso('Enviando dados...', false); },
success: function (HTML) { contato_form_envia_aviso(HTML, true); }
} );
}
} else {
alert('Aguarde o processamento dos dados...');
}
}
/* ============================================= */
/* Funções para envio do formulário de vendas */
vendas_form_envia_hide_timeout = null;
vendas_form_envia_aviso = function (HTML, timeout) {
var d = $j("#vendas_resposta");
try { clearTimeout(vendas_form_envia_hide_timeout); } catch (e) {}
d.show();
d.html(HTML);
if (timeout) vendas_form_envia_hide_timeout = setTimeout('$j("#vendas_resposta").hide()', 3000);
}
vendas_form_envia = function () {
if ($j('#vendas_resposta').css('display') != 'block') {
$j.ajax( { type: "POST",
url: "contato_post.php",
data: $j("#form_sales").serialize(),
dataType: "html",
beforeSend: function () { vendas_form_envia_aviso('Enviando dados...', false); },
success: function (HTML) { vendas_form_envia_aviso(HTML, true); }
} );
} else {
alert('Aguarde o processamento dos dados...');
}
}
/* ============================================= */
/* Atualiza o status do atendimento online */
atendimento_online_get_status = function () {
$j.ajax( { type: "GET",
url: "atendimento_online_get_status.php",
data: "",
dataType: "html",
beforeSend: function () {},
success: function (s) {
var online = s == 1,
cci = $j('#chat_container_index'),
s_o = $j('#atendimento_online #status'),
s_l = $j('#atendimento_online_link'),
c_o = $j('#chat_status'),
c_l = $j('#chat_link');
try {
s_o.toggleClass("online", false).toggleClass("offline", false).toggleClass(online ? "online" : "offline", true);
s_o.html(online ? "Online" : "Offline");
s_l.css('display', online ? 'block' : 'none');
} catch (e) {}
try {
cci.toggleClass('chat_off', !online);
c_o.toggleClass("unavailable", !online);
c_l.css('display', online ? 'block' : 'none');
} catch (e) {}
setTimeout("atendimento_online_get_status()", 10000);
},
error: function () {
setTimeout("atendimento_online_get_status()", 10000);
}
} );
}
$j(document).ready(function () { setTimeout("atendimento_online_get_status()", 10000); });
/* ======================================= */
/* Funções para o menu */
submenu_aparece = function (what, show) {
var classOver = 'link_side_logo_hover',
isIE = !$j.support.boxModel,
m = $j('#menu_' + what),
s = $j('#submenu_' + what),
f = $j("#flash_home");
if (show) {
m.addClass(classOver);
if (isIE) f.fadeOut();
s.show();
} else {
m.removeClass(classOver);
s.hide();
if (isIE) f.fadeIn();
}
}
submenu_posiciona = function (what) {
var m = $j('#menu_' + what),
p = m.position(),
l = p.left,
t = p.top,
w = m.outerWidth(false),
h = m.outerHeight(false),
s = $j('#submenu_' + what),
w2 = s.outerWidth(false),
l_m = what == 'servicos' ? -102 : 1;
s.css('left', (l + l_m) + 'px');
s.css('top', (t + h) + 'px');
}
submenus_posiciona = function () {
try {
submenu_posiciona('empresa');
submenu_posiciona('produtos');
} catch (e) {
}
}
setInterval("submenus_posiciona()", 100);
$j(window).bind('resize', function () { submenus_posiciona() });
/* =================== */
/* ======== jCarousel ========= */
(function () {
$j.fn.infiniteCarousel = function () {
function repeat(str, n) {
return new Array( n + 1 ).join(str);
}
return this.each(function () {
// magic!
var $wrapper = $j('> div', this).css('overflow', 'hidden'),
$slider = $wrapper.find('> ul').width(9999),
$items = $slider.find('> li'),
$single = $items.filter(':first')
singleWidth = $single.outerWidth(),
visible = Math.ceil($wrapper.innerWidth() / singleWidth),
currentPage = 1,
pages = Math.ceil($items.length / visible);
/* TASKS */
// 1. pad the pages with empty element if required
if ($items.length % visible != 0) {
// pad
$slider.append(repeat('', visible - ($items.length % visible)));
$items = $slider.find('> li');
}
// 2. create the carousel padding on left and right (cloned)
$items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
$items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
$items = $slider.find('> li');
// 3. reset scroll
$wrapper.scrollLeft(singleWidth * visible);
// 4. paging function
function gotoPage(page) {
var dir = page < currentPage ? -1 : 1,
n = Math.abs(currentPage - page),
left = singleWidth * dir * visible * n;
$wrapper.filter(':not(:animated)').animate({
scrollLeft : '+=' + left
}, 500, function () {
// if page == last page - then reset position
if (page > pages) {
$wrapper.scrollLeft(singleWidth * visible);
page = 1;
} else if (page == 0) {
page = pages;
$wrapper.scrollLeft(singleWidth * visible * pages);
}
currentPage = page;
});
}
// 5. insert the back and forward link
$wrapper.after('<>');
// 6. bind the back and forward links
$j('a.back', this).click(function () {
gotoPage(currentPage - 1);
return false;
});
$j('a.forward', this).click(function () {
gotoPage(currentPage + 1);
return false;
});
$j(this).bind('goto', function (event, page) {
gotoPage(page);
});
// THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
$j(this).bind('next', function () {
gotoPage(currentPage + 1);
});
});
};
})(jQuery);
$j(document).ready(function () {
// THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
var autoscrolling = true;
$j('.infiniteCarousel').infiniteCarousel().mouseover(function () {
autoscrolling = false;
}).mouseout(function () {
autoscrolling = true;
});
setInterval(function () {
if (autoscrolling) {
$j('.infiniteCarousel').trigger('next');
}
}, 6500);
});
/* =================== */