//<![CDATA[	
$amount = Math.round(($("#gallery .listado-producto li").length)/2);
$incremental = 0;
function upGallery() {
	if (($amount-$incremental) > 5) {
		$incremental++;
		$("#gallery .listado-producto").animate({
			"top": ((74*$incremental)*(-1))
		}, "swing");
	}
}
function downGallery() {
	$actualTop = $("#gallery .listado-producto").css("top");
	if ($incremental > 0) {
		$actualTopInt = ($actualTop.replace("px", ""))*1;
		$("#gallery .listado-producto").animate({
			"top": ($actualTopInt)+(74)
		}, "swing");
		$incremental--;
	}
}
/* Inicialización en español para la extensión 'UI date picker' para jQuery. */
/* Traducido por Vester (xvester [en] gmail [punto] com). */
jQuery(function($){
   $.datepicker.regional['es'] = {
      closeText: 'Cerrar',
      prevText: '<Ant',
      nextText: 'Sig>',
      currentText: 'Hoy',
      monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
      monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
      dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
      dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sab'],
      dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sa'],
      weekHeader: 'Sm',
      dateFormat: 'dd/mm/yy',
      firstDay: 1,
      isRTL: false,
      showMonthAfterYear: false,
      yearSuffix: ''};
   $.datepicker.setDefaults($.datepicker.regional['es']);
}); 

