omw_override_selectBoxIt = true;
function callbackShoppingCart( cart ) {

	if ($(".numItens").length > 0) $(".numItens").html(cart.totalItems)
	if ($(".totalInCart").length > 0) $(".totalInCart").html(cart.totalPrice)
	
	
	
	// resume cart
	if ($("#omw_resume_cart").length > 0) {
		var cartUrl = cart.options.url;
		var cartTrad = cart.options.trad;
		
		var html ='<ol id="mini-cart-list" class="mini-products-list">';
		$.each(cart.items, function() {
			
			html +='<li class="item odd">';
			html +='<a class="product-image" title="'+(this.descricao)+'" href="'+this.url+'">';
			html +='<img width="50" height="50" alt="'+(this.descricao)+'" src="'+this.imagem+'"></a>';
			html +='</a>';
			html +='<div class="product-details">'
			
			html +='<p class="product-name">';
			html +='<a href="'+this.url+'">'+(this.descricao)+'</a>'
			html +='</p><strong>'+this.qtd+'</strong>x<span class="price">'+this.valor+'</span>'
			
			
			html +='</div>';
			html +='</li>';
			
		});
		html +="</ol>";
		
		html +='<div class="actions">'
		html +='<button class="button btn-inline" onclick="location.href=\'/'+cartUrl+'\'" title="'+cartTrad+'" type="button"><span>'
		html +='<span>'+cartTrad+'</span>'
		html +='</span></button></div>'
		
		$("#omw_resume_cart").html(html);
	}	
	
}

(function($) {    
  if ($.fn.style) {
    return;
  }

  // Escape regex chars with \
  var escape = function(text) {
    return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  };

  // For those who need them (< IE 9), add support for CSS functions
  var isStyleFuncSupported = !!CSSStyleDeclaration.prototype.getPropertyValue;
  if (!isStyleFuncSupported) {
    CSSStyleDeclaration.prototype.getPropertyValue = function(a) {
      return this.getAttribute(a);
    };
    CSSStyleDeclaration.prototype.setProperty = function(styleName, value, priority) {
      this.setAttribute(styleName, value);
      var priority = typeof priority != 'undefined' ? priority : '';
      if (priority != '') {
        // Add priority manually
        var rule = new RegExp(escape(styleName) + '\\s*:\\s*' + escape(value) +
            '(\\s*;)?', 'gmi');
        this.cssText =
            this.cssText.replace(rule, styleName + ': ' + value + ' !' + priority + ';');
      }
    };
    CSSStyleDeclaration.prototype.removeProperty = function(a) {
      return this.removeAttribute(a);
    };
    CSSStyleDeclaration.prototype.getPropertyPriority = function(styleName) {
      var rule = new RegExp(escape(styleName) + '\\s*:\\s*[^\\s]*\\s*!important(\\s*;)?',
          'gmi');
      return rule.test(this.cssText) ? 'important' : '';
    }
  }

  // The style function
  $.fn.style = function(styleName, value, priority) {
    // DOM node
    var node = this.get(0);
    // Ensure we have a DOM node
    if (typeof node == 'undefined') {
      return this;
    }
    // CSSStyleDeclaration
    var style = this.get(0).style;
    // Getter/Setter
    if (typeof styleName != 'undefined') {
      if (typeof value != 'undefined') {
        // Set style property
        priority = typeof priority != 'undefined' ? priority : '';
        style.setProperty(styleName, value, priority);
        return this;
      } else {
        // Get style property
        return style.getPropertyValue(styleName);
      }
    } else {
      // Get CSSStyleDeclaration
      return style;
    }
  };
})(jQuery);


