	$(document).ready(function(){
							   
		cargapaso1();
		cargaautentificacion();
		
		$("#slider").easySlider({
			auto: true,
			continuous: true,
			nextId: "slider1next",
			prevId: "slider1prev"
		});

		anchoSCR = ( $(window).width() );
		altoSCR = ( $(window).height() );
		posXmitadSCR = ( anchoSCR /2 );
		posXSCR = posXmitadSCR -488;
		
		$("#naranjacentralbajo").css("left", posXmitadSCR -127);
		$("#naranjacentralbajo").show();
		$("#naranjacentral").css("left", posXmitadSCR -127);
		$("#naranjacentral").fadeTo(0,1);
		
		$("#cabeceraSector1").css("left", posXSCR + 14);
		$("#cabeceraSector2").css("left", posXSCR + 338);
		$("#cabeceraSector3").css("left", posXSCR + 663);
		
		$("#listaMenu").css("left", -40);
		$("#listaMenuSecundario").css("left", -40);
		$("#enlaceBlog").css("left", 0);

		$("#cabeceraSector1").fadeTo(1000,1);
		$("#cabeceraSector2").fadeTo(1000,1);
		$("#cabeceraSector3").fadeTo(1000,1);
				
		$(".enlaceMenu").mouseenter(function() {
			posXOpcionMenu = $(this).offset().left;
			posYOpcionMenu = $(this).offset().top;
			margenXNaranjita = 25;
			if(posXOpcionMenu > posXmitadSCR) {
				$("#naranjacentralimg").rotateAnimation(0);
			} else {
			$("#naranjacentralimg").rotateAnimation({animateAngle:-120, preservePosition: true});
			};
			$("#naranjita").css("left", margenXNaranjita - 20);
			$("#naranjita").css("top", posYOpcionMenu - 116);
			$(this).css("color", "#ffffff");
			$("#naranjita").fadeTo(750,1);
		});
		
		$(".enlaceMenu").mouseleave(function() {
			$(this).css("color", "#777777");
			$("#naranjita").stop(true, true).show(200);
			$("#naranjita").hide();
		});

		$(".enlaceMenu3").mouseenter(function() {
			posXOpcionMenu = $(this).offset().left;
			posYOpcionMenu = $(this).offset().top;
			margenXNaranjita = 25;
			if(posXOpcionMenu > posXmitadSCR) {
				$("#naranjacentralimg").rotateAnimation(0);
			} else {
			$("#naranjacentralimg").rotateAnimation({animateAngle:-120, preservePosition: true});
			};
			$("#naranjita3").css("left", margenXNaranjita - 20);
			$("#naranjita3").css("top", posYOpcionMenu - 116);
			$(this).css("color", "#ffffff");
			$("#naranjita3").fadeTo(750,1);
		});
		
		$(".enlaceMenu3").mouseleave(function() {
			$(this).css("color", "#777777");
			$("#naranjita3").stop(true, true).show(200);
			$("#naranjita3").hide();
		});
		
		$("#enlaceBlog").mouseover(function() {
			$("#naranjacentralimg").rotateAnimation(-60);
		});

		$("#slider").mouseover(function() {
			$("#naranjacentralimg").rotateAnimation(-190);
		});
		
		$(".imagensector4").fancybox({
			'overlayShow'	: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		
		//altoImgFondo = $("#fondoIMG").height();
		//anchoImgFondo = $("#fondoIMG").width();
		//$("#fondoIMG").css("height", altoSCR);
		//$("#fondoIMG").css("width", ((altoSCR/altoImgFondo)*anchoImgFondo));
		//$("#fondo").css("left", posXmitadSCR);

		posOfertaIzq = ( $(window).width() -330 );
						   
		$('#ofertatortas').animate({left: posOfertaIzq -20}, 1500, 'swing');

		$("#promoHorz").css("left", posXmitadSCR-100);

		$("#logoagriculturasostenible").css("left", posXmitadSCR+380);
		
		$("#calendario").datepicker({
   			onChangeMonthYear: function(year, month, inst) {
				mes = month.toString();
				if(mes.length == 1) { mes = "0"+mes; };
				fecha = year+"/"+mes+"/01";
				muestraBlog(fecha);
			},onSelect: function(fecha, inst) {
				muestraBlog(fecha);
			},dateFormat: 'yy-mm-dd'
		});

		cargaTienda();

    var i;
    //alert(document.images.length);
    for(i in document.images){
      if(document.images[i].src){
        var imgSrc = document.images[i].src;
        if(imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG'){
        document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
        }
      }
    }   
		

	});

function muestraarticulo(seccion) {
	$.ajax({
		type: "GET",
		url: "articulos.php",
		data: "sc="+seccion,
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					scroll(0,760);
					$('#gallery').galleria({
        				width:500,
        				height:500,
						autoplay: 2000
    				});				
		}
	});
}

function muestracontacto() {
	$.ajax({
		type: "GET",
		url: "contacto.php",
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					scroll(0,760);
					cargarmapa();
		}
	});
}

function muestraficha(seccion) {
	$.ajax({
		type: "GET",
		url: "fichas.php",
		data: "sc="+seccion,
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					scroll(0,760);
		}
	});
}

function registroUsuario(modo,n,rf) {
	if(modo == 1) {
		cadenaurl = "fusuarios.php?n="+n+"&rf="+rf;
	} else {
		cadenaurl = "fusuarios.php";
	};
	$.ajax({
		type: "GET",
		url: cadenaurl,
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					scroll(0,760);
		}
	});
}

