jQuery(document).ready(function($) {
	a=parseFloat(400);// valor inccial para el background 1
	b=parseFloat(0);// valor inccial para el background 1
	c=parseFloat(400);// valor inccial para el background 2
	d=parseFloat(0);// valor inccial para el background 2
	e=parseFloat(400);// valor inccial para el background 3
	f=parseFloat(0);// valor inccial para el background 3
	g=parseFloat(400);// valor inccial para el background 4
	h=parseFloat(0);// valor inccial para el background 4
	i=parseFloat(0);// valor inccial para el background 4
	j=parseFloat(0);// valor inccial para el background 4
	k=parseFloat(0);// valor inccial para el background 4
	var scrollTop = $(window).scrollTop();			
	var scroll_actually= new Array();// identifica los valoares del background X y  Y
		
	$(window).scroll(function(){//this is not the cleanest way to do this, I'm just keeping it short.
		if(scrollTop>$(this).scrollTop()) // desplazamiento hacia arriba
		{
			if (getScrollTop()<=1600 && getScrollTop()>=0)// identyifica cuando la posicion del background_1 esta en scroll
			{
					a=a+35;// posicion del background1 decrementa en 35 pixeles
					b=b+10;// posicion de background1 decrementa en 15 pizeles 
					i=i+45;// posicion de background1 decrementa en 15 pizeles 
					$('.img_1').css('backgroundPosition', '50% '+a+'px');
					$('.img_8').css('backgroundPosition', '50% '+i+'px');
					$('.bk_0').css('backgroundPosition', '0 '+b+'px');		
			}
			if (getScrollTop()>=1850 && getScrollTop()<=3650)
			{
					c=c+35;// posicion del background2 decrementa en 35 pixeles
					d=d+10;// posicion del background2 decrementa en 35 pixeles
					j=j+45;// posicion de background1 decrementa en 15 pizeles 
					$('.img_2').css('backgroundPosition', '50% '+c+'px');
					$('.img_7').css('backgroundPosition', '50% '+j+'px');
					$('.bk_1').css('backgroundPosition', '0 '+d+'px');				
			}
			
			
			
			
			
			
			if (getScrollTop()>=3900 && getScrollTop()<=5300)
			{
					e=e+35;// posicion del background2 decrementa en 35 pixeles
					f=f+10;// posicion del background2 decrementa en 35 pixeles
					k=k+45;// posicion del background2 decrementa en 35 pixeles
					$('.img_3').css('backgroundPosition', '50% '+e+'px');
					$('.img_5').css('backgroundPosition', '50% '+k+'px');
					$('.bk_2').css('backgroundPosition', '0 '+f+'px');				
			}
			if (getScrollTop()>=5600 && getScrollTop()<=7850)
			{
					g=g+35;// posicion del background2 decrementa en 35 pixeles
					h=h+10;// posicion del background2 decrementa en 35 pixeles
					$('.img_4').css('backgroundPosition', '50% '+g+'px');
					
					$('.bk_3').css('backgroundPosition', '0 '+h+'px');				
			}
			
			
			
			
			
			
			
			
			
			
			
			
		}
		else
		{// desplazamiento hacia  abajo
			if (getScrollTop()>=0 && getScrollTop()<=1600)			
			{
				  a=a-35;// posicion del background1 incrementa en 35 pixeles
				  b=b-10;// posicion del background1 incrementa en 35 pixeles
				  i=i-45;// posicion de background1 decrementa en 15 pizeles 
				  $('.img_1').css('backgroundPosition', '50% '+a+'px');
				  $('.img_8').css('backgroundPosition', '50% '+i+'px');
				  $('.bk_0').css('backgroundPosition', '0 '+b+'px');				
		    }
				if (getScrollTop()>=1850 && getScrollTop()<=3650)			
			{
				  c=c-35;// posicion del background1 incrementa en 35 pixeles
				  d=d-10;// posicion del background1 incrementa en 35 pixeles
				  j=j-45;// posicion de background1 decrementa en 15 pizeles 
				  $('.img_2').css('backgroundPosition', '50% '+c+'px');
				  $('.img_7').css('backgroundPosition', '50% '+j+'px');
				  $('.bk_1').css('backgroundPosition', '0 '+d+'px');				
		    }
			
			
			
			
			
			
			
			if (getScrollTop()>=3900 && getScrollTop()<=5300)
			{
					e=e-35;// posicion del background2 decrementa en 35 pixeles
					f=f-10;// posicion del background2 decrementa en 35 pixeles
					k=k-45;// posicion del background2 decrementa en 35 pixeles
					$('.img_3').css('backgroundPosition', '50% '+e+'px');
					$('.img_5').css('backgroundPosition', '50% '+k+'px');
					$('.bk_2').css('backgroundPosition', '0 '+f+'px');				
			}
			
			if (getScrollTop()>=5600 && getScrollTop()<=7850)
			{
					g=g-35;// posicion del background2 decrementa en 35 pixeles
					h=h-10;// posicion del background2 decrementa en 35 pixeles
					$('.img_4').css('backgroundPosition', '50% '+g+'px');
					$('.bk_3').css('backgroundPosition', '0 '+h+'px');				
			}
			
			
			
			
			
			
			
			
			
			
			
	 	}
		if (getScrollTop()==0)// ajusta la posiciones y las reseatea en cero cuando hace scroll havciaa arriba
		{
			a=parseFloat(400);
			b=parseFloat(0);
			c=parseFloat(400);
			d=parseFloat(0);
			e=parseFloat(400);
			f=parseFloat(0);
			g=parseFloat(400);
			h=parseFloat(0);
			i=parseFloat(400);
			j=parseFloat(400);
			k=parseFloat(400);
			$('.bk_0').css('backgroundPosition', '0 0');	
			$('.bk_1').css('backgroundPosition', '0 0');
			$('.bk_2').css('backgroundPosition', '0 0');
			$('.bk_3').css('backgroundPosition', '0 0');
			$('.img_7').css('backgroundPosition', '50% '+400+'px');	
			$('.img_8').css('backgroundPosition', '50% '+400+'px');	
			$('.img_5').css('backgroundPosition', '50% '+400+'px');	
			$('.img_4').css('backgroundPosition', '50% '+400+'px');	
			$('.img_3').css('backgroundPosition', '50% '+400+'px');	
   		    $('.img_2').css('backgroundPosition', '50% '+400+'px');			
   		    $('.img_1').css('backgroundPosition', '50% '+400+'px');						
		}
	  scrollTop = $(this).scrollTop();		
	});
});
function getScrollTop(){ ///  verifica el calculo total en pixeles de toda la pagina

    if(typeof pageYOffset!= 'undefined'){
        //most browsers
        return pageYOffset;
    }
    else{
        var B= document.body; //IE 'quirks'
        var D= document.documentElement; //IE with doctype
        D= (D.clientHeight)? D: B;
        return D.scrollTop;
    }
}

