var anterior=1;
var tiempo=8000;
$(document).ready(function(){
	
	if (isset($('ul.gallery'))) {
	
	var url=window.location.href;
	if (url.indexOf("gal") != -1)
		window.location.href=window.location.href+"#http://www.purojabugo.es/img/upload/6-1250346935-thumb-450.JPG";
		
		
	jQuery(function($) {
		
		$('ul.gallery').galleria({
			history   : true, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);
				}
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Siguiente imagen >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});
	});



  //galeria de imagenes
	}
	$(".visor .imagenes img").fadeOut(1);
	$('#imagen_'+anterior).fadeIn(400);
	$('.visor .imagenes h4').fadeOut(1);
	$('.visor .imagenes h4').css({opacity: 0.7});
	$('#h4_'+anterior).fadeIn(400);
	$('#enlace_imagen_'+anterior).addClass('activo');
	


	$('#banner_tienda').click(function(){
		redireccionar('http://www.purojabugo.es/tienda/');
	});
	$('#banner_contacto').click(function(){
		redireccionar('http://www.purojabugo.es/es/contactar/');
	});
	$(".visor .submenu ul li").click(
		function () {
			$('.visor .submenu ul li').removeClass('activo');
			$(this).addClass('activo');
			$('#imagen_'+anterior).fadeOut(100);
			$('#h4_'+anterior).fadeOut(10);
			anterior=parseInt($(this).attr('class'));
			$('#imagen_'+anterior).fadeIn(400);
			$('#h4_'+anterior).fadeIn(400);
			$('.visor .imagenes h4').css({opacity: 0.7});
			tiempo=16000;
		}
	);

$('.error').hide(); 
$('#enviar').click(
	function () {
	 
	 $('.error').hide(); 
	 $("#enviar").val('enviando...');
	 
	 
	 var nombre = $("#nombre").val();
		if (nombre == "") {
      $("#nombre_error").show(50);
      $("input#nombre").focus();
	  $("#enviar").val('enviar');
      return false;
    }
		var email = $("#mail").val();
		if (email == "") {
      $("#mail_error").show(50);
      $("input#mail").focus();
	  $("#enviar").val('enviar');
      return false;
    }
		var telefono = $("#telefono").val();
		if (telefono == "") {
      $("#telefono_error").show(50);
      $("input#telefono").focus();
	  $("#enviar").val('enviar');
      return false;
    }
		var comentarios = $("#comentarios").val();
		if (comentarios == "") {
      $("#comentarios_error").show(50);
      $("input#comentarios").focus();
	  $("#enviar").val('enviar');
      return false;
    }
		
		var dataString = 'nombre='+ nombre + '&email=' + email + '&telefono=' + telefono + '&comentarios=' + comentarios;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "php/enviar_form.php",
      data: dataString,
      success: function(retorno) {
        $('#contacto').html("<div id='message'></div>");
        $('#message').html("<h2><img id='enviado' src='http://www.purojabugo.es/img/enviado-trans.png' /><br>"+retorno+"</h2>")
		.hide()
        .fadeIn(1500);
      }
     });
    return false;				   
});
});
	function siguienteImagen(){
		$('.visor .submenu ul li').removeClass('activo');
		$('#imagen_'+anterior).fadeOut(100);
		$('#h4_'+anterior).fadeOut(100);
		
		if (anterior>2) {
			anterior=1;	
		}
		else
		{
			anterior=parseInt(anterior)+1;	
		}
		
		$('#imagen_'+anterior).fadeIn(400);
		$('#h4_'+anterior).fadeIn(400);
		$('.visor .imagenes h4').css({opacity: 0.7});
		$('#enlace_imagen_'+anterior).addClass('activo');
		tiempo=8000;
	}
	
	setInterval("siguienteImagen()",tiempo);

	function redireccionar(pagina) 
	{
		location.href=pagina;
	} 

function isset(variable_name) {
    try {
         if (typeof(eval(variable_name)) != 'undefined')
         if (eval(variable_name) != null)
         return true;
     } catch(e) { }
    return false;
   }