$j = jQuery; /* Loading */ $j(window).load(function() { $j("#loading_site").hide(); $j("#site").show(); $j("a[rel='produtos']").colorbox(); }); /* ======= */ /* Newsletter */ $j(document).ready(function () { var newsletter = $j("#form_newsletter"), form = newsletter, input = form.find(".textfield1"), botao = form.find("a"), loadi = form.find("span"), aviso = form.find(".aviso"); input.focus(function () { if (this.value == this.defaultValue) this.value = ''; }) .blur(function () { if (this.value == '') this.value = this.defaultValue; }); botao.click(function () { var enviando, fdat; try { enviando = newsletter_XMLHTTP.readyState != 4; } catch (e) { enviando = false; } if (!enviando) { fdat = form.serialize(); input.each(function () { if (this.value == this.defaultValue) fdat = fdat.replace($j(this).serialize(), ""); }); newsletter_XMLHTTP = $j.ajax({ type: form.attr("method"), url: "newsletter-post.php", data: fdat, dataType: "json", beforeSend: function () { botao.css("display", "none"); loadi.css("display", "block"); input.removeClass("erro ok"); aviso.removeClass("erro ok").css("visibility", "hidden"); }, error: function (qXHR, textStatus, errorThrown) { botao.css("display", "block"); loadi.css("display", "none"); aviso.addClass("erro").css("visibility", "visible").html("Erro!"); }, success: function (response) { alert(response.codigo); alert(response.erro); botao.css("display", "block"); loadi.css("display", "none"); if (response.codigo == 0) { form[0].reset(); aviso.addClass("ok"); } else { for (i = 0; i < response.campos.length; i++) { input.each(function () { var obj = $j(this); if (obj.attr("name") == response.campos[i]) obj.addClass("erro"); }); } aviso.addClass("erro"); } aviso.css("visibility", "visible").html(response.erro); } }); } return false; }); }); /* ========== */ /* Nivo Slider */ $j(window).load(function() { $j('#slider').nivoSlider({ effect: 'boxRainGrow', pauseTime: 5000, directionNav: false, controlNav: false }); }); /* =========== */ /* Lightbox */ /*$j(document).ready(function () { $j('a[rel="lightbox_legend"]').click(function() { var this_element = $j(this), this_legend = this_element.children('.legend').html(), this_href = this_element.attr('href'); open_lightbox(this_href, 'image_legend', this_legend); /* Add attr id in the prev and nexts lightboxes */ /* if ($j('a[rel="lightbox_legend"]').length > 1) { var next_element = this_element.next('a[rel="lightbox_legend"]'), prev_element = this_element.prev('a[rel="lightbox_legend"]'); if (prev_element.length == 0) { prev_element = $j('a[rel="lightbox_legend"]:last'); } if (next_element.length == 0) { next_element = $j('a[rel="lightbox_legend"]:first'); } $j('a[rel="lightbox_legend"]').removeAttr('id'); next_element.attr('id', 'next_lightbox'); prev_element.attr('id', 'prev_lightbox'); } else { $j('#lightbox .next').hide(); $j('#lightbox .prev').hide(); } /* ============================================ */ /* return false; }); $j('#lightbox .next').live('click', function() { $j('a[rel="lightbox_legend"]#next_lightbox').trigger('click'); return false; }); $j('#lightbox .prev').live('click', function() { $j('a[rel="lightbox_legend"]#prev_lightbox').trigger('click'); return false; }); $j('a[rel="lightbox_video"]').click(function() { open_lightbox($j(this).attr('id'), 'video'); return false; }); $j("#lightbox .btn_close, #lightbox .shadow").click( function() { $j("#lightbox").stop().animate({ opacity: "0" }, 200, function() { $j("#lightbox").stop().hide().css("opacity","1"); }); $j('#lightbox iframe').hide(); $j('#lightbox iframe')[0].contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*'); return false; }); }); open_lightbox = function(href, lightbox, legend) { $j("html, body").stop().animate({ scrollTop: 0 }, 0); if (lightbox == 'video') { $j('#lightbox .bg iframe').show().attr('src', 'http://www.youtube.com/embed/' + href + '?autoplay=1&wmode=transparent'); $j("#lightbox").fadeIn(500); $j('#lightbox .bg').css('marginLeft', '-320px').css('marginTop', '-240px'); } else if (lightbox == 'image_legend') { $j('#lightbox .bg img').attr('src', href); $j("#lightbox").fadeIn(500); $j("#lightbox .bg").hide(); $j('#lightbox .bg img').load( function() { var bg = $j("#lightbox .bg"); bg.show(); var bg_width = bg.width(), bg_height = bg.height(), img_width = $j("#lightbox .bg img").width(), window_height = $j(window).height(), img_height = $j(this).height(); bg_width = '-' + bg_width / 2 + 'px'; if (bg_height > window_height) bg_height = (window_height - bg_height) / 2; else bg_height = '-' + bg_height / 2 + 'px'; if (legend.length > 0) $j("#lightbox .bg .legend").css('width', img_width).html(legend).show(); bg.css('marginLeft', bg_width).css('marginTop', bg_height).css('width', img_width + 'px'); $j('#lightbox .prev, #lightbox .next').css('height', img_height + 'px').css('marginTop', '-' + img_height + 'px'); }) } } /* ======== */ /* Function form contact */ send_form_contact_message = "Enviando solicitação..."; form_contact_send = function () { if ($j("#form_contact .answer").html() != send_form_contact_message) { $j.ajax({ type: "POST", url: "contato_post.php", data: $j("#form_contact").serialize() + "&send=send", dataType: "html", beforeSend: function () { $j("#form_contact .answer").html(send_form_contact_message); }, success: function (HTML) { $j("#form_contact .answer").html(HTML); } } ); } else { alert("Aguarde enquanto a mensagem está sendo enviada."); } } /* ============================== */ /* Mask */ //$j(document).ready(function () { $j("#datepicker2").focus(function () { $j(this).mask("99/99/9999"); }); }); /* ==== */ /* Paginators */ /*news_paginator = function (page) { $j.ajax({ type: "GET", url: "noticias_paginacao.php", data: "pagina=" + page, dataType: "html", beforeSend: function () { $j("#news_paginator").html('
mais notícias
'); }, success: function (HTML) { $j("#news_paginator").html(HTML); } } ); $j(".paginator_bottom").hide(); $j(".paginacao_loading_bottom").show(); } /* =========== */ /* Funções para a busca */ /*busca_autocomplete = function (page) { 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: "http://www.coconutoficial.com.br/busca_autocomplete.php", data: f.serialize() + "&page=" + page, 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 (page) { busca_autocomplete_timeout = setTimeout("busca_autocomplete('" + page + "')", 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); }); /* ============================================ */ /* }); /* ==================== */