﻿
//Unload
//$(window).unload(function () { PreviewCarrinhoLoad(); });

(function ($) {
	$.fn.extend({

		customStyle: function (options) {
			if (!$.browser.msie || ($.browser.msie && $.browser.version > 6)) {
				return this.each(function () {

					var currentSelected = $(this).find(':selected');
					$(this).wrap("<div class='selectcustom' />");
					$(this).before('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">' + currentSelected.text() + '</span></span>').css({ position: 'absolute', opacity: 0, fontSize: $(this).next().css('font-size') });
					var selectBoxSpan = $(this).next();
					var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) - parseInt(selectBoxSpan.css('padding-right'));
					var selectBoxSpanInner = selectBoxSpan.find(':first-child');
					selectBoxSpan.css({ display: 'inline-block' });
					selectBoxSpanInner.css({ width: selectBoxWidth, display: 'inline-block' });
					var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
					$(this).height(selectBoxHeight).change(function () {
						// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
						$(this).parent().find('.customStyleSelectBoxInner').text($(this).find(':selected').text()).parent().addClass('changed');
						// Thanks to Juarez Filho & PaddyMurphy
					});

				});
			}
		}
	});
})(jQuery);

$(function () {
    $('.fale select, .politica select, select.custom').customStyle();
    $('.CmpCarrinho .Titulo img').click(function () {
        $(this).parent().toggleClass('fechado');
        if ($(this).parent().hasClass('fechado')) {
            $('.CmpCarrinho .Titulo img.imgdetalhe').hide();
            $('.CmpCarrinho .Titulo img.imgfechar').show();
        } else {
            $('.CmpCarrinho .Titulo img.imgdetalhe').show();
            $('.CmpCarrinho .Titulo img.imgfechar').hide();
        }
        $('.detalhe').slideToggle();
        return false;
    });

    var text = 'Buscar aparelhos';
    $('.CmpTxt input').val(text).focus(function () {
        if ($(this).val() == text) { $(this).val(''); }
    }).blur(function () {
        if ($(this).val() == '') { $(this).val(text); }
    });

    /* Saudação */

    if ($('window').height() > $('.tudo').height()) {
        var wid = $('window').height();
    } else {
        var wid = $('.tudo').height() + $('.rodape').height();
    }

    $('.mask').css({ 'height': '' + wid + 'px', 'opacity': '.75' });

    //    /* Detalhe do Produto */
    //    $('.loading').hide();
    //    $(".thumb a").click(function () {
    //        var link = $(this).attr("href");
    //        alert(link);
    //        $(".loading").before("<img class='load' src='http://novo.celuladireto.com.br/upload/" + link + "' alt='' />");
    //        $(".big > img").eq(1).fadeOut(function () { $(this).remove(); });
    //        $('.loading').fadeIn();
    //        $('.load').hide().load(function () {
    //            $('.loading').hide();
    //            $(this).fadeIn();
    //            $(this).removeClass('.load');
    //        });
    //        return false;
    //    });

    $('.hide').not(':first').hide();
    $('.detalheaba ul li:first a').addClass('ativo');
    $('.detalheaba ul li a').click(function () {
        var link = $(this).attr('href');
        $('.ativo').removeClass('ativo');
        $(this).addClass('ativo');
        $('.hide').hide();
        $(link).show();
        return false;
    });

    $('.perfil .direita div.pedidos ul li > div').hide();
    $('#perfilDireitaPrimeiro').slideToggle();
    $('.perfil .direita div.pedidos ul li > p').click(function () {
        $(this).next('div').slideToggle();
    });

    // Masks

    //$('.data').mask("99/99/9999");

    /* Filtro Home */

    $(".CmpEncontre a").click(function () {
        $(this).next(".SubMarca").slideToggle();
        return false;
    });

    $(".busca ul li a").click(function () {
        $(this).next(".SubMarca").toggle();
        return false;
    });

    $(".sexto img").click(function () {
        $(this).parent().next(".oculta").slideToggle();
        return false;
    });

    // Hover dos Boxes em Serviços
    $(".servicos .primeiro").hover(
		function () { $(this).find("p").show(); },
		function () {
		    $(this).find("p").hide();
		});

    $(".duvidahide div p").hide();
    $(".duvidahide h2").click(function () {
        $(this).toggleClass("aberto");
        $(this).next("div").find("p").toggle();
    });

    $('.movelhide').not(':first').hide();
    $('.movelaba > ul li:first').addClass('ativo');
    $('.movelaba > ul li a').click(function () {
        var link = $(this).attr('href');
        $('.ativo').removeClass('ativo');
        $(this).parent().addClass('ativo');
        $('.movelhide').hide();
        $(link).show();
        return false;
    });

});
