﻿////// Funções do countdown

function setcountdown(theyear, themonth, theday, thehour, themin, thesec) {
    yr = theyear; mo = themonth; da = theday; hr = thehour; min = themin; sec = thesec
}

var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
var crosscount = ''

function start_countdown() {
    if (document.layers)
        document.countdownnsmain.visibility = "show"
    else if (document.all || document.getElementById)
        crosscount = document.getElementById && !document.all ? document.getElementById("dias_cont") : dias_cont
    countdown()
}

function countdown() {
    var today = new Date()
    var todayy = today.getYear()
    if (todayy < 1000)
        todayy += 1900
    var todaym = today.getMonth()
    var todayd = today.getDate()
    var todayh = today.getHours()
    var todaymin = today.getMinutes()
    var todaysec = today.getSeconds()
    var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec
    futurestring = montharray[mo - 1] + " " + da + ", " + yr + " " + hr + ":" + min + ":" + sec
    dd = Date.parse(futurestring) - Date.parse(todaystring)
    dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1)
    dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1)
    dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1)
    dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1)

    if (dday <= -1) {
        if (document.layers) {
            document.countdownnsmain.document.countdownnssub.document.write("0")
            document.countdownnsmain.document.countdownnssub.document.close()
        }
        else if (document.all || document.getElementById)
            crosscount.innerHTML = "0"
        return
    }
    //else, if not yet
    else {
        if (document.layers) {
            document.countdownnsmain.document.countdownnssub.document.write(dday)
            document.countdownnsmain.document.countdownnssub.document.close()
        }
        else if (document.all || document.getElementById)
            crosscount.innerHTML = dday
    }
    setTimeout("countdown()", 1000)
}

function replaceAll(string, token, newtoken) {
    while (string.indexOf(token) != -1) {
        string = string.replace(token, newtoken);
    }
    return string;
}

// Fotos Flickr

function LoadPhotos(userId) {
    $("#flickrThumbs_progress").show();

    var flickrUrl = "http://api.flickr.com/services/feeds/photos_public.gne?id=" + userId + "&format=json&jsoncallback=?";

    $.getJSON(flickrUrl, function(data) {
        $("#flickrThumbs_thumbnails").empty();
        $.each(data.items, function(i, item) {
            $("<div/>")
                    .addClass("thumbFoto")
                    .attr({
                        id: ('thumb' + i)
                    }).appendTo("#flickrThumbs_thumbnails");

            $("<a/>")
                    .attr({
                        id: ('thumbLink' + i),
                        href: item.link,
                        target: '_blank'
                    }).appendTo("#thumb" + i);

            $("<img/>")
                    .attr({
                        src: item.media.m,
                        width: '75'
                    }).appendTo("#thumbLink" + i);
        });

        $("#flickrThumbs_thumbnails").css('display', 'block');
        $("#flickrThumbs_progress").hide();
    });
}

$(document).ready(function() {
    /* ID Digitas: 56286005@N07*/
    var url = window.location + "";
    if(url.lastIndexOf("Imprensa") > -1)
        LoadPhotos("56286005@N07");
});

//Resultados de busca
$(document).ready(function() {
    $(".PagingTable span:contains('First'), .PagingTable a:contains('First')").css("display", "none");
    $(".PagingTable span:contains('Last'), .PagingTable a:contains('Last')").css("display", "none");

    $(".PagingTable span:contains('Previous'), .PagingTable a:contains('Previous')").addClass("pgAnt");
    $(".PagingTable span:contains('Next'), .PagingTable a:contains('Next')").addClass("pgProx");
});

// Estilos busca

$(document).ready(function() {
    if ($("#dnn_dnnSEARCH_txtSearch").attr("value") == '') $("#dnn_dnnSEARCH_txtSearch").css("background", "url(/Portals/_default/Skins/Whirlpool/Images/busca_bg_text.png) no-repeat 3px 7px");

    $("#dnn_dnnSEARCH_txtSearch").focus(function() {
        $("#dnn_dnnSEARCH_txtSearch").css("background", "none");
    });
    $("#dnn_dnnSEARCH_txtSearch").blur(function() {
        if ($("#dnn_dnnSEARCH_txtSearch").attr("value") == '') $("#dnn_dnnSEARCH_txtSearch").css("background", "url(/Portals/_default/Skins/Whirlpool/Images/busca_bg_text.png) no-repeat 3px 7px");
    });
});


