/*

PLOT JS

*/

var inav = false;

$(document).ready (

	function ( )
	{		
		
		/* iNav */
		
		if ( navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPod/i) != null || navigator.userAgent.match(/iPhone/i) != null )
		{
			inav = true;
		}
		
		if ( inav )
		{
			$( "#main" ).addClass ( 'main-no-fixed' );
			$( "#header" ).addClass ( 'no-fixed' );
		}
		
				
		/* SLIDER ABOUT */
			
		var tip_cant  = jQuery( '.empleados' ).length ;
		
		var tip_width = 110;
		
		var tip_actual = 0;
		
		var tip_max =  tip_cant - 8;
		
		jQuery( '#flecha-empleados-left' ).click ( 
		
			function ( event )
			{
				event.preventDefault ( );
				
				if ( tip_actual > 0 )
				{
					tip_actual --;
					mover_tips ( );	
				}
				
			}
		
		);
		
		jQuery( '#flecha-empleados-right' ).click ( 
		
			function ( event )
			{
				event.preventDefault ( );
				
				if ( tip_actual < tip_max  )
				{
					tip_actual ++;
					mover_tips ( );	
				}
				
			}
		
		);
		
		function mover_tips ( )
		{
			var val_x = - ( tip_actual * tip_width );
			
			
			
			jQuery( '.thumbs-empleados' ).animate ( { left: val_x } , 500 );
			
			if ( tip_actual == tip_cant )
			{
				jQuery( '#flecha-empleados-right' ).addClass ( 'flecha-empleados-right-disable' );
			}
			
			else
			{
				jQuery( '#flecha-empleados-right' ).removeClass ( 'flecha-empleados-right-disable' );
			}
			
			if ( tip_actual == 0 )
			{
				jQuery( '#flecha-empleados-left' ).addClass ( 'flecha-empleados-left-disable' );
			}
			else
			{
				jQuery( '#flecha-empleados-left' ).removeClass ( 'flecha-empleados-left-disable' );
			}
			
		}
		
		var nombre = 'Florencia Rodriguez';
			
		var descripcion = 'Directora Editorial';
		
		var id_plotter = 'plotter1';
		
		/* Despcriocion about */
		
		$(".volver-slider").click
		(
			function ( event )
			{
				event.preventDefault ( );
				
				$("#slider-empleados").removeClass( 'no-visible' );
				
				$("#decripcion-empleados").addClass( 'no-visible' );
				
				$("#decripcion-empleados ." + id_plotter +" ").addClass( 'no-visible' );
			}
		)
		
		
		$(".empleados").click
		(
			function ( event )
			{
				event.preventDefault ( );
				
				$("#slider-empleados").addClass( 'no-visible' );
				
				$("#decripcion-empleados").removeClass( 'no-visible' );
				
				
				id_plotter = $(this).attr('id');
				
				$("#decripcion-empleados ." + id_plotter +" ").removeClass( 'no-visible' );

			}
		)
		
		$("#siguiente-descripcion").click
		(
			function ( event )
			{
				event.preventDefault ( ); 
			
				if(id_plotter != "plotter8")
				{
				
					$("#decripcion-empleados ." + id_plotter +" ").addClass( 'no-visible' );
					
					id_plotter = id_plotter;
					
					var num = id_plotter.charAt(7);
					
					num = parseFloat(num);
					num = num + 1;
					
					id_plotter = 'plotter'.concat(num);
					
					
					$("#decripcion-empleados ." + id_plotter +" ").removeClass( 'no-visible' );
			
				}
			}
		)
		
		$("#anterior-descripcion").click
		(
			function ( event )
			{
				event.preventDefault ( );
				
				if(id_plotter != "plotter1")
				{
					
					$("#decripcion-empleados ." + id_plotter +" ").addClass( 'no-visible' );
					
					id_plotter = id_plotter;
					
					var num = id_plotter.charAt(7);
					
					num = parseFloat(num);
					num = num - 1;
					
					id_plotter = 'plotter'.concat(num);
					
					
					$("#decripcion-empleados ." + id_plotter +" ").removeClass( 'no-visible' );
			
				}
			
			}
		)
		
		
		
		/* HOVERS */
		
		
			
		
		$(".fila-lista").hover(function() {
			$(this).stop().animate({ backgroundColor: "#FFEC00"}, 100);
			},function() {
			$(this).stop().animate({ backgroundColor: "#D9D9D9" }, 800);
			})
			
		$(".item-lista").hover(function() {
			$(this).stop().animate({ backgroundColor: "#FFEC00"}, 100);
			},function() {
			$(this).stop().animate({ backgroundColor: "#CCC" }, 800);
			})

		/* HOVERS ICONS HEADER */
		
		if ($( "body" ).hasClass('layout-videos')  )
		{
			icons_hover_header_video ( );
		}else{
			
			icons_hover_header ( );
		}
		
		
		/* EASING */
		
		jQuery.easing.def = 'easeOutExpo';
		
		/* UTILS */
		
		if ( !inav )
		{
			tooltips_header ( );
		}
		
		desplegables ( );
		
		subir ( );
		
		newsletter ( );
		
		busqueda ( );
		
		/* SECCIONES */
		
		posts ( );
		
		video ( );
		
		tienda ( );
		
		contacto ( );
		
		single_producto ( );
		
		/* HOVER FLECHAS AGENDA */
		
		flechas_agenda ( );
		
		mostrar_linea_del_tiempo ( ) ;
		
		/* VIDEO THUMB HOVER */
		
		thumbs_hover ( );
		
		/* title hover */
		
		hover_title ( );
		
		/* POST HOVER */
		
		hover_post ( );
		
		/* ABOUT */
		
		agenda_hover( );
		
		empleados_hover ( );
		
		$(".layout-eventos").animate(
				
						{ 
				
							backgroundColor: "#D9D9D9"
				
						}, 1200);
		$(".layout-search").animate(
				
						{ 
				
							backgroundColor: "#ccc"
				
						}, 1200);
						
		$(".layout-").animate(
				
						{ 
				
							backgroundColor: "#ccc"
				
						}, 1200);
		
		$(".layout-page").animate(
				
						{ 
				
							backgroundColor: "#D9D9D9"
				
						}, 1200);
						
		$(".layout-page.page-332, .layout-page.page-344").animate(
				
						{ 
				
							backgroundColor: "#ccc"
				
						}, 1200);
		
		/* LIGHTBOX */
		
		$( '.fancy' ).fancybox (
		
			{
				'titleShow': false ,
				'overlayColor': '#000',
				'overlayOpacity': 0.6
			}
		
		);
		
	}
	
);

/* SINGLE PRODUCTO */

function single_producto ( )
{
	if ( $( ".single-productos" ).length )
	{
		$( ".slideshow-set" ).appendTo ( "#slider-producto" );
	}
	
}


/* VIDEO */

var video_list = new Array ( );
var video_cant = 0;
var video_page = 0;
var video_page_total = 0;

function video ( )
{
	
	if ( $("#super-video").length )
	{
		
		$(".layout-videos").animate ( {	backgroundColor: "#3C3C3B" } , 1200 );
			
		$(".thumbs-container > .thumbs .thumb").each (
			
			function ( )
			{
				video_list.push ( $(this).find( '.hash' ).text ( ) ); 	
			}
			
		);
		
		
		video_cant = video_list.length;
		
		video_page_total = Math.ceil ( video_cant / 10 );
		
		video_page_total --;
		
		if ( video_cant > 0 )
		{
			
			$(window).hashchange ( 
				function ( )
				{
					config_video_by_hash ( );
					
				}
			);
			
			config_video_by_hash ( );
			
			config_video_pagination ( );
			
		}
		else
		{
			//mostrar videos not found !
			alert ("no se encontraron videos!");
		}
		
	}
}

function config_video_by_hash ( )
{
	var hash = window.location.hash;
			
	var current = 0;
	
	if ( hash && hash.length > 1 )
	{	
		hash = hash.slice ( 1 );
		
		var current = video_list.indexOf ( hash );
		
		if ( current == -1 )
		{
			current = 0;
			
			$('.thumbs .thumb:first').addClass ( 'thumb-selected' );
			
		}
		else
		{
			$('.thumbs .thumb').removeClass ( 'thumb-selected' );
			$('.thumbs .' + hash ).addClass ( 'thumb-selected' );	
		}
	}
	else
	{
		$('.thumbs .thumb:first').addClass ( 'thumb-selected' );
			
	}
	
	$( '#subir' ).click ( );
	
	
	load_video ( current );	
	
}