$(document).ready(function() {



	// $("#popup_warning").on("click", function(){
	// 	$("#popup_warning").remove()
	// })


	//////////////////////////////
    // CURRENCIES
    //////////////////////////////
    if ($("#omw-moneyManager").length>0) {
		$("#omw-moneyManager").click(function() {
			$("#omw-moneyPanel").toggle();
		} );
		$("#omw-moneyPanel").bind( "clickoutside", function(event){
				var target = $(event.target).attr("id") || "body";
				if (target != "omw-moneyManager" && target!="selectedMoney") $("#omw-moneyPanel").fadeOut("fast");
		});
	}

	//////////////////////////////
    // ZOOM IMAGE GALERIES
    //////////////////////////////
    $("a[rel^='prettyPhoto']").prettyPhoto({autoplay_slideshow: false, overlay_gallery: false, social_tools:false, deeplinking: false, theme:'pp_default', slideshow:5000});


    //////////////////////////////
    // BANNER ROTATOR
	//////////////////////////////
	$('.banner-rotator').bannerRotator({
			effect:'fade',
			navButtons:'large',
			thumbnails:'bullet',
			playButton:false,
			timer:'none',
			tooltip:'none',
			cpanelAlign:'center',
			responsive:'true',
			height:500,
			width:1600

	});


    //////////////////////////////
    // BEGIN: OMW FORM METATAGS HANDLER
	//////////////////////////////
    $.validator.messages.required = "";
	$.validator.messages.number = "";
	$.validator.messages.email = "";
	$.validator.messages.remote = "";
	$.validator.messages.equalTo = "";
	
	$("form.omw_form").each(function() {
		
		 $(this).validate({
			  errorClass:"errorValidation",
			  errorElement:"span",
			  focusInvalid: true,
			  highlight: function(element, errorClass, validClass) {
					$(element).addClass("errorClass");	 
			  },
			  unhighlight: function(element, errorClass, validClass) {
					$(element).removeClass("errorClass");
			  },
			  
			  submitHandler: function(form) { 
					var humanValidator= $(form).children().find("input[id='humanValidator']").attr("rel").split(",");
					var value1 = parseInt(humanValidator[0]);
					var value2 = parseInt(humanValidator[1]);
					var response = parseInt($(form).children().find("input[id='humanValidator']").val());
					
					if ( value1 + value2 == response ) {
						$(form).find("input.submitbtn").fadeOut("fast", function() {
							$(form).append("<img src='http://www.omeuwebsite.com/images/indicator.gif'>");
							

							var url = location.href.split("https://").join("").split("http://").join("");

								$.ajax({
											type: "POST",
											url: "/formupdate.php",
											data: "url=" +  Base64.encode(url),
											dataType:"json",
											success: function(msg){
												form.submit();
											},
											error: function(XMLHttpObj, erroCode) {
											  
											}
										 });


						})
						
						
						return;
					}
					else {
						$(form).children().find("input[id='humanValidator']").focus()
						return false;
					}
				
			  }
		});
	});
	// END: OMW FORM METATAGS HANDLER
	
	// BEGIN: OMW BRANDS HANDLER
	if ($("#omw-brands-slider").length  > 0) {
		var logoSlider = $('#omw-brands-slider').bxSlider({
				  pager:true,
				  controls:false,
				  auto:true,
				  minSlides: 4,
				  maxSlides: 4,
				  autoStart:true
		});
	}

	/*try{
		$('.owl-carousel').owlCarousel({
	    loop:true,
	    margin:10,
	    nav:false,
	    responsive:{
	        0:{
	            items:1
	        },
	        600:{
	            items:3
	        },
	        1000:{
	            items:4
	        }
	    }
	})
	}
	catch(err){}

	try{
		$('.owl-carousel2').owlCarousel({
	    loop:true,
	    margin:10,
	    nav:false,
 		autoplay:true,
   		autoplayTimeout:1000,
   		autoplaySpeed:2000,
   		dots:false,
   		autoplayHoverPause:true,
	    responsive:{
	        0:{
	            items:1
	        },
	        600:{
	            items:3
	        },
	        1000:{
	            items:4
	        }
	    }
	})
	}
	catch(err){}*/


	try{
		$('.banner_destaque_zone ul').owlCarousel({
	    loop:true,
	    margin:10,
	    nav:false,
	    responsive:{
	        0:{
	            items:1
	        },
	        600:{
	            items:1
	        },
	        1000:{
	            items:1
	        }
	    }
	})
	}
	catch(err){}


	isChanged=false;
	function changeHeader() {
		//if ( $(window).width() < 480 ) return true;
		var scrollPos = $(window).scrollTop();
		var windowWidth = $( window ).width();


		if (windowWidth<1010) {
			/*console.log("nao fixou --> "+windowWidth)
			$(".menuContainer").css("position","static");
			$("#main").css("margin-top","0px")
			$("nav").css("border-bottom","0px solid #fff")
			return;*/
		}

		if (windowWidth>1024) {
			if ( (scrollPos > 96) && (isChanged == false ) )   {
				console.log("fixou --> "+windowWidth)
				 isChanged = true;
				 $(".logoContainerScroll").show();
				 $(".logoContainerScroll div.fader").stop().stop().fadeIn();
				// $(".menuContainer").css("position","fixed").css("top","0px").css({"z-index":"9999999","width":"100%"});
				  $("nav").css({"position":"fixed","top":"0px","left":"0px"});
				 $("#main").css("margin-top","35px");
				$("nav").css("border-bottom","1px solid #fff")
				/* $(".menuContainer ul.mlddm").stop().stop().animate({width: "90%"}, 500).css("float","right")
				 $(".menuContainer ul.mlddm a").stop().stop().animate({fontSize: ".6em"}, 500)*/
			}
			else if ( (scrollPos < 96) && (isChanged == true ) )   {
				console.log("nao fixou --> "+windowWidth)
				 isChanged = false;	
				  $(".logoContainerScroll").hide();
				  $(".logoContainerScroll div.fader").hide();
				 $(".menuContainer").css("position","static");
				 $("nav").css("position","static");
				 $("#main").css("margin-top","0px")
				$("nav").css("border-bottom","0px solid #fff")
				 /*$(".menuContainer ul.mlddm").stop().stop().animate({width: "100%"}, 500)
				 $(".menuContainer ul.mlddm a").stop().stop().animate({fontSize: ".85em"}, 500)*/


			}
		}
	

	}

	$(window).on("scroll", function(e){
		changeHeader();
		var scrollTop = $(window).scrollTop();
		if ( scrollTop > Math.ceil($(window).height() / 2 ) ){
			$("#backToTop").fadeIn();
		}
		else {
			$("#backToTop").fadeOut();
		}

	})
	changeHeader();

	// END: OMW BRANDS HANDLER
	
	
	//////////////////////////////
    // CUSTOM
	//////////////////////////////
    //$(".leftColumn").equalHeights($(".maincontent").height() - 300); 
  
	 $('ul.mlddm > li > ul > li > ul').parent().children("a").addClass("hsub")
	 $('ul.mlddm > li > ul > li > ul > li > ul').parent().children("a").addClass("hsub")
	 
	 // MARCA O MENU PRINCIPAL COM CURRENT
	 $('ul.mlddm .current').parent().parent().parent().children("a").addClass("current")
	 //$('ul.mlddm .current').parent().parent().parent().parent().parent().children("a").addClass("current")
	 
	 
	 $("#backToTop").on("click", function() {
		TweenLite.to(window, .8, {scrollTo:{y:0}, ease:Power2.easeOut});

	})

    try{
		//PRODUTOS SLIDE
		var owlDestaque = $("#owl-produtos");
		owlDestaque.owlCarousel({
			items : 4, //6 items above 1000px browser width
			itemsDesktop : [1000,3], //5 items between 1000px and 901px
			itemsDesktopSmall : [900,2], // betweem 900px and 601px
			itemsTablet: [600,1], //2 items between 600 and 0
			pagination:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		// Custom Navigation Events
		$(".nextProd").click(function(){
			owlDestaque.trigger('owl.next');
		})
		$(".prevProd").click(function(){
			owlDestaque.trigger('owl.prev');
		})
		$(".play").click(function(){
			owlDestaque.trigger('owl.play',3000); //owl.play event accept autoPlay speed as second parameter
		})
		$(".stop").click(function(){
			owlDestaque.trigger('owl.stop');
		})
	}
	catch(err){}

	try{
		//NOTICIAS SLIDE
		var owlNoticias = $("#owl-noticias");
		owlNoticias.owlCarousel({
			items : 3, //6 items above 1000px browser width
			itemsDesktop : [1024,2], //5 items between 1000px and 901px
			itemsDesktopSmall : [900,2], // betweem 900px and 601px
			itemsTablet: [768,1], //2 items between 600 and 0
			pagination:false,
			afterInit: function (elem) {
				var alt = elem.find(".noticiaItem")
				for(var i=0; i<alt.length; i++){
					if(i==1){
						alt.eq(i).addClass("noticiaPrincipal");
					}
				}
			},
			afterMove: function (elem) {
				var current = this.currentItem;
				var alt = elem.find(".noticiaItem")
				for(var i=0; i<alt.length; i++){
					alt.eq(i).removeClass("noticiaPrincipal");
				}
				elem.find(".noticiaItem").eq(Number(current+1)).addClass("noticiaPrincipal");
			},
			navigation:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		owlNoticias.trigger('owl.play',3000);
	}
	catch(err){}

	try{
		//REFERENCIAS SLIDE
		var owlReferencias = $("#owl-referencias");
		owlReferencias.owlCarousel({
			items : 3, //6 items above 1000px browser width
			itemsDesktop : [1024,2], //5 items between 1000px and 901px
			itemsDesktopSmall : [900,2], // betweem 900px and 601px
			itemsTablet: [768,1], //2 items between 600 and 0
			pagination:false,
			navigation:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
	}
	catch(err){}

	try{
		//PARCEIROS SLIDE
		var owlParceiros = $("#owl-parceiros");
		owlParceiros.owlCarousel({
			items : 6, //6 items above 1000px browser width
			itemsDesktop : [1024,4], //5 items between 1000px and 901px
			itemsDesktopSmall : [900,3], // betweem 900px and 601px
			itemsTablet: [768,1], //2 items between 600 and 0
			pagination:false,
			navigation:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		owlParceiros.trigger('owl.play',3000);
	}
	catch(err){}

	try{
		$(".referenciaTitulo").height($(".referenciaBase").height());
		$(window).on("resize", function(e){
			$(".referenciaTitulo").height($(".referenciaBase").height());
		});
	}
	catch(err){}

	try{
		//PRODUTOS RELACIONADOS
		var objRel = $("#owl-detalhe");
		objRel.owlCarousel({
			items : 4, //6 items above 1000px browser width
			itemsDesktop : [1000,3], //5 items between 1000px and 901px
			itemsDesktopSmall : [900,2], // betweem 900px and 601px
			itemsTablet: [600,1], //2 items between 600 and 0
			pagination:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		// Custom Navigation Events
		$(".nextProd").click(function(){
			objRel.trigger('owl.next');
		})
		$(".prevProd").click(function(){
			objRel.trigger('owl.prev');
		})
		$(".play").click(function(){
			objRel.trigger('owl.play',3000); //owl.play event accept autoPlay speed as second parameter
		})
		$(".stop").click(function(){
			objRel.trigger('owl.stop');
		})
	}
	catch(err){console.log(err)}

	try{
		//PRODUTOS RELACIONADOS
		var objRelMain = $(".imgsDetalheProd");
		objRelMain.owlCarousel({
			items : 1, //6 items above 1000px browser width
			itemsDesktop : [1000,1], //5 items between 1000px and 901px
			itemsDesktopSmall : [900,1], // betweem 900px and 601px
			itemsTablet: [600,1], //2 items between 600 and 0
			pagination:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		var objXXX = $(".imgsDetalheProd").data('owlCarousel');
		// Custom Navigation Events
		$(".nextProd").click(function(){
			objRelMain.trigger('owl.next');
		})
		$(".prevProd").click(function(){
			objRelMain.trigger('owl.prev');
		})
		$(".play").click(function(){
			objRelMain.trigger('owl.play',3000); //owl.play event accept autoPlay speed as second parameter
		})
		$(".stop").click(function(){
			objRelMain.trigger('owl.stop');
		})
		$(".extraThumbImage2").click(function(){
			var indexImagem = $(this).attr("rel");
			objXXX.goTo(indexImagem);
		})
	}
	catch(err){console.log(err)}

	try{
		
		$( ".omw-banner-description" ).each(function( i ) {
			var alturaConteudo = $(this).height();
			var alturaSlider = $(".banner-rotator-container").height();
			$(this).css("top",( Number(alturaSlider/2) - Number( alturaConteudo / 2 ) )+"px");
		})
		$(window).on("resize", function(e){
			$( ".omw-banner-description" ).each(function( i ) {
				var alturaConteudo = $(this).height();
				var alturaSlider = $(".banner-rotator-container").height();
				$(this).css("top",( Number(alturaSlider/2) - Number( alturaConteudo / 2 ) )+"px");
			})
		});
	}
	catch(err){console.log(err)}

	//SITE NOVO

	try{
		$(".home_tabs .tab").on("click", function() {
			$( ".home_tabs .tab" ).each(function( i ) {
				$(this).removeClass("tabActive");
			});
			$(this).addClass("tabActive");

			var tabClicada = $(this).attr("rel");
			$( ".tabContainer" ).each(function( i ) {
				$(this).removeClass("tabContainerActive");
			});	
			if(tabClicada=="tab1"){
				$(".tab1").addClass("tabContainerActive");	
			}else if(tabClicada=="tab2"){
				$(".tab2").addClass("tabContainerActive");	
			}else if(tabClicada=="tab3"){
				$(".tab3").addClass("tabContainerActive");	
			}	
		});
	}catch(err){console.log(err)}

	try{
		//NOTICIAS SLIDE NOVO
		var owlNoticiasNew = $(".tabDetailBoxNoticias");
		owlNoticiasNew.owlCarousel({
			items : 1, //6 items above 1000px browser width
			itemsDesktop : [1024,1], //5 items between 1000px and 901px
			itemsDesktopSmall : [768,2], // betweem 900px and 601px
			itemsTablet: [480,1], //2 items between 600 and 0
			pagination:false,
			navigation:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		//owlNoticiasNew.trigger('owl.play',3000);
		$(".nextNoticiaNew").click(function(){
			owlNoticiasNew.trigger('owl.next');
		})
		$(".prevNoticiaNew").click(function(){
			owlNoticiasNew.trigger('owl.prev');
		})
	}
	catch(err){}

	try{
		//DESTAQUES SLIDE NOVO
		var tabDetailBoxProdutos = $(".tabDetailBoxProdutos");
		tabDetailBoxProdutos.owlCarousel({
			items : 1, //6 items above 1000px browser width
			itemsDesktop : [1024,1], //5 items between 1000px and 901px
			itemsDesktopSmall : [768,2], // betweem 900px and 601px
			itemsTablet: [480,1], //2 items between 600 and 0
			pagination:false,
			navigation:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		//tabDetailBoxProdutos.trigger('owl.play',3000);
		$(".nextProdutoNew").click(function(){
			tabDetailBoxProdutos.trigger('owl.next');
		})
		$(".prevProdutoNew").click(function(){
			tabDetailBoxProdutos.trigger('owl.prev');
		})
	}
	catch(err){}

	try{
		//REFERENCIAS SLIDE NOVO
		var tabDetailBoxReferencias = $(".tabDetailBoxReferencias");
		tabDetailBoxReferencias.owlCarousel({
			items : 1, //6 items above 1000px browser width
			itemsDesktop : [1024,1], //5 items between 1000px and 901px
			itemsDesktopSmall : [768,2], // betweem 900px and 601px
			itemsTablet: [480,1], //2 items between 600 and 0
			pagination:false,
			navigation:false,
			itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
		});
		//tabDetailBoxReferencias.trigger('owl.play',3000);
		$(".nextReferenciaNew").click(function(){
			tabDetailBoxReferencias.trigger('owl.next');
		})
		$(".prevReferenciaNew").click(function(){
			tabDetailBoxReferencias.trigger('owl.prev');
		})
	}
	catch(err){}
    
	try{
		$(".secondLevel").mouseover(function() {
			$(this).parent().find(".firstLevelLink").addClass("megaMenuCustomHover");
		});
		$(".secondLevel").mouseout(function() {
			$(this).parent().find(".firstLevelLink").removeClass("megaMenuCustomHover");
		});

		$(".megamenuBox .secondLevel > div > a").on("click",function(event){
			event.preventDefault();
			$(".megamenuBox .secondLevel > div > a").attr("style", "color: #a6a6a6;background-color: transparent;");
			$(this).attr("style", "color: #4ba13c;background-color: #eee; ");
			var relLink = $(this).attr("rel");
			$(".ctrConteudosMegamenu").each(function() {
				var relConteudo = $(this).attr("rel");
				if(relLink==relConteudo){
					$(".secondLevel").find(".controloBannerMegamenu").css("display","block");
					$(this).closest(".secondLevel").find(".controloBannerMegamenu").css("display","none");
					$(this).css("display","block");
				}
				else{
					$(this).css("display","none");	
				}
			});
		});
	}catch(err){}

});	