function enviaralta(modo,n,rf) {
	if(document.getElementById('nombre')) {
		cadena="nombre="+encodeURIComponent(document.getElementById('nombre').value)+"&cif="+encodeURIComponent(document.getElementById('cif').value)+"&empresa="+encodeURIComponent(document.getElementById('empresa').value)+"&direccion="+encodeURIComponent(document.getElementById('direccion').value)+"&cp="+encodeURIComponent(document.getElementById('cp').value)+"&poblacion="+encodeURIComponent(document.getElementById('poblacion').value)+"&provincia="+encodeURIComponent(document.getElementById('provincia').value)+"&pais="+encodeURIComponent(document.getElementById('pais').value)+"&email="+encodeURIComponent(document.getElementById('email').value)+"&web="+encodeURIComponent(document.getElementById('web').value)+"&telefono="+encodeURIComponent(document.getElementById('telefono').value)+"&fax="+encodeURIComponent(document.getElementById('fax').value)+"&movil="+encodeURIComponent(document.getElementById('movil').value)+"&observaciones="+encodeURIComponent(document.getElementById('observaciones').value)+"&autusuario="+encodeURIComponent(document.getElementById('autusuario').value)+"&autclave="+encodeURIComponent(document.getElementById('autclave').value)+"&modo="+modo+"&n="+n+"&rf="+rf;
	};

	$.ajax({
		type: "POST",
		url: "fusuariosprocesado.php",
		data: cadena,
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					scroll(0,760);
		}
	});
}

function repetirAlta(modo,resultado,cr) {
	$.ajax({
		type: "GET",
		url: "fusuarios.php",
		data: resultado+"&cr="+cr,
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					scroll(0,760);
		}
	});
}

function muestraBlog(entrada) {
	fecha = $("#calendario").datepicker("getDate");
	dia = fecha.getDate().toString();
	mestmp = (fecha.getMonth()) +1;
	mes = mestmp.toString();
	anno = fecha.getFullYear().toString();
	if(mes.length == 1) { mes = "0"+mes; };
	if(dia.length == 1) { dia = "0"+dia; };
	fecha = anno+"/"+mes+"/"+dia;
	document.getElementById("articulos").innerHTML = "";
	muestraBlogTemas(fecha);
	muestraBlogContenido(fecha);
	$("#blogNaranjas").show();
}

function muestraBlogTemas(entrada) {
	$.ajax({
		type: "GET",
		url: "blog_temas.php",
		data: "en="+entrada,
		success: function(datos) {
					$("#blogTemas").html(datos);
					$("#copyright").hide();
					$("html, body").animate({scrollTop: 760}, 'slow', 'swing');
		}
	});
}

function muestraBlogContenido(entrada) {
	$.ajax({
		type: "GET",
		url: "blog_contenido.php",
		data: "en="+entrada,
		success: function(datos) {
					$("#contenidoBlog").html(datos);
					$("#copyright").hide();
					$("html, body").animate({scrollTop: 760}, 'slow', 'swing');
					$(".imagenesBlog").fancybox({
						'overlayShow'	: false,
						'transitionIn'	: 'elastic',
						'transitionOut'	: 'elastic'
					});
		}
	});
}

function ocultaBlog() {
	$("#blogNaranjas").hide();
}

function usuariosMisDatos() {
	$.ajax({
		type: "GET",
		url: "fusuarios.php",
		data: "mod=1",
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					$("html, body").animate({scrollTop: 760}, 'slow', 'swing');
		}
	});
}

function enviarmodificacion(modo,n,rf) {
	if(document.getElementById('nombre')) {
		cadena="nombre="+encodeURIComponent(document.getElementById('nombre').value)+"&cif="+encodeURIComponent(document.getElementById('cif').value)+"&empresa="+encodeURIComponent(document.getElementById('empresa').value)+"&direccion="+encodeURIComponent(document.getElementById('direccion').value)+"&cp="+encodeURIComponent(document.getElementById('cp').value)+"&poblacion="+encodeURIComponent(document.getElementById('poblacion').value)+"&provincia="+encodeURIComponent(document.getElementById('provincia').value)+"&pais="+encodeURIComponent(document.getElementById('pais').value)+"&email="+encodeURIComponent(document.getElementById('email').value)+"&web="+encodeURIComponent(document.getElementById('web').value)+"&telefono="+encodeURIComponent(document.getElementById('telefono').value)+"&fax="+encodeURIComponent(document.getElementById('fax').value)+"&movil="+encodeURIComponent(document.getElementById('movil').value)+"&observaciones="+encodeURIComponent(document.getElementById('observaciones').value)+"&autusuario="+encodeURIComponent(document.getElementById('autusuario').value)+"&autclave="+encodeURIComponent(document.getElementById('autclave').value)+"&modo="+modo+"&n="+n+"&rf="+rf;
	};

	$.ajax({
		type: "POST",
		url: "fusuariosprocesado.php",
		data: cadena,
		success: function(datos) {
					$("#articulos").html(datos);
					ocultaBlog();
					$("#copyright").hide();
					$("html, body").animate({scrollTop: 760}, 'slow', 'swing');
		}
	});
}

function compraclasica() {
	ocultaBlog();
	document.getElementById("articulos").innerHTML = "";
	$("html, body").animate({scrollTop: 760}, 'slow', 'swing');
}