function change_video_hash_to ( current )
{
	current = parseInt ( current );
	
	window.location.hash = video_list[current];
	
}

function load_video ( current )
{
	current = parseInt ( current );
	
	var next = -1;
	var prev = -1;
	
	if ( video_list[current+1] )
	{
		next = current + 1;
	}
	
	if ( video_list[current-1] )
	{
		prev = current - 1;
	}
		
	$.ajax ( {
		url: "/tv/" + video_list[current] + "/?next=" + next + "&prev=" + prev,
		success: load_video_success
	} );
	
}

function load_video_success ( video )
{
	$("#super-video").html ( video );
	
	$("#super-video .siguiente, #super-video .anterior").click (
	
		function ( event )
		{
			event.preventDefault ( );
			
			change_video_hash_to ( $(this).attr ( 'rel' ) );	
				
		}
		
	);
	tooltip_video ( );
}

function config_video_pagination ( )
{
	if ( video_cant > 10 )
	{
		
		$(".controles").removeClass ( 'no-visible' );
		
		$("#video-arriba").click ( 
		
			function ( event )
			{
				event.preventDefault ( );
				
				if ( video_page > 0 )
				{
					video_page --;
					video_mover ( );	
				}
			}
		
		);
		
		$("#video-abajo").click ( 
		
			function ( event )
			{
				event.preventDefault ( );
				
				if ( video_page < video_page_total )
				{
					video_page ++;
					video_mover ( );	
				}
			}
		
		);
		
	}
}

function video_mover ( )
{	
	var val_y = - ( video_page * 526 );
	
	$( '.thumbs-container .thumbs' ).animate ( { top: val_y } , 500 );
	
	if ( video_page == video_page_total )
	{
		$( '#video-abajo' ).addClass ( 'disabled' );
		$( '#video-arriba' ).removeClass ( 'disabled' );
		
	}
	else
	{
		$( '#video-abajo' ).removeClass ( 'disabled' );
	}
	
	if ( video_page == 0 )
	{
		$( '#video-arriba' ).addClass ( 'disabled' );
		$( '#video-abajo' ).removeClass ( 'disabled' );
	}
	else
	{
		$( '#video-arriba' ).removeClass ( 'disabled' );
	}
	
}


/* POSTS */

var last_grilla = 1;

var post_count = 0;
var post_per_page = 0;
var post_page = 0;
var post_total = 0;
var post_loading = false;

function posts ( )
{

	$(".layout-post").animate(
				
						{ 
				
							backgroundColor: "#ccc"
				
						}, 1200);


	if ( $("#posts-pre").length )
	{
				
		/* ACOMODA LOS POSTS EN LA GRILLA */
		
		grilla_posts ( );
		
		
		/* POSTS PAGINATION */
		
		post_count = parseInt ( $("#post-count").html( ) );
		post_per_page = parseInt ( $("#post-per-page").html( ) );
		post_page = parseInt ( $("#post-paged").html( ) );
		post_total = post_page * post_per_page;
		
		if ( post_total < post_count )
		{
			$("#pagination").removeClass ( 'no-visible' );
			
			$("#cargar-anteriores").click ( 
				
				function ( event )
				{
					event.preventDefault ( );
					
					cargar_mas_posts ( );
				}
			);
			
		}
		
		
	}

}

function grilla_posts ( )
{
	var cant = $("#posts-pre .post").length;
	var i = last_grilla;
	
	$("#posts-pre .post").each(function(index) {
						  
		if ( i == 5 ) i = 1;	
		
		$(this).appendTo($('#posts-grid-' + i));
		
		i ++;
	});
	
	last_grilla = i;
	
	$("#posts-pre").html ( '' );	
}