$(document).ready(function() {
    $(".listaMarcasInt li").mouseover(function() {
        $(this).css("background", "url(/Portals/11/Images/marcas_bg_sel.png) no-repeat center top");
    });
    $(".listaMarcasInt li").mouseout(function() {
        $(this).css("background", "url(/Portals/11/Images/marcas_bg.png) no-repeat center top");
    });
});

$(document).ready(function() {
    $(".listaInovacaoInt li").mouseover(function() {
        $(this).css("background", "url(/Portals/11/Images/inovacao_bg2_sel.jpg) no-repeat center top");
    });
    $(".listaInovacaoInt li").mouseout(function() {
        $(this).css("background", "url(/Portals/11/Images/inovacao_bg2.jpg) no-repeat center top");
    });
});


$(document).ready(function() {
    $(".listaSobre2Int li").mouseover(function() {
        $(this).css("background", "url(/Portals/11/Images/sobre_bg_sel.jpg) no-repeat center top");
    });
    $(".listaSobre2Int li").mouseout(function() {
        $(this).css("background", "url(/Portals/11/Images/sobre_bg.jpg) no-repeat center top");
    });
});

$(document).ready(function() {
    $('.intShare .aFacebook a').attr({
        href: "http://www.facebook.com/share.php?u=" + window.location,
        target: "_blank"
    });
    $('.intShare .aTwitter a').attr({
        href: "http://www.twitter.com/home?status=" + replaceAll(document.title, " ", "+") + ":+" + window.location,
        target: "_blank"
    });
    $(".intShare .aMail a").attr({
        href: "http://www.whirlpool.com.br/Portals/11/Util/EnviarPorEmail.aspx?urlRelease=" + window.location + "&tituloRelease=" + replaceAll(document.title, " ", "+") + "&iframe=true&width=578&height=496",
        rel: "prettyPhoto"
    });
});
$(document).ready(function() {
    $('a.BlogPrint, a.BlogSavePDF').attr({
        href: "http://www.whirlpool.com.br/Portals/11/Util/ExportPrint.aspx?url=" + window.location + "&iframe=true&width=790&height=700",
        rel: "prettyPhoto"
    });
});



/////PESSOAS ////////

$(document).ready(function() {

    $(".listaPessoasInt li").mouseover(function() {
        $(this).css("background", "url(/Portals/11/Images/pessoas_bg_sel.jpg) no-repeat center top");
    });
    $(".listaPessoasInt li").mouseout(function() {
        $(this).css("background", "url(/Portals/11/Images/pessoas_bg.jpg) no-repeat center top");
    });
    $(".boxImagem iframe").attr({
        src: "http://www.facebook.com/plugins/like.php?href=" + window.location + "&layout=button_count&show_faces=true&width=450&action=recommend&colorscheme=light&height=80"
    });


});

////FIM PESSOAS ////



$(document).ready(function() {
    var psize = $('p');
    var tamanhoatual = 0;
    var tamanhoatual = tamanhoatual + 1;
    $(".acessMaxTexto").click(function() {
        var size = $(psize).css("font-size");
        var newSize = parseInt(size.replace(/px/, "")) + 1;

        if (tamanhoatual <= 2) {
            $(psize).css("font-size", newSize + "px");
            tamanhoatual++;
        }

    });
    $(".acessMinTexto").click(function() {
        var size = $(psize).css("font-size");
        var newSize = parseInt(size.replace(/px/, "")) - 1;

        if (tamanhoatual >= 0) {
            $(psize).css("font-size", newSize + "px");
            tamanhoatual--;
        }

    });
});


////////////////  MARCAS //////////////////////

$(document).ready(function() {
    $(".homeMarcasCont > .marcaSel").hide();
    //$(".homeMarcasCont > .marcaSel:eq(0)").show();

    $(".listaMarcas li > a:eq(0)").parent().removeClass("itemAtivo");
    opentab(1);
});

function opentab(num) {
    $(".homeMarcasCont > .marcaSel").hide();
    $(".homeMarcasCont > .marcaSel:eq(" + (num - 1) + ")").fadeIn();

    $(".listaMarcas li > a").parent().removeClass("itemAtivo");

    $(".listaMarcas li > a:eq(" + (num - 1) + ")").parent().addClass("itemAtivo");
}

