// JavaScript Document

   


function callbackShoppingCart( cart ) {
	
	$(".numItens").html(cart.totalItems)
	$(".totalInCart").html(cart.totalPrice)
}

$(document).ready(function() {
	
		
	
		$("#slides").slidesjs({
			width: 481,
			height: 150,
			pagination:false,
			navigation:false
		  });
		
		$('.bxslider').bxSlider({
			  pager:false,
			  auto:true,
			  minSlides: 8,
			  maxSlides: 8,
			  slideWidth: 100,
			  slideMargin: 20
		});
		
		$('.slider8').bxSlider({
			mode: 'vertical',
			slideWidth: 481,
			auto:true,
			minSlides: 3,
			maxSlides: 3,
		  });
		
		$('.bxsliderNoticias').bxSlider({
			  pager:false,
			  auto:true,
			  minSlides: 1,
			  maxSlides: 1,
			  slideWidth: 100,
			  slideMargin: 20
		});
		
		var  slider2 =  $('.bxslider2').bxSlider({
			  pager:false,
			  auto:true,
			  controls:false,
			  minSlides: 1,
			  maxSlides: 1,
			  slideWidth: 558,
			  slideMargin: 20
		});
		
		$("#nextCuriosity").click(function() {
			slider2.stopAuto();
			slider2.goToNextSlide();
		});
		
		$("#prevCuriosity").click(function() {
			slider2.stopAuto();
			slider2.goToPrevSlide();
		});

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

		$(".containerFotos").wtRotator({
							width: $(".wt-rotator").attr("width"),
							height:$(".wt-rotator").attr("height"),
							thumb_width:24,
							thumb_height:24,
							button_width:24,
							button_height:24,
							button_margin:5,
							auto_start:true,
							delay:5000,
							play_once:false,
							transition:$(".wt-rotator").attr("effect"),
							transition_speed:500,
							auto_center:true,
							easing:"",
							cpanel_position:"inside",
							cpanel_align:"BC",
							timer_align:"top",
							display_thumbs:true,
							display_dbuttons:false,
							display_playbutton:false,
							display_thumbimg:false,
							display_side_buttons:false,
							display_numbers:true,
							display_timer:false,
							mouseover_select:false,
							mouseover_pause:false,
							cpanel_mouseover:false,
							text_mouseover:false,
							text_effect:"fade",
							text_sync:true,
							tooltip_type:"",
							shuffle:false,
							block_size:70,
							vert_size:55,
							horz_size:50,
							block_delay:25,
							vstripe_delay:75,
							hstripe_delay:180,
							mousewheel_scroll:false			
		});  
		
		
		
		// BEGIN: 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: FORM METATAGS HANDLER
	});	
	
	
	$(".mainCat a").click( function(e) {
		e.preventDefault();
		$("div.mainCatSub").slideUp();
		$("div.mainCat a").removeClass("selected");
		
		if ($(this).parent().children(".mainCatSub").length > 0) {
				$(this).parent().children("a").addClass("selected");

				$(this).parent().children(".mainCatSub").slideDown()
			
		}
		else {
			location.href = $(this).attr("href");
		}
		
	});
	
	// MARK CURRENT MENU AS SELECTED
	// mark side categories on menu
	$(".leftBanners a[href='"+window.location.pathname+"']").addClass("selected");
	$(".leftBanners a[href='"+window.location.pathname+"']").parent().parent().slideDown();
	$(".leftBanners a[href='"+window.location.pathname+"']").parent().parent().parent().children("a").addClass("selected");
	
	var dummyHtmlFirstTime = false;
	var dummyHtml;
	
	$("#map area").click(function(e) {
		e.preventDefault();
		var idToLoad = $(this).attr("href");
		
		if (dummyHtmlFirstTime==false) {
			dummyHtml = $(".prod_detalhe_descricao").html();
			dummyHtmlFirstTime = true;
		}
		$(".prod_detalhe_descricao").fadeOut("fast", function() {
			$.get('/assets/html/' + idToLoad, function(data) {
				$(".prod_detalhe_descricao").html(data + "<br><br><input id='backToPreviews' type='button' style='float:left' value='Voltar à descrição geral'>");
				$(".prod_detalhe_descricao").fadeIn()
			});
		});
		
		$("#backToPreviews").live("click", function(e) {
			e.preventDefault();
			$(".prod_detalhe_descricao").fadeOut("fast", function() {
				$(".prod_detalhe_descricao").html(dummyHtml);
				$(".prod_detalhe_descricao").fadeIn()	
			});
		})
		
		
	})
	
	
	$("#mapaportugal area , .distritosportugal ul a").hover(
		 
		  function () {
		    var classname = $(this).attr("href").replace("#","");
		    $(".distritosportugal ul a[href='#"+classname+"']").addClass("selected");
		    $("#mapaportugal").append("<div id='imagemaphover' class='"+classname+"'></div>");
		  },
		  function () {
		   var classname = $(this).attr("href").replace("#","");
		   $(".distritosportugal ul a[href='#"+classname+"']").removeClass("selected");
		   $("#imagemaphover").remove();
		  }
    )
	
	$("#mapaportugal area , .distritosportugal ul a").click( function(e) {
		e.preventDefault();
		$(".establecimentos").html("<img src='assets/images/indicator.gif'>");
		
		var classname = $(this).attr("href");
		var title = $(this).html()

		$.ajax({
				type:"POST",
				url:"/get_stores.php",
				data: "distrito="+ classname,
				dataType:"html",
				success: function(html) {
				    $(".titleEstablecimentos h1.title").html("Establecimentos em " + title);
					$(".establecimentos").html(html);

					
				},
				error: function(xmlRequest, errorCode) {
				}
				
			})

		
		
	})

	 
});