function cargar_mas_posts ( )
{
	if ( post_loading == false )
	{
		var load_url = document.URL;
		
		load_url = load_url.replace ( /page.*/ , "" );
		load_url = load_url.replace ( /#/ , "" );
		
		post_page = parseInt ( post_page ) + 1;	
		
		load_url = load_url + "page/" + post_page + "/";
		
		post_loading = true;
		
		$('#posts-pre').load ( load_url , { ajax: 1 } , cargar_mas_posts_success );
		
		$('#cargar-anteriores').html ( 'Cargando...' );
		$('#cargar-anteriores').addClass ( 'cargando' );
	}
}

function cargar_mas_posts_success ( )
{
	
	grilla_posts ( );
	
	post_total = post_total + post_per_page;
	
	$('#cargar-anteriores').html ( 'Cargar m&aacute;s posts' );
	$('#cargar-anteriores').removeClass ( 'cargando' );
	
	if ( post_total >= post_count )
	{
		$("#pagination").addClass ( 'no-visible' );		
	}
	
	post_loading = false;
	
}


/* CONTACTO */

function contacto ( )
{
	tooltip_contacto ( );
	if ( $( ".main-contacto" ).length )
	{
		clean_input ( "contacto-nombre"      , "Nombre" );
		clean_input ( "contacto-apellido"    , "Apellido" );
		clean_input ( "contacto-numero"      , "N°" );
		clean_input ( "contacto-depto"       , "Dpto" );
		clean_input ( "contacto-direccion"   , "Dirección" );
		clean_input ( "contacto-postal"      , "Código Postal" );
		clean_input ( "contacto-ciudad"      , "Ciudad" );
		clean_input ( "contacto-provincia"   , "Provincia" );
		clean_input ( "contacto-pais"        , "País" );
		clean_input ( "contacto-email"       , "Email" );
		clean_input ( "contacto-telefono"    , "Teléfono" );
		clean_input ( "contacto-comentarios" , "Comentarios/Inquietudes" );
		
		$( "#enviar" ).click (
		
			function ( event )
			{
				
				event.preventDefault ( );
				
				var v_nombre   = is_valid ( "contacto-nombre" , "Nombre" );
				var v_apellido = is_valid ( "contacto-apellido" , "Apellido" );
				var v_email    = is_valid_email ( "contacto-email" );
				
				$( ".enviado-exitosamente" ).addClass ( "no-visible" );
				$( ".captcha-error" ).addClass ( "no-visible" );
				$( ".no-enviado" ).addClass ( "no-visible" );
				
				if ( v_nombre && v_apellido && v_email )
				{
					
					var nombre      = url_var ( "contacto-nombre"      , "Nombre" );
					var apellido    = url_var ( "contacto-apellido"    , "Apellido" );
					var numero      = url_var ( "contacto-numero"      , "N°" );
					var depto       = url_var ( "contacto-depto"       , "Dpto" );
					var direccion   = url_var ( "contacto-direccion"   , "Dirección" );
					var postal      = url_var ( "contacto-postal"      , "Código Postal" );
					var ciudad      = url_var ( "contacto-ciudad"      , "Ciudad" );
					var provincia   = url_var ( "contacto-provincia"   , "Provincia" );
					var pais        = url_var ( "contacto-pais"        , "País" );
					var email       = url_var ( "contacto-email"       , "Email" );
					var telefono    = url_var ( "contacto-telefono"    , "Teléfono" );
					var comentarios = url_var ( "contacto-comentarios" , "Comentarios/Inquietudes" );
					
					var recaptcha_challenge_field = $( '#recaptcha_challenge_field' ).val ( );
					var recaptcha_response_field  = $( '#recaptcha_response_field'  ).val ( );
					
					$.ajax ( 
						{
							type: "POST" ,
							url: "/wp-content/themes/plot/utils/send_contacto.php",
							data: "task=email&nombre="+nombre+"&apellido="+apellido+"&numero="+numero+"&depto="+depto+"&direccion="+direccion+"&postal="+postal+"&ciudad="+ciudad+"&provincia="+provincia+"&pais="+pais+"&email="+email+"&telefono="+telefono+"&comentarios="+comentarios+"&recaptcha_challenge_field="+recaptcha_challenge_field+"&recaptcha_response_field="+recaptcha_response_field,
							success: function ( msg )
							{
								
								if ( msg == "ok" )
								{
									reset_input ( "contacto-nombre"      , "Nombre" );
									reset_input ( "contacto-apellido"    , "Apellido" );
									reset_input ( "contacto-numero"      , "N°" );
									reset_input ( "contacto-depto"       , "Dpto" );
									reset_input ( "contacto-direccion"   , "Dirección" );
									reset_input ( "contacto-postal"      , "Código Postal" );
									reset_input ( "contacto-ciudad"      , "Ciudad" );
									reset_input ( "contacto-provincia"   , "Provincia" );
									reset_input ( "contacto-pais"        , "País" );
									reset_input ( "contacto-email"       , "Email" );
									reset_input ( "contacto-telefono"    , "Teléfono" );
									reset_input ( "contacto-comentarios" , "Comentarios/Inquietudes" );
		
									$( ".enviado-exitosamente" ).removeClass ( "no-visible" );
								}
								else if ( msg == "captcha" )
								{
									$( ".captcha-error" ).removeClass ( "no-visible" );
								}
								else
								{
									$( ".no-enviado" ).removeClass ( "no-visible" );
								}
							}
						
						}
					);
				}
				
			}
		
		);
		
	}

}


/* BUSQUEDA */

var search_open = false;

function busqueda ( )
{
	
	$( "#link-search" ).click (
		
		function ( event )
		{

			$( this ).addClass ( 'link-search-open' );
			
			$( this ).animate( { width: 140 } );
			
			search_open = true;
			
			$( "#search" ).focus ( ); 
			
			event.preventDefault ( );
		}
	
	);
	
	$( "#search" ).blur ( 
		
		function ( )
		{
			$( "#link-search" ).removeClass ( 'link-search-open' );
				
			$( "#link-search" ).animate( { width: 7 } );
				
			search_open = false;
		}
	);
	
	$( "#search" ).keypress ( 
		
		function ( event )
		{
			if ( event.which == 13 )
			{
				window.location = plot_url + '/?s=' + escape ( $( this ).val ( ) );
			}
		}
	);
	
	if ( $( '#icon-busqueda' ).length )
	{
		
		$( "#icon-busqueda" ).click ( 
			
			function ( event )
			{
				window.location = plot_url + '/?s=' + escape ( $( '#busqueda' ).val ( ) );
			}
		);
	
	}
}

/* NEWSLETTER */

var news_config = false;
var news_open   = false;

function newsletter ( )
{
	
	$( ".action-news" ).click (
		
		function ( event )
		{
			var callback = abrir_news;
			
			if ( news_open )
			{
				callback = cerrar_news;	
			}
			
			if ( $.browser.opera ) 
			{
				$( 'html' ).animate( { scrollTop: 0 } , 500 , callback );
			} 
			else
			{
				$( 'body, html' ).animate( { scrollTop: 0 } , 500 , callback );  
			}
			
			event.preventDefault ( );
		}
	
	);

}

function abrir_news ( )
{
	if ( !news_config )
	{
	
		clean_input ( "news-nombre"      , "Nombre" );
		clean_input ( "news-apellido"    , "Apellido" );
		clean_input ( "news-numero"      , "N°" );
		clean_input ( "news-depto"       , "Dpto" );
		clean_input ( "news-direccion"   , "Dirección" );
		clean_input ( "news-postal"      , "Código Postal" );
		clean_input ( "news-ciudad"      , "Ciudad" );
		clean_input ( "news-provincia"   , "Provincia" );
		clean_input ( "news-pais"        , "País" );
		clean_input ( "news-email"       , "Email" );
			
		$( "#news-enviar" ).click (
		
			function ( event )
			{
				event.preventDefault ( );
				
				var v_nombre   = is_valid ( "news-nombre" , "Nombre" );
				var v_apellido = is_valid ( "news-apellido" , "Apellido" );
				var v_email    = is_valid_email ( "news-email" );
				
				if ( v_nombre && v_apellido && v_email )
				{
					
					var nombre      = url_var ( "news-nombre"      , "Nombre" );
					var apellido    = url_var ( "news-apellido"    , "Apellido" );
					var numero      = url_var ( "news-numero"      , "N°" );
					var depto       = url_var ( "news-depto"       , "Dpto" );
					var direccion   = url_var ( "news-direccion"   , "Dirección" );
					var postal      = url_var ( "news-postal"      , "Código Postal" );
					var ciudad      = url_var ( "news-ciudad"      , "Ciudad" );
					var provincia   = url_var ( "news-provincia"   , "Provincia" );
					var pais        = url_var ( "news-pais"        , "País" );
					var email       = url_var ( "news-email"       , "Email" );
					
					$.ajax ( 
						{
							type: "POST" ,
							url: "/wp-content/themes/plot/utils/send_news.php",
							data: "task=news&nombre="+nombre+"&apellido="+apellido+"&numero="+numero+"&depto="+depto+"&direccion="+direccion+"&postal="+postal+"&ciudad="+ciudad+"&provincia="+provincia+"&pais="+pais+"&email="+email,
							success: function ( msg )
							{
								if ( msg == "ok" )
								{
									cerrar_news ( );
								}
								else
								{
									$( ".suscripcion-noenviado" ).removeClass ( "no-visible" );
									$( "#newsletter-form" ).addClass ( "no-visible" );
								}
							}
						
						}
					);
				}
				
			}
		
		);
		
		$( ".suscripcion-noenviado .volver" ).click ( 
		
			function ( )
			{
				
				$( ".suscripcion-noenviado" ).addClass ( "no-visible" );
				$( "#newsletter-form" ).removeClass ( "no-visible" );
					
			}
		
		);
		
	}
	
	news_config = true;
	
	$( "#main" ).addClass ( 'main-no-fixed' );
	$( "#header" ).addClass ( 'no-fixed' );
	
	$( "#container-newsletter" ).slideDown ( 'slow' );
	
	news_open = true;
}

function cerrar_news ( )
{
	news_config = true;
	
	if ( !inav )
	{
		$( "#header" ).removeClass ( 'no-fixed' );
		$( "#main" ).removeClass ( 'main-no-fixed' );
	}
	
	$( "#container-newsletter" ).slideUp ( 'slow' );
	
	news_open = false;
}


/* UTILS */

function desplegables ( )
{
	
	$( '.desplegable-link' ).click (
					  
		function ( event )
		{
			
			event.preventDefault ( );
			
			if ( $( this ).parent( ).hasClass( 'desplegable-head-closed' ) )
			{
				$( this ).parent( ).removeClass( 'desplegable-head-closed' );
				$( this ).parent( ).parent( ).find( '.desplegable-body' ).slice(0,1).slideToggle( 'slow' );
				
			}
			else
			{
				$( this ).parent( ).parent( ).find( '.desplegable-body' ).slice(0,1).slideToggle( 'slow' , 
					function ( ) 
					{
						$( this ).parent( ).find( '.desplegable-head' ).slice(0,1).addClass( 'desplegable-head-closed' );
					}
				);
			}
		}
		
	);

}

function subir ( )
{
	
	$( '#subir' ).click (
					  
		function ( event )
		{
			if ( $.browser.opera ) 
			{
				$( 'html' ).animate( { scrollTop: 0 } , 500 );
			} 
			else
			{
				$( 'body, html' ).animate( { scrollTop: 0 } , 500 );  
			}
			
			event.preventDefault ( );
		}
		
	);

}

function clean_input ( input_id, default_value )
{
	
	$( "#" + input_id ).focus (
					  
		function ( )
		{
			
			if ( $( this ).val ( ) == default_value ) 
			{
				$( this ).val ( '' );
			} 
		}
		
	);
	
	$( "#" + input_id ).blur (
					  
		function ( )
		{
			if ( $( this ).val ( ) == '' ) 
			{
				$( this ).val ( default_value );
			} 
		}
		
	);

}

function reset_input ( input_id, default_value )
{
	
	$( "#" + input_id ).val ( default_value );

}

function url_var ( input_id, default_value )
{
	
	var return_string = "-";
	
	if ( $( "#" + input_id ).val ( ) != default_value )
	{
		return_string = $( "#" + input_id ).val ( );
	}
	
	return escape ( return_string );
}

function is_valid ( input_id , default_value )
{
	
	var valor  = $( "#" + input_id ).val ( );
	var valido = false;
	
	if ( valor.length > 1 && valor != default_value )
	{
		valido = true;
		$( "#" + input_id ).removeClass ( 'error' );
	}
	else
	{
		$( "#" + input_id ).addClass ( 'error' );
	}
	
	return valido;
	
}

function is_valid_email ( input_id )
{
	
	var valor  = $( "#" + input_id ).val ( );
	var valido = false;
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
    if ( filter.test ( valor ) ) 
	{
		valido = true;
		$( "#" + input_id ).removeClass ( 'error' );
	}
	else
	{
		$( "#" + input_id ).addClass ( 'error' );
	}
	
	return valido;
	
}

function is_checked ( input_id )
{
	
	var valido  = $( "#" + input_id ).is ( ':checked' );
	
    if ( valido ) 
	{
		$( "label[for='" + input_id + "']" ).removeClass ( 'error' );
	}
	else
	{
		$( "label[for='" + input_id + "']" ).addClass ( 'error' );
	}
	
	return valido;
	
}

function is_selected ( group_id , for_id_1 , for_id_2  )
{
	
	var valido  = $( "input[name='" + group_id + "']:checked" ).val ( );
	
    if ( !valido ) 
	{
		$( "#" + for_id_1 ).addClass ( 'error' );
		$( "#" + for_id_2 ).addClass ( 'error' );
	}
	else
	{
		$( "#" + for_id_1 ).removeClass ( 'error' );
		$( "#" + for_id_2 ).removeClass ( 'error' );
	}
	
	return valido;
	
}


/* TIENDA */

var tienda_cant = 0;

function tienda ( )
{	
	
	config_tienda_pop ( );
	
	$(".layout-productos").animate( { backgroundColor: "#D8D8D8" } , 1200 );

	update_cart_cant ( );
	
	config_shop ( );
	
	check_pais ( );
	
}

function config_tienda_pop ( )
{
	$( '#tienda-pop' ).fancybox ( { 'hideOnOverlayClick' : false , 'showCloseButton' : false } );
	
	$( '#pais-argentina' ).click (
	
		function ( event )
		{
			
			event.preventDefault ( );
			
			$( '#pais-argentina' ).addClass ( 'selected' );
			$( '#pais-internacional' ).removeClass ( 'selected' );
			
		}
	
	);
	
	$( '#pais-internacional' ).click (
	
		function ( event )
		{
			
			event.preventDefault ( );
			
			$( '#pais-argentina' ).removeClass ( 'selected' );
			$( '#pais-internacional' ).addClass ( 'selected' );
			
		}
	
	);
	
	$( '#pais-continuar' ).click (
	
		function ( event )
		{
			
			event.preventDefault ( );
			
			if ( $( '#pais-argentina' ).hasClass ( 'selected' ) )
			{
				$.cookie ( 'plot_tienda_pais' , 'arg' , { expires: 100 , path: '/' }  );
			}
			else
			{
				$.cookie ( 'plot_tienda_pais' , 'int' , { expires: 100 , path: '/' }  );
			}
			
			check_pais ( );
				
			$.fancybox.close ( );
			
		}
	
	);
	
}

function check_pais ( )
{
	
	var pais = $.cookie ( 'plot_tienda_pais' );
	
	if ( pais == null )
	{
		$( '.precio_arg' ).addClass ( 'no-visible' );
		$( '.precio_int' ).addClass ( 'no-visible' );
		
		$('#tienda-pop' ).click ( );
	}
	else
	{
		
		if ( pais == "arg" )
		{
			
			$( '#tienda_arg' ).removeClass ( 'no-visible' );
			$( '#tienda_int' ).addClass ( 'no-visible' );
			
			$( '.precio_arg' ).removeClass ( 'no-visible' );
			$( '.precio_int' ).addClass ( 'no-visible' );
			
		}
		else
		{
			
			$( '#tienda_int' ).removeClass ( 'no-visible' );
			$( '#tienda_arg' ).addClass ( 'no-visible' );
			
			$( '.precio_int' ).removeClass ( 'no-visible' );
			$( '.precio_arg' ).addClass ( 'no-visible' );
		}
		
		if ( $( ".main-carrito" ).length && tienda_cant > 0 )
		{
			//hola
			
		}
			
	}
}

function config_shop ( )
{
	
	$( '#tienda_arg' ).click (
	
	
		function ( event )
		{
		
			event.preventDefault ( );
			
			$.cookie ( 'plot_tienda_pais' , 'int' , { expires: 100 , path: '/' }  );
			
			check_pais ( );
			
		}
	
	);
	
	$( '#tienda_int' ).click (
	
	
		function ( event )
		{
		
			event.preventDefault ( );
			
			$.cookie ( 'plot_tienda_pais' , 'arg' , { expires: 100 , path: '/' }  );
			
			check_pais ( );
			
		}
	
	);
	
	if ( $(".container-shop").length )
	{	
	
		$(".container-shop > .thumb").click (
			
			function ( )
			{
				window.location =  $( this ).find ( ".detalle > .descripcion >  h2 > a" ).attr ( "href" );
			}
			
		);
		
		$(".container-shop > .thumb").hover (
  			
			function ( )
			{
				$(this).addClass ( "thumb-over" );
			    $(this).find ( ".detalle" ).show ( );
			},
			
			function ( )
			{
				$(this).removeClass ( "thumb-over" );
    			$(this).find ( ".detalle" ).hide ( );
  			}
			
		);
	}
	
	if ( $( ".main-shopcart" ).length && $( "#comprar" ).length )
	{	
	
		$( "#comprar" ).click (
			
			function ( event )
			{
				event.preventDefault ( );
				
				var prod_id = $( "#prod-id" ).text ( );
				var prod_cant = parseInt ( $( "#prod-cant" ).val ( ) );
				
				if ( prod_cant == 0 || isNaN ( prod_cant ) )
				{
					prod_cant = 1;	
				}
				else if ( prod_cant > 99 )
				{
					prod_cant = 99;	
				}
				
				var prod_opcion = new Array ( );
				var prod_valor  = new Array ( );
				
				for ( var i = 0 ; i < 4 ; i ++ )
				{
					if ( $( "#opcion_nombre_" + i ) && $( "#opcion_valor_" + i ) )
					{
						var nombre = $( "#opcion_nombre_" + i ).text ( );
						nombre = nombre.slice ( 0 , -1 );
						
						var valor  = $( "#opcion_valor_"  + i + " > option:selected" ).text ( );
						
						if ( nombre && valor )
						{
							prod_opcion.push ( nombre );
							prod_valor.push  ( valor  );
						}
					}
					
				}
				
				//alert ( "ID: " + prod_id + " / CANT: " + prod_cant + " / OP NOMBRES: " + prod_opcion + " OP VALOR: " + prod_valor );
				
				add_to_cart ( prod_id , prod_cant , prod_opcion , prod_valor );
			}
			
		);
		
	}
	
	if ( $( ".main-carrito" ).length )
	{
		if ( tienda_cant == 0 )
		{
			$( ".main-carrito h3" ).addClass ( 'no-visible' );
			$( ".main-carrito #no-result" ).removeClass ( 'no-visible' );	
		}
		else
		{
			load_cart_items ( );
			
			$( '#checkout-dm' ).click (
			
				function ( event )
				{
					event.preventDefault ( );
					
					checkout ( );
				}
			
			);
			
			$( '#continuar' ).click (
			
				function ( event )
				{
					event.preventDefault ( );
					
					$( this ).addClass ( 'no-visible' );
					
					clean_input ( "buyer_name"            , "Nombre" );
					clean_input ( "buyer_lastname"        , "Apellido" );
					clean_input ( "buyer_number"          , "N°" );
					clean_input ( "buyer_complement"      , "Dpto" );
					clean_input ( "buyer_street"          , "Dirección" );
					clean_input ( "buyer_zip_code"        , "Código Postal" );
					clean_input ( "buyer_city"            , "Ciudad" );
					clean_input ( "buyer_state"           , "Provincia" );
					clean_input ( "buyer_phone"           , "Teléfono" );
					clean_input ( "buyer_document_number" , "DNI" );
					clean_input ( "buyer_email"           , "Email" );
										
					$( '#carrito-checkout' ).slideDown ( );
					
					var offset = $( '.volver-tienda' ).offset ( );
					
					if ( $.browser.opera ) 
					{
						$( 'html' ).animate( { scrollTop: offset.top } , "slow" );
					} 
					else
					{
						$( 'body, html' ).animate( { scrollTop: offset.top } , "slow" );  
					}
					
				}
			
			);
		}
	}
}

function load_cart_items ( )
{	
	var load_ids = $.cookie ( 'plot_tienda_ids' );
	
	if ( load_ids )
	{
		load_ids = load_ids.slice ( 0 , -1 );
		
		var load_url = plot_url + '/tienda/xml/' + load_ids;
		
		$('#carrito-inner').load ( load_url , { ajax: 1 } , load_cart_items_success );
		
		$( ".main-carrito #carrito-loading" ).removeClass ( 'no-visible' );
	}
	
}

function load_cart_items_success ( )
{
	
	check_pais ( );
	
	$( "#carrito-inner ul" ).each (
	
		
		function ( )
		{
			var prod_id = $( this ).find( ".producto-id" ).text ( );
			
			var cookie_exists = $.cookie ( "plot_tienda_" + prod_id );
			
			if ( cookie_exists )
			{
				var xml_doc  = $.parseXML( cookie_exists  );				
				var xml_prod = $( xml_doc );
				
				// eliminar
				
				$( this ).find ( ".cancelar" ).click (
				
					function ( )
					{
						
						remove_from_cart ( prod_id );
						
						$( this ).parent ( ).parent ( ).remove ( );
						
						update_cart_total ( );
						
					}
				
				);
				
				
				// cantidad 
				
				var prod_cant = parseInt ( xml_prod.find ( "cant" ).text ( ) );
				
				$( this ).find ( ".carrito-cant" ).val ( prod_cant );
				
				$( this ).find ( ".carrito-cant" ).change (
				
					function ( )
					{
						
						var nu_cant = parseInt ( $ ( this ).val ( ) );
						
						var el_precio = $( this ).parent ( ).parent ( ).find ( ".carrito-precio > span:not(.no-visible)" ).text ( );
						
						var signo = '';
						
						if ( $.cookie ( 'plot_tienda_pais' ) == 'arg' )
						{
							signo = '$';
							el_precio = el_precio.slice ( 1 );				
						}
						else
						{
							signo = 'usd';
							el_precio = el_precio.slice ( 3 );
						}
						
						
						var el_precio_final = el_precio * nu_cant;
						
						el_precio_final = Math.round ( el_precio_final * 100 ) / 100;
						
						$( this ).parent ( ).parent ( ).find( ".carrito-subtotal" ).html ( signo + el_precio_final );
						
						update_cart_total ( );
						
					}
				
				);
				
				$( this ).find ( ".carrito-cant" ).change ( );
				
				/*
				
				$( xml_prod ).find ( "opcion" ).each ( 
					
					function ( )
					{
						//alert ( $( this ).text ( ) );
						//alert ( $( this ).find ( "nombre" ).text ( ) + ': ' + $( this ).find ( "valor" ).text ( ) );
					}
					
				);
				
				*/
				
				// calculo subtotal
				/*var prod_precio = $( this ).parent ( ).parent ( ).find ( ".carrito-precio > span:not(.no-visible)" ).text ( );
									
				var signo = '';
				
				if ( $.cookie ( 'plot_tienda_pais' ) == 'arg' )
				{
					signo = '$';
					prod_precio = prod_precio.slice ( 1 );				
				}
				else
				{
					signo = 'usd';
					prod_precio = prod_precio.slice ( 3 );
				}		
				
				var precio_final = parseFloat ( prod_precio ) * prod_cant;
						
				precio_final = Math.round ( precio_final * 100 ) / 100;
				
				$( this ).find( ".carrito-subtotal" ).html ( signo + precio_final );*/
				
			}
			else
			{
				$( this ).remove ( );	
			}
		}
	
	);
	
	$( ".main-carrito #carrito-loading" ).addClass ( 'no-visible' );	
	$( ".main-carrito #carrito" ).removeClass ( 'no-visible' );	
	$( ".main-carrito #carrito-footer" ).removeClass ( 'no-visible' );
	
	columna_hover ( ) ;/*llamo a la function hover*/
	
	update_cart_total ( );
}

function update_cart_total ( )
{
	var total = 0;
	
	var signo = '';
	var slice_index = 0;
					
	if ( $.cookie ( 'plot_tienda_pais' ) == 'arg' )
	{
		signo = '$';
		slice_index = 1;				
	}
	else
	{
		signo = 'usd';
		slice_index = 3;
	}
	
	$( ".carrito-subtotal" ).each (
		
		function ( )
		{
			
			var el_precio = $( this ).find ( "span:not(.no-visible)" ).text ( );
			
			var subtotal = $( this ).text ( );
			
			subtotal = parseFloat ( subtotal.slice ( slice_index ) );
			
			total += subtotal;	
		}
	
	);
						
	total = Math.round ( total * 100 ) / 100;
	
	$( '.carrito-total > .precio' ).html ( signo + total );
}

function update_cart_cant ( )
{	
	var tienda_ids = $.cookie ( 'plot_tienda_ids' );
	
	if ( tienda_ids )
	{		
		//alert ( tienda_ids );
		
		var arr_tienda = tienda_ids.split ( ',' );
		tienda_cant = arr_tienda.length;
		tienda_cant --;
		
		$( '.link-carrito' ).html ( '(' + tienda_cant + ')' );
		$( '.link-carrito' ).addClass ( 'link-carrito-txt' );	
	}
	else
	{
		tienda_cant = 0;
		
		$( '.link-carrito' ).html ( '' );
		$( '.link-carrito' ).removeClass ( 'link-carrito-txt' );
		
		$( ".main-carrito h3" ).addClass ( 'no-visible' );
		$( ".main-carrito #no-result" ).removeClass ( 'no-visible' );
			
		$( ".main-carrito #carrito" ).addClass ( 'no-visible' );	
		$( ".main-carrito #carrito-footer" ).addClass ( 'no-visible' );
	}
	
}

function add_to_cart ( prod_id , prod_cant , prod_opcion , prod_valor )
{	
	var cant_prods = prod_opcion.length;
	
	var cookie_exists = $.cookie ( 'plot_tienda_' + prod_id );
	
	if ( cookie_exists )
	{		
		var xml_doc  = $.parseXML( cookie_exists  );				
		var xml_prod = $( xml_doc );
		
		prod_cant = parseInt ( xml_prod.find ( 'cant' ).text ( ) ) + prod_cant;
	}
	
	var prod_xml = "<producto id='" + parseInt ( prod_id ) + "' >";
	
		prod_xml += "<cant>"+ prod_cant +"</cant>";
		
		prod_xml += "<opciones>";
		
			for ( var i = 0 ; i < cant_prods ; i++ )
			{
				prod_xml += "<opcion><nombre><![CDATA[" + prod_opcion[i] + "]]></nombre><valor><![CDATA[" + prod_valor[i] + "]]></valor></opcion>"
			}
		
		prod_xml += "</opciones>";
	
	prod_xml += "</producto>";
	
	//alert ( prod_xml );
	
	$.cookie ( 'plot_tienda_' + prod_id , prod_xml , { expires: 100 , path: '/' }  );
	
	
	if ( !cookie_exists )
	{
		
		var tienda_ids = $.cookie ( 'plot_tienda_ids' );
		
		if ( tienda_ids )
		{
			tienda_ids = tienda_ids + prod_id + ",";
		}
		else
		{
			tienda_ids = prod_id + ",";
		}
		
		$.cookie ( 'plot_tienda_ids' , tienda_ids , { expires: 100 , path: '/' }  );
		
		update_cart_cant ( );
		
	}
	
	window.location = plot_url + "/tienda/compras/";
}

function remove_from_cart ( prod_id )
{
	$.cookie ( 'plot_tienda_' + prod_id , null , { path: '/' } );	
	
	var tienda_ids = $.cookie ( 'plot_tienda_ids' );
	
	var arr_tienda = tienda_ids.split ( ',' );
	
	arr_tienda.pop ( );
	
	var cant_items = arr_tienda.length;
	
	if ( cant_items > 1 )
	{
		var pos_remove = null;
		
		for ( var i = 0 ; i < cant_items ; i++ )
		{
			if ( parseInt ( arr_tienda[i] ) == parseInt ( prod_id ) )
			{
				pos_remove = i;
				break;
			}
		}
		
		arr_tienda.splice ( pos_remove , 1 );
		
		var nu_ids = '';
		
		cant_items = arr_tienda.length;
		
		for ( var e = 0 ; e < cant_items ; e++ )
		{
			
			nu_ids += arr_tienda[e] + ',';
		}
		
		$.cookie ( 'plot_tienda_ids' , nu_ids , { expires: 100 , path: '/' } ); 
	}
	else
	{
		$.cookie ( 'plot_tienda_ids' , null , { path: '/' } ); 
	}
	
	update_cart_cant ( );
}

function checkout ( )
{
	
	var inter = true;
	var currency = 'usd';
	
	if ( $.cookie ( 'plot_tienda_pais' ) == 'arg' )
	{
		inter = false;
		currency = 'ars';	
	}
	
	// VALIDAR DATOS DE ENVIO COMPLETADOS
	
	var f_name   = is_valid ( "buyer_name"            , "Nombre" );
	var f_last   = is_valid ( "buyer_lastname"        , "Apellido" );
	var f_number = is_valid ( "buyer_number"          , "N°" );
	var f_depto  = is_valid ( "buyer_complement"      , "Dpto" );
	var f_street = is_valid ( "buyer_street"          , "Dirección" );
	var f_zip    = is_valid ( "buyer_zip_code"        , "Código Postal" );
	var f_city   = is_valid ( "buyer_city"            , "Ciudad" );
	var f_state  = is_valid ( "buyer_state"           , "Provincia" );
	var f_phone  = is_valid ( "buyer_phone"           , "Teléfono" );
	var f_dni    = is_valid ( "buyer_document_number" , "DNI" );
	var f_email  = is_valid ( "buyer_email"           , "Email" );
	
	if ( f_name && f_last && f_number && f_depto && f_street && f_zip && f_city && f_state && f_phone && f_dni && f_email )
	{
		var item_nro = 1;
		
		insert_in_checkout_form ( 'merchant'     , "dineromail@revistaplot.com" );
		insert_in_checkout_form ( 'seller_name'  , "Tienda Plot" );
		insert_in_checkout_form ( 'country_id'   , "1" );
		insert_in_checkout_form ( 'header_image' , "https://revistaplot.com/wp-content/themes/plot/img/plot-dm.jpg" );
		insert_in_checkout_form ( 'payment_method_available' , "all" );
		//insert_in_checkout_form ( 'currency'     , currency );
		
		var registro = '';
		
		$( '#carrito-inner > ul' ).each (
			
			function ( )
			{
				var item_name = $( this ).find ( '.carrito-nombre' ).text ( );				
				
				var item_quantity = parseInt ( $( this ).find ( '.carrito-cant' ).val ( ) );
				
				var item_ammount = $( this ).find ( '.carrito-precio > span:not(.no-visible)' ).text ( );
				
				if ( inter )
				{
					item_ammount = item_ammount.slice ( 3 );
				}
				else
				{
					item_ammount = item_ammount.slice ( 1 );
				}
				
				item_ammount = item_ammount.replace ( "," , "." );
				if ( item_ammount.indexOf ( '.' ) < 0 ) item_ammount += '.00'; 
				if ( item_ammount.indexOf ( '.' ) == ( item_ammount.length - 2 ) ) item_ammount += '0';
				
				insert_in_checkout_form ( 'item_name_' + item_nro , item_name );
				insert_in_checkout_form ( 'item_quantity_' + item_nro , item_quantity );
				insert_in_checkout_form ( 'item_ammount_' + item_nro , item_ammount );
				insert_in_checkout_form ( 'item_currency_' + item_nro , currency );
				
				registro += "<tr><td class='n' >" + item_name + "</td><td class='q' >" + item_quantity + "</td><td class='a' >" + item_ammount + "</td></tr>";
				
				item_nro ++;
			}
			
		);
		
		var compra_data = "task=comprar";
	
		var v_nombre    = url_var ( "buyer_name"            , "Nombre" );
		var v_apellido  = url_var ( "buyer_lastname"        , "Apellido" );
		var v_dni       = url_var ( "buyer_document_number" , "DNI" );
		var v_numero    = url_var ( "buyer_number"          , "N°" );
		var v_depto     = url_var ( "buyer_complement"      , "Dpto" );
		var v_direccion = url_var ( "buyer_street"          , "Dirección" );
		var v_postal    = url_var ( "buyer_zip_code"        , "Código Postal" );
		var v_telefono  = url_var ( "buyer_phone"           , "Teléfono" );
		var v_ciudad    = url_var ( "buyer_city"            , "Ciudad" );
		var v_provincia = url_var ( "buyer_state"           , "Provincia" );
		var v_email     = url_var ( "buyer_email"           , "Email" );
		var v_pais      = $( '#additional_var_value_1 option:selected' ).val ( );
		
		var recaptcha_challenge_field = $( '#recaptcha_challenge_field' ).val ( );
		var recaptcha_response_field  = $( '#recaptcha_response_field'  ).val ( );
		
		$( ".captcha-error" ).addClass ( "no-visible" );
		$( ".no-enviado" ).addClass ( "no-visible" );
		
		compra_data += "&nombre=" + v_nombre + "&apellido=" + v_apellido + "&dni=" + v_dni + "&numero=" + v_numero + "&depto=" + v_depto + "&direccion=" + v_direccion + "&postal=" + v_postal + "&telefono=" + v_telefono + "&ciudad=" + v_ciudad + "&provincia=" + v_provincia + "&email=" + v_email + "&pais=" + v_pais + "&registro=" + registro + "&recaptcha_challenge_field=" + recaptcha_challenge_field + "&recaptcha_response_field=" + recaptcha_response_field;
				
		$.ajax ( 
		{
			type: "POST" ,
			url: "/wp-content/themes/plot/utils/send_compra.php" ,
			data: compra_data ,
			success: function ( msg )
			{
				if ( msg == "ok" )
				{
					$( '#dm-data' ).submit ( );
				}
				else if ( msg == "captcha" )
				{
					$( ".captcha-error" ).removeClass ( "no-visible" );
				
				}
				else
				{
					$( ".no-enviado" ).removeClass ( "no-visible" );	
				}
			}
		
		} );
		
	}
	
}

function encode_value ( value )
{
	return escape ( value );	
}

function insert_in_checkout_form ( element_id , value )
{
	$( '#dm-data' ).append ( '<input type="hidden" id="' +  element_id + '" name="' + element_id + '" value="' + value + '" />' );
}


/* SUSCRIPCION */

var paso1 = false;
var paso2 = false;

function suscripcion_web ( )
{
		
	// NAV TOP
	
	$( "#paso-1" ).click (
	
		function ( event )
		{
			event.preventDefault ( );
			
			if ( paso1 )
			{
				$( "." + paso2 ).addClass ( 'no-visible' );
				$( ".page1" ).removeClass ( 'no-visible' );
				
				paso1 = false;
			}
			else
			{
				$( ".page1" ).removeClass ( 'no-visible' );
				$( ".page-numero" ).addClass ( 'no-visible' );
			}
		}
		
	);
	
	$( "#paso-2" ).click (
	
		function ( event )
		{
			event.preventDefault ( );
			
			if ( paso2 )
			{
				$( "." + paso2 ).removeClass ( 'no-visible' );
				$( ".page1" ).addClass ( 'no-visible' );
				$( ".page-numero" ).addClass ( 'no-visible' );
				
				paso1 = true;
			}
		}
		
	);
	
	// PAGE 1 / DATOS PERSONALES
	
	clean_input ( "s-nombre"        , "Nombre" );
	clean_input ( "s-apellido"      , "Apellido" );
	clean_input ( "s-dni"           , "DNI" );
	clean_input ( "s-direccion"     , "Dirección" );
	clean_input ( "s-codigo-postal" , "Código Postal" );
	clean_input ( "s-telefono"      , "Teléfono" );
	clean_input ( "s-ciudad"        , "Ciudad" );
	clean_input ( "s-provincia"     , "Provincia" );
	clean_input ( "s-email"         , "Email" );
	clean_input ( "s-vendedor"      , "Cod. Vendedor (si aplica)" );
	
	$( "#continuar" ).click (
	
		function ( event )
		{
			
			event.preventDefault ( );
			
			var v_nombre    = is_valid ( "s-nombre"        , "Nombre" );
			var v_apellido  = is_valid ( "s-apellido"      , "Apellido" );
			var v_dni       = is_valid ( "s-dni"           , "DNI" );
			var v_direccion = is_valid ( "s-direccion"     , "Dirección" );
			var v_postal    = is_valid ( "s-codigo-postal" , "Código Postal" );
			var v_telefono  = is_valid ( "s-telefono"      , "Teléfono" );
			var v_ciudad    = is_valid ( "s-ciudad"        , "Ciudad" );
			var v_provincia = is_valid ( "s-provincia"     , "Provincia" );
			var v_email     = is_valid_email ( "s-email"   , "Email" );
			var v_terminos  = is_checked ( "s-terminos" );
			
			if ( v_nombre && v_apellido && v_dni && v_direccion && v_postal && v_ciudad && v_provincia && v_email && v_terminos )
			{
				
				$( ".page1" ).addClass ( 'no-visible' );
				
				$( ".page-numero" ).removeClass ( 'no-visible' );
				
			}
			
		}
	
	);
	
	$( "#continuar-2" ).click (
	
		function ( event )
		{
			
			event.preventDefault ( );
			
			var v_numero = is_selected ( 'suscripcion' , 'label-numero-actual' , 'label-numero-proximo' );
			var v_pago   = is_selected ( 'tipo' , 'label-cbu' , 'label-tarjeta' );
			
			if ( v_numero && v_pago )
			{
				
				paso1 = true;
				
				$( ".page-numero" ).addClass ( 'no-visible' );
				
				if ( $( 'input[name=tipo]:checked' ).val( ) == 'cbu' )
				{
					$( ".page3" ).removeClass ( 'no-visible' );
					paso2 = "page3";
				}
				else
				{
					$( ".page4" ).removeClass ( 'no-visible' );
					paso2 = "page4";
				}
				
			}
			
		}
	
	);
	
	
	$( "#s-pais" ).change (
	
		function ( )
		{
			
			var pais_selected = $( this ).find ( "option:selected" ).val ( );
			
			if ( pais_selected == "Argentina" )
			{
				$( ".precio" ).html ( precio_ar );
				$( ".pais" ).html ( cambio_ar );
			}
			else
			{
				$( ".precio" ).html ( precio_int );
				$( ".pais" ).html ( cambio_int );
			}
			
		}
		
	);
	
	$ ( "#hisorial-numeros" ).click (
	
		function ( )
		{
			$( this ).attr ( 'href', plot_url + "tienda/categoria/numeros-anteriores/" );
		}
	
	);
	
	// PAGE 2 / TERMINOS Y CONDICIONES
	
	$( "#terminos-condiciones" ).click (
	
		function ( event )
		{
			event.preventDefault ( );
			
			$( ".page1" ).addClass ( 'no-visible' );
			$( ".page2" ).removeClass ( 'no-visible' );
		}
	
	);
	
	$( "#volver" ).click (
	
		function ( event )
		{
			event.preventDefault ( );
			
			$( ".page2" ).addClass ( 'no-visible' );
			$( ".page1" ).removeClass ( 'no-visible' );
		}
	
	);
	
	// PAGE 3
	
	clean_input ( "s-numero-titular"   , "" );
	clean_input ( "s-nombre-titular"   , "" );
	clean_input ( "s-apellido-titular" , "" );
	clean_input ( "s-dni-titular"      , "" );
	
	$( "#s-enviar-2" ).click (
	
		function ( event )
		{
			event.preventDefault ( );
			
			var v_numero_titular   = is_valid ( "s-numero-titular"   , "" );
			var v_nombre_titular   = is_valid ( "s-nombre-titular"   , "" );
			var v_apellido_titular = is_valid ( "s-apellido-titular" , "" );
			var v_dni_titular      = is_valid ( "s-dni-titular"      , "" );
			
			if ( v_numero_titular && v_nombre_titular && v_apellido_titular && v_dni_titular )
			{				
				$( ".page3" ).addClass ( 'no-visible' );
				
				send_suscripcion_web ( );				
			}
			
		}
	
	);
	
	// PAGE 4
		
	clean_input ( "s-titular-2"              , "" );
	clean_input ( "s-dni-2"                  , "" );
	clean_input ( "s-tipo-tarjeta-2"         , "" );
	clean_input ( "s-numero-tarjeta-titular" , "" );
	clean_input ( "s-codigo-seguridad"       , "" );
	
	$( "#s-enviar-3" ).click (
	
		function ( event )
		{
			event.preventDefault ( );
			
			var v_titular_2              = is_valid ( "s-titular-2"              , "" );
			var v_dni_2                  = is_valid ( "s-dni-2"                  , "" );
			var v_tipo_tarjeta_2         = is_valid ( "s-tipo-tarjeta-2"         , "" );
			var v_numero_tarjeta_titular = is_valid ( "s-numero-tarjeta-titular" , "" );
			var v_seguridad              = is_valid ( "s-codigo-seguridad"       , "" );
			
			if ( v_titular_2 && v_dni_2 && v_tipo_tarjeta_2 && v_numero_tarjeta_titular && v_seguridad )
			{				
				$( ".page4" ).addClass ( 'no-visible' );
				
				send_suscripcion_web ( );
			}
			
		}
	
	);
	
	
}

function send_suscripcion_web ( )
{
	var suscripcion_data = "task=suscribir";
	
	var v_nombre    = url_var ( "s-nombre"        , "Nombre" );
	var v_apellido  = url_var ( "s-apellido"      , "Apellido" );
	var v_dni       = url_var ( "s-dni"           , "DNI" );
	var v_direccion = url_var ( "s-direccion"     , "Dirección" );
	var v_postal    = url_var ( "s-codigo-postal" , "Código Postal" );
	var v_telefono  = url_var ( "s-telefono"      , "Teléfono" );
	var v_ciudad    = url_var ( "s-ciudad"        , "Ciudad" );
	var v_provincia = url_var ( "s-provincia"     , "Provincia" );
	var v_email     = url_var ( "s-email"         , "Email" );
	var v_vendedor  = url_var ( "s-vendedor"      , "Cod. Vendedor (si aplica)" );
	
	var v_revista   = $( 'input[name=suscripcion]:checked' ).val ( );
	var v_pais      = $( '#s-pais option:selected' ).val ( );
	var v_pago      = $( 'input[name=tipo]:checked' ).val ( );
	
	suscripcion_data += "&nombre=" + v_nombre + "&apellido=" + v_apellido + "&dni=" + v_dni + "&direccion=" + v_direccion + "&postal=" + v_postal + "&telefono=" + v_telefono + "&ciudad=" + v_ciudad + "&provincia=" + v_provincia + "&email=" + v_email + "&revista=" + v_revista + "&pais=" + v_pais + "&pago=" + v_pago + "&vendedor=" + v_vendedor;
	
	
	if ( v_pago == "cbu" )
	{
		
		var v_numero_titular   = url_var ( "s-numero-titular"   , "" );
		var v_nombre_titular   = url_var ( "s-nombre-titular"   , "" );
		var v_apellido_titular = url_var ( "s-apellido-titular" , "" );
		var v_dni_titular      = url_var ( "s-dni-titular"      , "" );
		
		var v_banco            = $( '#s-banco option:selected' ).val ( );
		var v_cuenta           = $( '#s-tipo-cuenta option:selected' ).val ( );
		
		suscripcion_data += "&numero-titular=" + v_numero_titular + "&nombre-titular=" + v_nombre_titular + "&apellido-titular=" + v_apellido_titular + "&dni-titular=" + v_dni_titular + "&banco=" + v_banco + "&cuenta=" + v_cuenta;
		
	}
	else
	{
		
		var v_titular_2              = url_var ( "s-titular-2"              , "" );
		var v_dni_2                  = url_var ( "s-dni-2"                  , "" );
		var v_tipo_tarjeta_2         = url_var ( "s-tipo-tarjeta-2"         , "" );
		var v_numero_tarjeta_titular = url_var ( "s-numero-tarjeta-titular" , "" );
		var v_seguridad              = url_var ( "s-codigo-seguridad"       , "" );
		
		var v_mes                    = $( '#s-vencimiento-mes option:selected' ).val ( );
		var v_anio                   = $( '#s-vencimiento-ano option:selected' ).val ( );
		
		suscripcion_data += "&titular-2=" + v_titular_2 + "&dni-2=" + v_dni_2 + "&tipo-tarjeta-2=" + v_tipo_tarjeta_2 + "&numero-tarjeta-titular=" + v_numero_tarjeta_titular + "&seguridad=" + v_seguridad + "&mes=" + v_mes + "&anio=" + v_anio;
		
	}
	
	$.ajax ( 
		{
			type: "POST" ,
			url: plot_ssl + "utils/send_suscripcion.php" ,
			data: suscripcion_data ,
			success: function ( msg )
			{
				if ( msg == "ok" )
				{
					$( ".page3" ).addClass ( 'no-visible' );
					$( ".page4" ).addClass ( 'no-visible' );
					
					$( ".page5" ).removeClass ( 'no-visible' );
					$( ".finish" ).removeClass ( 'no-visible' );
				}
				else
				{
					$( ".page3" ).addClass ( 'no-visible' );
					$( ".page4" ).addClass ( 'no-visible' );
					
					$( ".page5" ).removeClass ( 'no-visible' );
					$( ".ocurrio-error" ).removeClass ( 'no-visible' );
				}
			}
		
		}
	);
	
}

function empleados_hover ( )
{
		$(".empleados").hover (
  			
			function ( )
			{
				$(this).find("p").removeClass ( "no-visible" );
				$(this).find("span").removeClass ( "no-visible" );
				$(this).find(".capa-thumb-empleados").removeClass ( "no-visible" );
				$(this).find(".more-info").removeClass ( "no-visible" );
				$(this).find(".capa-thumb-empleados").stop().animate({ backgroundColor: "#f00"}, 3000);
  			},	
			
			function ( )
			{
				$(this).find("p").addClass ( "no-visible" );
				$(this).find("span").addClass ( "no-visible" );
				$(this).find(".more-info").addClass ( "no-visible" );
				
			   $(this).find(".capa-thumb-empleados").stop().animate({ backgroundColor: "#fff" }, 3000);
			   $(this).find(".capa-thumb-empleados").addClass ( "no-visible" );
			}
			
		);

}
function flechas_agenda (){
		
		$("#anterior-mes").hover (
  			
			function ( )
			{
				
				$(".mes-anterior").stop().animate({ opacity: 10}, 600);
    		
  			},	
			
			function ( )
			{
				$(".mes-anterior").stop().animate({ opacity: 0}, 600);
			   
			}
			
		);
		
		$("#agenda-mes").hover (
  			
			function ( )
			{
				
				
				$(".mes-siguiente").stop().animate({ opacity: 10}, 600);
    		
  			},	
			
			function ( )
			{
				
			   	$(".mes-siguiente").stop().animate({ opacity: 00}, 600)
			}
			
		);
		
}
		/* LINEA DEL TIEMPO */
		
function mostrar_linea_del_tiempo () {
		$mostrar_linea_tiempo = 0;
		
		$("#ico-linea-tiempo").click
		(
			function() 
		
				{
					if ( $mostrar_linea_tiempo == 0 ){
		
						$mostrar_linea_tiempo = 1;
			
						$("#linea-del-tiempo").removeClass('no-visible');
			
					}else{
		
						$mostrar_linea_tiempo = 0;
		
						$("#linea-del-tiempo").addClass('no-visible');
		
						}
	
				}
				
		)

}

/* FUNCTION HOVER THUMBS VIDEOSS */

function thumbs_hover( ) {
	
	$(".main-video .thumb").hover(function() {
			$(this).stop().animate({ opacity: 0.50}, 100);
			
			},function() {
			$(this).stop().animate({ opacity: 10 }, 800);
			
			})
	
}

function columna_hover( ) {
	
	$(".producto-col").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#EDEDED"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#D8D8D8"
				
				}, 1200)
			
			}
			
		)
	
}

