
	// addthis fix in order to disable its flash-based analytics cookie
	var addthis_config = {
	  data_use_flash: false
	}
		
	$(document).ready(function(){
		
	// categoria tabs
	
		$('#categorias').tabs();
		
	// popup close
	
		$('#popup_window_close').click(function(){
		
		// hide popup board
		
			$('#popup_window,#popup_board').hide();
			
		// unselect contact menu item
		
			//$('a.menu_item').removeClass('menu_selected');
			
			return false;	
		});
		
	// close popupboard whenever click ESC
	
		$(document).keydown(function(e){
			if( $('#popup_window').css('display') == 'block' ) {
				if( e.which == 27 ) {
					$('#popup_window_close').click();
				}
			}
		});
		
	// popup_content links
	
		$('.popup_content').live('click',function(){
		
			var link = $(this);
		
		// hide and empty popup window log
		
			$('#popup_window_log').hide().empty();
			
		// hide actual content and show loading image
		
			$('#popup_window_content').hide();
			$('#popup_window_loading_image').show();
			
		// check if its contact menu item
		
			if( $(this).attr('id') == 'menu_item_contact' ) {
			
			// add class to popup_window
			
				$('#popup_window').addClass('popup_window_form');
				
			} else {
				
			// remove class
			
				$('#popup_window').removeClass('popup_window_form');
			}
			
		// show popup board
		
			$('#popup_board').show();
			
			$('#popup_window').fadeIn(function(){
				
			// load popup content
			
				$('#popup_window_content').load(link.attr('href'),null,function(){

				// callback function

					if( link.attr('callback') )
					{
						eval(link.attr('callback'));
					}
				
				// hide loading image
				
					$('#popup_window_loading_image').fadeOut(function(){
						
					// show popup content
					
						$('#popup_window_content').fadeIn();

					});
				});
			});
			
			return false;	
		});
	
	// menu selection
	
		$('a.menu_item').click(function(){
			
			$('a.menu_item').removeClass('menu_selected');
		
			$(this).addClass('menu_selected');
		});
		
		
	// ajax_content links
	
		$('.ajax_content').live('click',function(){
				
			var link = $(this);
			
			var confirm_ok = true;
			
			if( $(this).attr('confirm') )
			{
				confirm_ok = confirm($(this).attr('confirm'));
			}
			
			if( confirm_ok )
			{		
			// scroll to top links
			
				if( $(this).hasClass('scroll2top') ) {
				
					$.scrollTo('a[name=top_anchor]',{
						'duration': 600 
					});
				}
				
			// hide popup board
			
				$('#popup_window,#popup_board').hide();
				
			// hide actual ajax_content
			
				$('#ajax_content').fadeOut(function(){
					
				// show loading image
				
					$('#ajax_content_loading_image').fadeIn(function(){
	
						$('#ajax_content').load(link.attr('href'),null,function(){

							if( link.attr('callback') )
							{
								eval(link.attr('callback'));
							}
							
						// hide loading image
						
							$('#ajax_content_loading_image').fadeOut(function(){
								
							// show content
							
								$('#ajax_content').fadeIn();
								
								var href = link.attr('href');
								
							// update mini cart if it's loading tpv connect
								if( typeof (window.update_mini_cart) == 'function'
								 && href.match(/confirm_process/) != null ) {
									update_mini_cart();
								}
							});
						});
					});
				});
			}
			return false;
		});

	// update_cart links
	
		$('.update_cart').live('click',function(){
			
			var link = $(this);
			
		// hide popup board
		
			$('#popup_window,#popup_board').hide();
			
		// hide actual cart count
		
			$('#cesta_cantidad').fadeOut(function(){
				
			// show loading image
			
				$('#cesta_loading_image').fadeIn(function(){

					$('#cesta_cantidad').load(link.attr('href'),null,function(){
						
					// hide loading image
					
						$('#cesta_loading_image').fadeOut(function(){
							
						// show cart count
						
							$('#cesta_cantidad').fadeIn();
						});
					});
				});
			});
			
			return false;
		});
		
/*
	// submit del formulario de login
	
		$('#ajax_form_login_submit').live('click',function(){
			
			var formulario = this;
			
		// hide actual ajax_content
		
			$('#ajax_content').fadeOut(function(){
				
			// show loading image
			
				$('#ajax_content_loading_image').fadeIn(function(){
	
					// ajax call
					$.ajax({
						type: 'post',
						url: $(formulario).attr('action'),
						data: getAjaxInputs(formulario),
						success: function(data) {
console.log('hello');								
						// check if a redirection has to be made
console.log(data.indexOf('redirect:'));
							if( data.indexOf('redirect:') == 0 ) {
								
								//window.location = data.slice(9);
								
							} else {
									
							// hide loading image
							
								$('#ajax_content_loading_image').fadeOut(function(){
									
								// show content
								
									$('#ajax_content').html(data).fadeIn();
								});
							}
						}
					});
						
				});
			});
			
			return false;
		});
*/
	
		// due to non-ajax usuarios/usuarios/forgot_pass_end method
		forgot_password_form_callback();
	});

	
	// login form callback
	function login_form_callback()
	{
		$('#login').submit(function(){

			var formulario = this;

			if( checkCamposObligatorios($(formulario).attr('id'), $(formulario).attr('required_msg')) != false )	{

			// hide actual ajax_content
	
				$('#ajax_content').fadeOut(function(){
					
				// show loading image
				
					$('#ajax_content_loading_image').fadeIn(function(){
		
						// ajax call
						$.ajax({
							type: 'post',
							url: $(formulario).attr('action'),
							data: getAjaxInputs(formulario),
							success: function(data) {
								
							// check if a redirection has to be made

								if( data.indexOf('redirect:') == 0 ) {
								
									window.location = data.slice(9);
								
								} else {
									
								// hide loading image
							
									$('#ajax_content_loading_image').fadeOut(function(){
									
									// show content
								
										$('#ajax_content').html(data).fadeIn();
												
									// rebind submit event
										
										login_form_callback();
									});
								}
							}
						});
							
					});
				});
			}
		
			return false;
		});
	}
	
	// join form callback
	function join_form_callback()
	{
		$('#FormRegister').submit(function(){

			var formulario = this;

			if( checkCamposObligatorios($(formulario).attr('id'), $(formulario).attr('required_msg')) != false )	{

			// hide actual ajax_content
	
				$('#ajax_content').fadeOut(function(){
					
				// show loading image
				
					$('#ajax_content_loading_image').fadeIn(function(){
		
						// ajax call
						$.ajax({
							type: 'post',
							url: $(formulario).attr('action'),
							data: getAjaxInputs(formulario),
							success: function(data) {
								
							// hide loading image
						
								$('#ajax_content_loading_image').fadeOut(function(){
								
								// show content
							
									$('#ajax_content').html(data).fadeIn();
										
								// rebind submit event
									
									join_form_callback();
								});
							}
						});
							
					});
				});
			}
		
			return false;
		});
	}
	
	
	function forgot_password_form_callback()
	{
		$('#forgot_password').submit(function(){

			var formulario = this;

			if( checkCamposObligatorios($(formulario).attr('id'), $(formulario).attr('required_msg')) != false )	{

			// hide actual ajax_content
	
				$('#ajax_content').fadeOut(function(){
					
				// show loading image
				
					$('#ajax_content_loading_image').fadeIn(function(){
		
						// ajax call
						$.ajax({
							type: 'post',
							url: $(formulario).attr('action'),
							data: getAjaxInputs(formulario),
							success: function(data) {
								
							// hide loading image
						
								$('#ajax_content_loading_image').fadeOut(function(){
								
								// show content
							
									$('#ajax_content').html(data).fadeIn();
										
								// rebind submit event
									
									join_form_callback();
								});
							}
						});
							
					});
				});
			}
		
			return false;
		});
	}
	
	
	function account_form_callback()
	{
		$('#FormAccount').submit(function(){

			var formulario = this;

			if( checkCamposObligatorios($(formulario).attr('id'), $(formulario).attr('required_msg')) != false )	{

			// hide actual ajax_content
	
				$('#ajax_content').fadeOut(function(){
					
				// show loading image
				
					$('#ajax_content_loading_image').fadeIn(function(){
		
						// ajax call
						$.ajax({
							type: 'post',
							url: $(formulario).attr('action'),
							data: getAjaxInputs(formulario),
							success: function(data) {
								
							// hide loading image
						
								$('#ajax_content_loading_image').fadeOut(function(){
								
								// show content
							
									$('#ajax_content').html(data).fadeIn();
										
								// rebind submit event
									
									account_form_callback();
								});
							}
						});
							
					});
				});
			}
		
			return false;
		});
		
		$('#FormProfile').submit(function(){

			var formulario = this;

			if( checkCamposObligatorios($(formulario).attr('id'), $(formulario).attr('required_msg')) != false )	{

			// hide actual ajax_content
	
				$('#ajax_content').fadeOut(function(){
					
				// show loading image
				
					$('#ajax_content_loading_image').fadeIn(function(){
		
						// ajax call
						$.ajax({
							type: 'post',
							url: $(formulario).attr('action'),
							data: getAjaxInputs(formulario),
							success: function(data) {
								
							// hide loading image
						
								$('#ajax_content_loading_image').fadeOut(function(){
								
								// show content
							
									$('#ajax_content').html(data).fadeIn();
										
								// rebind submit event
								
									account_form_callback();
								});
							}
						});
							
					});
				});
			}
		
			return false;
		});
	}

	
	function tpv_connect_callback()
	{
	// auto submit and disable submit button

		$('form#tpv input:submit').click().attr('disabled','disabled');
		
	// on submit, show connecting message
		$('form#tpv').submit(function(){
				
			$('#tpv_connecting_message').show();
			
		});
	}