//// Links

// Sobre
$(document).ready(function() {
    $(".listaSobre2Int .unidades").parent().click(function() {
        window.location = "/SobreaWhirlpool/Unidades.aspx";
    });
    $(".listaSobre2Int .compraCerta").parent().click(function() {
        window.location = "/SobreaWhirlpool/CompraCerta.aspx";
    });
    $(".listaSobre2Int .embraco").parent().click(function() {
        window.location = "/SobreaWhirlpool/Embraco.aspx";
    });
    $(".listaSobre2Int .corportation").parent().click(function () {
        window.location = "/SobreaWhirlpool/WhirlpoolCorp.aspx";
    });
});


// Pessoas
$(document).ready(function() {
    
    $(".listaPessoasInt .codigoEtica").parent().click(function() {
        window.location = "/Pessoas/CódigodeÉtica.aspx";
    });

    $(".listaPessoasInt .trainee").parent().click(function () {
        window.location = "/Pessoas/Trainee.aspx";
    });

    $(".listaPessoasInt .estagio").parent().click(function () {
        window.location = "/Pessoas/Estágio.aspx";
    });

    $(".listaPessoasInt .trabalheConosco").parent().click(function () {
        window.location = "/Pessoas/TrabalheConosco.aspx";
    });

    $(".listaPessoasInt .nossosPremios").parent().click(function () {
        window.location = "/Pessoas/NossosPrêmios.aspx";
    });

});

$(document).ready(function() {
//INOVACAO
$(".listaInovacaoInt .premioInova").parent().click(function () {
    window.location = "/Inovação/PrêmioInova.aspx";
});

$(".listaInovacaoInt .produtos").parent().click(function () {
    window.location = "/Inovação/Produtos.aspx";
});

});