function agenda_hover( ) {
	
	$(".agenda").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#ffeb00"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#F4F4F4"
				
				}, 1200)
			
			}
			
		)
	
}

function hover_title ( )
{
	$(".post h3 a" ).hover(function() {
		
			$( this ).animate(
			{ 
				borderTopColor: '#706F6F', borderLeftColor: '#706F6F', borderRightColor: '#706F6F', borderBottomColor: '#706F6F' }, 100);
			},function() 
			{
				$(this ).animate({ borderTopColor: '#f2f2f2', borderLeftColor: '#f2f2f2', borderRightColor: '#f2f2f2', borderBottomColor: '#f2f2f2' }, 600);
			})
}

function hover_post ( )
{
	$(".post" ).hover(function() {
			
			$(this).animate(
			{ 
				backgroundColor: '#f2f2f2'
			}, 100);
			$(this).find('h3 > a').animate({ borderTopColor: '#f2f2f2', borderLeftColor: '#f2f2f2', borderRightColor: '#f2f2f2', borderBottomColor: '#f2f2f2' }, 50);
			},function() 
			{
				$(this).animate({ backgroundColor: '#fff' }, 800);
				
				$(this).find('h3 > a').animate({ borderTopColor: '#fff', borderLeftColor: '#fff', borderRightColor: '#fff', borderBottomColor: '#fff' }, 400);
	
			})
			
			
}