/* Devuelve si una cadena "dd/mm/yyyy" o
"dd-mm-yyyy" o "dd.mm.yyyy" es una fecha válida */
function esFecha (strValue)
{
	//check to see if its in a correct format
	//var objRegExp = '/^d{1,2}(-|/|.)d{1,2}(-|/|.)d{4}$/';
	var objRegExp = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/;

	if(! objRegExp.test(strValue)){
		
		return false; //doesn't match pattern, bad date
	}else {
		var strSeparator = strValue.substring(2,3)
		//create a lookup for months not equal to Feb.
		var arrayDate = strValue.split(strSeparator);

		var arrayLookup = { '01' : 31,'03' : 31,
							'04' : 30,'05' : 31,
					      '06' : 30,'07' : 31,
					      '08' : 31,'09' : 30,
					      '10' : 31,'11' : 30,'12' : 31
		}

		var intDay = parseInt(arrayDate[0],10);
		var intMonth = parseInt(arrayDate[1],10);
		var intYear = parseInt(arrayDate[2],10);
		var fechaHoy=new Date();
		var anoHoy=fechaHoy.getFullYear();
		//check if month value and day value agree

		if (arrayLookup[arrayDate[1]] != null) {
			if (intDay <= arrayLookup[arrayDate[1]] && intDay != 0
					&& intYear > 1900 && intYear <= anoHoy)
				return true;     //found in lookup table, good date
		}

		//check for February (bugfix 20050322)
		//bugfix for parseInt kevin
		//bugfix biss year  O.Jp Voutat

		if (intMonth == 2) {
			var intYear = parseInt(arrayDate[2]);

			if (intDay > 0 && intDay < 29) {
				return true;
			}
			else if (intDay == 29) {
				if ((intYear % 4 == 0) && (intYear % 100 != 0) || (intYear % 400 == 0)) {
					// year div by 4 and ((not div by 100) or div by 400) ->ok
					return true;
				}
			}
		}
		
		
	}
	return false; //any other values, bad date
}
$(document).ready(function() { 
	
	$("a.lightbox").fancybox({
		'overlayShow'			: false,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'			: 500,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack'
	}); 
	$("a.external").click( function() {
        window.open( $(this).attr("href") );
    	return false;
    });
    $("#gallery .listado-producto li:nth-child(2n)").css("margin", "0");
    $("#gallery .listado-producto a").each(function() {
		$(this).click(function() {
			$imagen = $(this).attr("href");
			$descripcion = $(this).parent().parent().find(".galeria-descripcion").text();
			$nombre = $(this).parent().parent().find("h3").html();
	
			$("#gallery #main-image h3").fadeOut("slow", function() { $("#gallery #main-image h3").text(''); });
			$("#gallery #main-image .main-descripcion").fadeOut("slow", function() { $("#gallery #main-image .main-descripcion").text(''); });
			$("#gallery #main-image a").fadeOut(
				750, function() {
				$("#gallery #main-image a img").attr("src", $imagen);
				$("#gallery #main-image a").fadeIn(750);		
				$("#gallery #main-image a").attr("href", $imagen.replace('mid\/', 'slideshow\/'));
				$("#gallery #main-image h3").html($nombre);
				$("#gallery #main-image h3").fadeIn();
				$("#gallery #main-image .main-descripcion").text($descripcion);
				$("#gallery #main-image .main-descripcion").fadeIn();
			});
	    	return false;		
		});
    })
	$("#gallery").append('<p class="gallery-controls"><a href="javascript:;" onclick="downGallery();" class="up"><img src="/images/gallery-scroll-buttons.gif" alt="Subir" /></a><a href="javascript:;" onclick="upGallery();" class="down"><img src="/images/gallery-scroll-buttons.gif" alt="Bajar" /></a></p>');
	
	/*****************************************************/
	/*				   BUSCADOR RAPIDO					 */
	/*****************************************************/

	$('#BusquedaRapida').click(function(event){		
		event.preventDefault();
		mi_input = $(this).parent().find('.input_buscador').val();
		
		if(mi_input.length==0){
			alert('Inserte algun parametro de busqueda');
		}else if(mi_input.length<=3){
			alert('Parametro de busqueda incorrecto. (Min 3 carac.)');
		}else{
			$('#FrmBuscadorRapido').submit();
		}
	});
	
	/*****************************************************/
	/*				  PRECIO PRODUCTO					 */
	/*****************************************************/
    
   $(".precio").each(function() {
	   
	   var id = $(this).parent().find('.productoId').val();
	   if(id!=undefined){
		   var precio = $(this);			//Dentro del each el this no haria referencia a la capa del precio
		   var iva = $(this).parent().find('.iva');
		   
		   $.getJSON(DOMINIO+"ajax/precio.php", {id:id}, function(data) {
			   $.each(data, function(index, array) {
				   precio.html( array['precio'] );
				   iva.html( array['iva'] );			   
			   });		   
		   });	
		   //$(this).load(DOMINIO+"ajax/precio.php #precio",{ id:id })		
	   }
    });
   
   	/*****************************************************/
	/*				  		CARRITO					 	*/
	/*****************************************************/
   $('.unidades_carrito').keyup(function(event){
		setTimeout(function(){ $(".mensajes").fadeIn(3000).fadeOut(5000)}, 500);
		precio_linea = parseFloat ( $(this).parent().parent().parent().find(".car_precio_linea").html() );
		dto_linea = parseFloat ($(this).parent().parent().parent().find(".car_dto_linea").html() );

		total_linea = $(this).val() * precio_linea;
		
		if(dto_linea.length>0 && dto_linea != 0 ){
			
			total_linea = total_linea * ((100 - dto_linea)/100);
		}

		$(this).parent().parent().parent().find(".car_total_linea").attr("value", total_linea) ;

		var cantidades='';
		$('.unidades_carrito').each(function() {
			if(cantidades.length = 0){
				cantidades = $(this).val();
			}else{
				cantidades += ","+$(this).val();
			}
			
			if($(this).parent().parent().find(".enviadas_carrito").val() < $(this).val())
				$(this).parent().parent().find(".enviadas_carrito").attr("value",$(this).val());
		});

		var total_pedido = 0;
		$('.car_total_linea').each(function() {
			
			total_pedido += parseFloat ($(this).val() );
			
		});
			
		$('#car_total_pedido').html(Math.round((total_pedido)*100)/100); 
		$('#cantidades').attr("value", cantidades); 
		$('#car_total').attr("value", total_pedido); 

	});
   
   $('.FrmEliminarProd').submit(function(event){
		if(confirm('\u00BFEsta seguro de querer eliminar el producto del carrito?'))
			return true;
		else
			return false;
	});
   
   /*****************************************************/
	/*				HISTORICO DE PEDIDOS				*/
	/****************************************************/
   //Pedidos Web:
	$('.estadoLinWeb').each(function() {		
		$(this).load(DOMINIO+"ajax/orderStatusLinea.php",{ DL_PieceBC:$(this).parent().find('.DL_PieceBC').val(), DL_Ligne:$(this).parent().find('.DL_Ligne').val() })	
	});
   
});


//]]>	

<!-- fin scripts galeria imagenes -->


<!-- CAPAS FLOTANTES -->

<!--
//Funcion que muestra el div en la posicion del mouse
function showdiv(event)
{
	//determina un margen de pixels del div al raton
	margin=5;

	//La variable IE determina si estamos utilizando IE
	var IE = document.all?true:false;
	//Si no utilizamos IE capturamos el evento del mouse
	if (!IE) document.captureEvents(Event.MOUSEMOVE)

	var tempX = 0;
	var tempY = 0;
/*
	if(IE)
	{ //para IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}else{ //para netscape
		tempX = event.pageX;
		tempY = event.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
*/
	//modificamos el valor del id posicion para indicar la posicion del mouse
	//document.getElementById('posicion').innerHTML="PosX = "+tempX+" | PosY = "+tempY;

	document.getElementById('flotante').style.top = (tempY+margin);
	document.getElementById('flotante').style.left = (tempX+margin);
	document.getElementById('flotante').style.display='block';
	return;
}


-->
