

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() {

	//////////////////////////////
    // 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:'bottomLeft',
			cpanelOutside:true,
			responsive:true,
			imagePosition:"fill",
			height:600
	});


    //////////////////////////////
    // 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'>");
							form.submit();
						})
						
						
						return;
					}
					else {
						$(form).children().find("input[id='humanValidator']").focus()
						return false;
					}
				
			  }
		});
	});
	// END: OMW FORM METATAGS HANDLER
	
	function changeHeader() {
		// var scrollPos = $(window).scrollTop();

		// var opacidade = ((scrollPos / 48 ) * .3 )+ 0.7;

		// if (scrollPos > 21) {
		// 	$(".preheader").css("position","absolute").css("top",( $(".menuHolder").offset().top - $(".preheader").height()  ) + "px");
		// 	$(".menuHolder").css("background-color","rgba(16,52,84,"+opacidade+")");
		// }
		// else {
		// 	$(".preheader").css({"position":"fixed","top":"0"});
		// 	$(".menuHolder").css("background-color","rgba(16,52,84,"+opacidade+")");
		// }

		// if (scrollPos > 48) {
		// 	 $(".menuHolder").style("position","fixed","important").css("top","0");
		// }
		// else if (scrollPos < 48) {
		// 	 $(".social_icons2").fadeOut();
		// 	 $(".menuHolder").style("position","absolute","important").css("top","48px");
		// }


		// if (scrollPos>48) {
		// 	$(".social_icons2").fadeIn()
		// }
		// else {
		// }

	}

	$(window).on("scroll", function(e){
		// if($("#st-container").hasClass("st-menu-open")){
		// 	$(".st-effect-7.st-menu").css("transform","translate(-100%, "+$(window).scrollTop()+"px)");
		// 	$(".st-effect-7.st-menu").css("transition","none");
		// 	$(".responsive-bar").css("transform","translate(0, "+$(window).scrollTop()+"px)");
		// }else{
		// 	if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1){}else{
		// 		$(".st-effect-7.st-menu").css("transform","translate(-100%, "+$(window).scrollTop()+"px)");
		// 		$(".st-effect-7.st-menu").css("transition","none");
		// 		$(".responsive-bar").css("transform","translate(0, "+$(window).scrollTop()+"px)");
		// 		$(".st-effect-7.st-menu").css("transition","all 0.5s ease 0s");
		// 		$("#idHeader").css("transform","translate(0, "+$(window).scrollTop()+"px)");
		// 	}
		// }

		if($("#idHeader").hasClass("menuHolder")){
			changeHeader();
		}
	})
	if($("#idHeader").hasClass("menuHolder")){
		changeHeader();
	}

	$(".social_box").on("click", function() {
		$(".social_box_options").toggle("fade");
	})

	$(".social_box_options").bind( "clickoutside", function(event){
	
		if ( $(event.target).attr("class") != "social_box") $(this).stop().fadeOut();
	});

	$(".searchBox").on("click", function() {
		$(".pesqBox").toggle("fade");
	})

	$(".pesqBox").bind( "clickoutside", function(event){
		//$(".pesqBox").css("display","none");
		if ( $(event.target).attr("class") != "searchBox") $(this).stop().fadeOut();
		//$(this).stop().fadeOut();
	});

	
	
	//////////////////////////////
    // CUSTOM
	//////////////////////////////
    //$(".leftColumn").equalHeights($(".maincontent").height() - 300); 
    
    $(".partilhaMain_voltar").on("click", function() {
    	window.history.back();
    });

    $("#bannerhomeslide").height($(".br-wrapper").height());
	$("#bannerhomeslide").css("background","url('"+$("#bannerhomeslideDummy img").attr("src")+"') no-repeat scroll  center center / cover")
    $("#bannerhomeslide2").height($(".br-wrapper").height());
	$("#bannerhomeslide2").css("background","url('"+$("#bannerhomeslideDummy2 img").attr("src")+"') no-repeat scroll  center center / cover")
    
    $( window ).resize(function() {
		$("#bannerhomeslide").height($(".br-wrapper").height());
		$("#bannerhomeslide2").height($(".br-wrapper").height());
	})
    
    //$(".item-news").
    //window.scrollTo(0, 300);
    var getUrlParameter = function getUrlParameter(sParam) {
	    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
	        sURLVariables = sPageURL.split('&'),
	        sParameterName,
	        i;

	    for (i = 0; i < sURLVariables.length; i++) {
	        sParameterName = sURLVariables[i].split('=');

	        if (sParameterName[0] === sParam) {
	            return sParameterName[1] === undefined ? true : sParameterName[1];
	        }
	    }
	};
	if(getUrlParameter('tipo')=="click"){
	    if($(window).width() <= 480){
	    	//console.log($(".galeria-main-detail div").hasClass("item-news"));
	    	if($(".galeria-main-detail div").hasClass("item-news") == true){
	    		var valorTopo = $(".galeria-main-detail .item-news").offset().top;
	    		//$('body').scrollTo({left:0, top:valorTopo}, 800, {easing:'swing'});
	    		//window.scrollTo( {top:'30%', left:'0px'}, 800, {easing:'swing'} );
	    		$('html, body').stop().animate({scrollTop: valorTopo}, 1000);
	    	}

	    }
	}
    //console.log($( window ).hasClass("item-news"));

    //tem que ser feito tudo antes desta linha por causa de um erro firebug
    try{
    	$("#owl-example").owlCarousel();
	}catch(err){}
    
    function shuffle(array) {
	    var i = array.length,
	        j = 0,
	        temp;

	    while (i--) {

	        j = Math.floor(Math.random() * (i+1));

	        // swap randomly chosen element with current element
	        temp = array[i];
	        array[i] = array[j];
	        array[j] = temp;

	    }

	    return array;
	}
    	
	try{
		var userid = "2236719284";
		var token = "2236719284.1677ed0.9118d1e8dac64a5f940400799603d6fd";
		var num_photos = 20;
	    $.ajax({
            type:"GET",
            //url:"https://api.instagram.com/v1/users/1680774924/media/recent/?access_token=1680774924.1677ed0.b1d5c0b11b6e4397bf8dae370c17d5c1",
			url: 'https://api.instagram.com/v1/users/'+userid+'/media/recent', // or /users/self/media/recent for Sandbox
			dataType: 'jsonp',
			type: 'GET',
			data: {access_token: token, count: num_photos},
			//url: 'https://api.instagram.com/v1/users/search',
			// dataType: 'jsonp',
			// data: {access_token: "1680774924.1677ed0.b1d5c0b11b6e4397bf8dae370c17d5c1", q: "nortemoda"},
            success: function(html) {
				console.log(html)
				var ranNums = shuffle([0,1,2,3,4,5,6,7,8]);
				for(var i=0;i<ranNums.length;i++){
					var imgSrc = html.data[ranNums[i]].images.standard_resolution.url;
					$("[rel='"+(i+1)+"']").css("background","url('"+imgSrc+"')");
					$("[rel='"+(i+1)+"']").attr("title",html.data[ranNums[i]].caption.text);
					//link para imagens
					$("[rel='"+(i+1)+"']").parent().attr("href",html.data[ranNums[i]].link);
				}
			 },
	         error: function(xmlRequest, errorCode) {
	         	console.log("erro instagram feed")
			}
    	})
	}catch(err){}

	// $(".st-container").addClass("st-effect-7");
	// $(".st-effect-7.st-menu").css("transform","translate(-100%, "+$(window).scrollTop()+"px)");
	// $(".responsive-bar").css("transform","translate(0, "+$(window).scrollTop()+"px)");
	// $(".st-effect-7.st-menu").css("transition","all 0.5s ease 0s");
	// $("#idHeader").css("transform","translate(0, "+$(window).scrollTop()+"px)");

	// $(".nav-responsive > ul").css("height",($(window).height()-$(".st-menu h2").outerHeight())+"px");
	// $(".nav-responsive > ul").css("overflow-y","auto");

});	