function tooltips_header ( )
{
	/* TOOLTIPS HEADER */
	
		$("#utils-menu .link-twitter").hover(function () {
	
			$(".tooltip-twitter").stop(true).fadeTo("normal",1);
			}, 
			function () {
			$(".tooltip-twitter").fadeTo("normal",0);
		});
		
		$("#utils-menu .link-rss").hover(function () {
	
			$(".tooltip-rss").stop(true).fadeTo("normal",1);
			}, 
			function () {
			$(".tooltip-rss").fadeTo("normal",0);
		});
	
		$("#utils-menu .link-suscribite").hover(function () {
	
			$(".tooltip-suscribite").stop(true).fadeTo("normal",1);
			}, 
			function () {
			$(".tooltip-suscribite").fadeTo("normal",0);
		});
		
		$("#utils-menu .link-newsletter").hover(function () {
	
			$(".tooltip-newsletter").stop(true).fadeTo("normal",1);
			}, 
			function () {
			$(".tooltip-newsletter").fadeTo("normal",0);
		});
		
		$("#utils-menu .link-carrito").hover(function () {
	
			$(".tooltip-carrito").stop(true).fadeTo("normal",1);
			}, 
			function () {
			$(".tooltip-carrito").fadeTo("normal",0);
		});
		
		$( "#utils-menu .link-facebook").hover(function () {
	
			$(".tooltip-facebook").stop(true).fadeTo("normal",1);
			}, 
			function () {
			$(".tooltip-facebook").fadeTo("normal",0);
		}); 
		
	
}