//////////////////////////////////////////////
///////////////// BANNER////////////////////////
jQuery(document).ready(function() {

    jQuery(".paging").show();
    jQuery(".paging span:first").addClass("active");

    var imageWidth = jQuery(".window").width();
    var imageSum = jQuery(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;

    jQuery(".image_reel").css({ 'width': imageReelWidth });


    rotate = function() {

        var triggerID = jQueryactive.attr("rel") - 1; //Get number of times to slide
        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

        jQuery(".paging span").removeClass('active'); //Remove all active class
        jQueryactive.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

        //Slider Animation
        jQuery(".image_reel").animate({
            left: -image_reelPosition
        }, 700);

    };

    //Rotation + Timing Event
    rotateSwitch = function() {

        play = setInterval(function() { //Set timer - this will repeat itself every 3 seconds
            jQueryactive = jQuery('.paging span.active').next();
            if (jQueryactive.length === 0) { //If paging reaches the end...
                jQueryactive = jQuery('.paging span:first'); //go back to first
            }
            // clearInterval(play);
            rotate(); //Trigger the paging and slider function
        }, 10000);

    };

    rotateSwitch(); //Run function on launch

    //On Hover
    jQuery(".image_reel span").hover(function() {
        clearInterval(play); //Stop the rotation
    }, function() {
        rotateSwitch(); //Resume rotation
    });


    //On Click
    jQuery(".paging span").click(function() {
        clearInterval(play);

        jQueryactive = jQuery(this); //Activate the clicked paging

        rotate(); //Trigger rotation immediately
        clearInterval(play); //Stop the rotation          

        rotateSwitch(); // Resume rotation
        clearInterval(play);

        return false; //Prevent browser jump to link anchor
    });

});

$(document).ready(function () {
    $.getScript("http://www.whirlpool.com.br/Portals/11/JavaScript/jquery.cycle.all.2.74.js", function () {
        $('.slideshow').cycle({
            prev: '#prev1',
            next: '#next1',
            nowrap: 1,
            timeout: 0,
            fx: 'fade',
            after: onAfter,
            cleartypeNoBg: 'true'
        });
    });
});

$(document).ready(function () {
    $(".slideshow .slideImg").css("background", "url('')");
});

function onAfter(curr, next, opts) {
    var caption = "<strong>" + (opts.currSlide + 1) + "</strong> / " + opts.slideCount;
    $('#caption').html(caption);
}





//////////////////////FIM BANNER /////////////////////////////


/* CONSULADO DA MULHER */

$(document).ready(function () {
    $('.listaConsuladoInt a').click(function () {
        switch_tabs02($(this));
    });
    switch_tabs02($('.defaulttab02'));
});
function switch_tabs02(obj) {
    $('.tab-content02').hide();
    $('.listaConsuladoInt a').removeClass("itemAtivo");
    var id = obj.attr("rel");
    $('#' + id).show();
    obj.addClass("itemAtivo");
}

/* Contato */

$(document).ready(function() {
    $('.abasContato a').click(function() {
        switch_tabs03($(this));
    });
    switch_tabs03($('.defaulttab02'));
});
function switch_tabs03(obj) {
    $('.tab-content02').hide();
    $('.abasContato a').removeClass("itemAtivo");
    var id = obj.attr("rel");
    $('#' + id).show();
    obj.addClass("itemAtivo");
}

//////////////////////UNIDADES - MAPA /////////////////////////////
$(document).ready(function () {
    $('.listaUnidadesInt a').click(function () {
        switch_tabs($(this));
    });
    switch_tabs($('.defaulttab'));
});

function switch_tabs(obj) {
    $('.tab-content').hide();
    $('.listaUnidadesInt a').removeClass("selected");
    var id = obj.attr("rel");
    $('#' + id).show();
}

$(document).ready(function () {
    $(".listaUnidadesInt li a").mouseover(function () {
        $(this).addClass('itemAtivo');
    });
    $(".listaUnidadesInt li a").mouseout(function () {
        $(this).removeClass('itemAtivo');
    });
});

$(document).ready(function () {
    $(".homeMarcas .listaMarcas li").mouseover(function () {
        $(this).addClass('itemAtivo');
    });
    $(".homeMarcas .listaMarcas li").mouseout(function () {
        $(this).removeClass('itemAtivo');
    });
});
///////////////////////////////////////////////////////////////
////////////////////  AMBIENTAL  /////////////////////////////
$(document).ready(function () {
    $("ul.menu_body li:even").addClass("alt");
    
	$('span.menu_head').click(function () {
    $('ul.menu_body').slideToggle('medium');
    });
	
		
	$('.menu_body li a').click(function () {
		$('ul.menu_body').slideToggle('medium');
    });
	
});

$(document).ready(function () {
    $('.menu_body a').click(function () {
        switch_tabs01($(this));
    });
    switch_tabs01($('.defaulttab01'));
});

function switch_tabs01(obj) {
    $('.tab-content01').hide();
    var id = obj.attr("rel");
    $('#' + id).show();
    $('.menu_head').html(obj.html());
    
}
///////////////////////////////////////////////////////////////

// Menu


var selector = "#nav li a"; // CSS Selector/s for element/s you want to apply fade effect to.
var hoverOverSpeed = "500"; // Hover over fade speed (in milliseconds)
var hoverOutSpeed = "300"; // Hover out fade speed (in milliseconds)

// Start JQuery

$(document).ready(function () {

    // Background Opacity Plugin by Nick Obrien (http://www.nickobrien.nl)

    (function ($) {
        jQuery.fn.backOpacity = function (settings) {
            // Default and argument settings
            settings = jQuery.extend({ background: '#000000', opacity: 0.5 }, settings);

            // Loop through each element given and add an opacity element
            jQuery(this).each(function (intIndex) {
                // For fixing background element's positions/sizes these variables are needed
                var pt = parseInt($(this).css('paddingTop'));
                var pb = parseInt($(this).css('paddingBottom'));
                var pl = parseInt($(this).css('paddingLeft'));
                var pr = parseInt($(this).css('paddingRight'));
                var fixedleft = parseInt($(this).css('marginLeft'));
                var fixedright = parseInt($(this).css('marginRight'));

                // Element offset width
                var parentow = $(this).width();

                // Fixed variables
                var fixedwidth, fixedheight, fixedleft, fixedright = 0;

                // Calculate fixing positions/sizes
                fixedwidth = parentow + pl + pr;
                fixedheight = $(this).height() + pt + pb;

                // Add background element
                $(document.createElement('div')).width(fixedwidth).height(fixedheight).css({ backgroundColor: settings.background, opacity: settings.opacity, position: 'relative', marginLeft: fixedleft + 'px', marginRight: fixedright + 'px', left: 0, top: 0, bottom: 0, zIndex: ((10) + intIndex * 10) }).insertAfter($(this));

                // Set positions for the content element
                $(this).css({ width: parentow, position: 'absolute', zIndex: ((20) + intIndex * 20) });
            });

            // Return
            return jQuery;
        };
    })(jQuery);


    // Animate Fade Effects

    $(selector).css({ background: 'none' }); //removes default CSS :hover effect

    $(selector).backOpacity({ background: 'transparent', opacity: '1' }); // Initiate default background opacity

    $(selector).hover(

		function () {
		    $(this).siblings('div').stop().animate({ 'opacity': 0 }, hoverOverSpeed); //fade out on hover
		},

		function () {
		    $(this).siblings('div').stop().animate({ 'opacity': 1 }, hoverOutSpeed); //fade in on mouseout

		});

}); //end

//

$(document).ready(function() {
    //Seta contador (ano, mês, dia, hora, minuto, segundo)
    setcountdown(2011, 11, 11, 23, 59, 00);
    
    var url = decodeURIComponent(window.location.pathname);
    url = url.substring(url.lastIndexOf("/"));
    url = url.replace("/", "");

    //alert(url);
    if (url != "") {
        $("ul li a[href$='" + url + "']").parent().addClass("itemAtivo");
        $(".breadCrumb a[href$='" + url + "']").css("font-weight", "bold");
        $("#nav li a[href$='" + url + "']").siblings("div").css("background", "none");
        $("#nav li a[href$='" + url + "']").parent().parent().parent().children("div").css("background", "none");
        
        //Contador
        if (url == "Home.aspx" || url == "Default.aspx") {
            start_countdown();
        }
    }
    else {
        //Contador 
        start_countdown();
    }
});


$(document).ready(function() {
    $('.menuInterna li').mouseover(function() {
        $(this).addClass("itemAtivo2");
    });
    $('.menuInterna li').mouseout(function() {
        $(this).removeClass("itemAtivo2");
    });
});

// voltar
$(document).ready(function () {
	//$('.btnVoltar').attr({
    //    href: "#"
	//});
	
	qtdFotos = -1;    
	
	if( $('.slideImg').length>0){
		qtdFotos = -1 * ($('.slideImg').length + 1);
	}

	if($.browser.msie == true){
		 
		// $('.btnVoltar').click(function () {
			//alert('VAI '+qtdFotos)
		//	history.go(qtdFotos);
		// });
		 $('.btnVoltar').attr({
    	   href: "javascript:history.go("+qtdFotos+")"
   	 	 });		
	}
	else
	{
		//$('.btnVoltar').click(function () {
		//	history.go(-1);
		// });
		$('.btnVoltar').attr({
    	    href: "javascript:history.go(-1)"
   	 	});
	}
		
});

//Access keys

$(document).ready(function () {
    $('#dnn_dnnSEARCH_txtSearch').attr({
        accesskey: "0"
    });
    $("a[href$=Acessibilidade.aspx]:first").attr({
        accesskey: "2"
    });
    $("a[href$=Default.aspx]:first").attr({
        accesskey: "1"
    });
    $("a[href$=#menu]:first").attr({
        accesskey: "3"
    });
    $("a[href$=#conteudo]:first").attr({
        accesskey: "4"
    });
    $("a[href$=#rodape]:first").attr({
        accesskey: "9"
    })
	
});


$(document).ready(function() {
    $("a[rel^='prettyPhoto']").prettyPhoto({
        animation_speed: 'normal', /* fast/slow/normal */
        padding: 0, /* padding for each side of the picture */
        opacity: 0.60, /* Value betwee 0 and 1 */
        show_title: false, /* true/false */
        allow_resize: false, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
        hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
        modal: true
    });
});

/* Campo máscaras */
function maskField(o, f) {
    //alert("este");
    v_obj=o
    v_fun=f
    setTimeout("execMask()",1)
}

/*Função que Executa os objetos*/
function execMask(){
    v_obj.value=v_fun(v_obj.value)
}

function maskTelefone(v) {
    v = v.replace(/\D/g, "")
    v = v.replace(/^(\d\d)(\d)/g, "($1) $2")
    v = v.replace(/(\d{4})(\d)/, "$1-$2")
    return v
}