function tooltip_video ( )
{
	
		$( "#facebook-tooltip .link-facebook").hover(function () {
			
			$(".facebook-tooltip").stop(true,true).fadeIn();
			}, 
			function () {
			$(".facebook-tooltip").stop(true,true).fadeOut();
		}); 
		
		$( "#twitter-tooltip .link-twitter").hover(function () {
			
			$(".twitter-tooltip").stop(true,true).fadeIn();
			}, 
			function () {
			$(".twitter-tooltip").stop(true,true).fadeOut();
		}); 
	
}
function tooltip_contacto ( )
{
	$( "#controls .icon-another").hover(function () {
			
			$(".recargar").stop(true,true).fadeIn();
			}, 
			function () {
			$(".recargar").stop(true,true).fadeOut();
		});
		
	$( "#controls .icon-audio").hover(function () {
			
			$(".audio").stop(true,true).fadeIn();
			}, 
			function () {
			$(".audio").stop(true,true).fadeOut();
		});
		
	$( "#controls .icon-help").hover(function () {
			
			$(".help").stop(true,true).fadeIn();
			}, 
			function () {
			$(".help").stop(true,true).fadeOut();
		});
	
	$("#controls a").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#706F6F"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#969696"
				
				}, 1200)
			
			}
			
		);
	
}
/**/
function icons_hover_header ( )
{
	$("#utils-menu .link-rss").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#e86a2d"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#3C3C3B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-twitter").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#3DB9EB"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#3C3C3B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-facebook").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#1D71B4"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#3C3C3B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-newsletter").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#000"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#3C3C3B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-carrito").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#FFED00"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#3C3C3B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-suscribite").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#575756"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#FFED00"
				
				}, 1200)
			
			}
			
		);
}
/* Video */
function icons_hover_header_video ( )
{
	$("#utils-menu .link-rss").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#e86a2d"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#1D1D1B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-twitter").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#3DB9EB"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#1D1D1B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-facebook").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#1D71B4"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#1D1D1B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-newsletter").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#000"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#1D1D1B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-carrito").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#FFED00"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#1D1D1B"
				
				}, 1200)
			
			}
			
		);
		
		$("#utils-menu .link-suscribite").hover(function() {
		
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#575756"
				
				}, 100)
			
			},function() {
				
			$(this).stop().animate(
				{ 
				
					backgroundColor: "#FFED00"
				
				}, 1200)
			
			}
			
		);
}
