// JavaScript Document
// Front-End : Ruan Candido / ruan1808@gmail.com
$(document).ready (function() {

	$("#list-redes li").mouseover(function(){
		$("#list-redes li").animate({ opacity:0.5 },{ queue:false, duration:300})
		$(this).stop().animate({opacity:1},{ queue:false, duration:300})
	});
	
	$("#list-redes li").mouseout(function(){
		$(this).animate({opacity:1},{ queue:false, duration:300})
		$("#list-redes li").stop().animate({opacity:1},{ queue:false, duration:300})
	});

//	$("#ft .iconBg").mouseover(function(){
		//$("#ft .iconBg").animate({ opacity:1 },{ queue:false, duration:300})
//		atualIcon = $("#ft .iconBg").index(this);
//		console.debug(atualIcon , " HOVER");
//		$("#ft .iconBg").css( {backgroundPosition: '0 -321px'} )
//		$(this).animate({backgroundPosition: '0 -411px'},{easing:"easeOutExpo", duration:700})
//	});
	
//	$("#ft .iconBg").mouseout(function(){
//		console.debug(atualIcon , $("#ft").index(".iconBg:hover") );
//		$(this).animate({backgroundPosition:'0 -501px'},{easing:"easeOutExpo", duration:700})
		//$("#ft .iconBg").stop().animate({opacity:1 },{ queue:false, duration:300})
//	});
	
	var atual;
	var anterior = 0;
	var anterior2;
	var positionOut = 0;
	function animateTo(a){
		
		switch (a){
			
			case 0:
				if (a >= anterior) {
					$("#ft .iconBg").css( {backgroundPosition: '0 -501px'} );
					$("#ft .iconBg:eq(" + a + ")").stop().animate({
						backgroundPosition: '0 -411px'
					}, {
						easing: "easeOutExpo",
						duration: 700
					})
					
				}else if(a < anterior){
					
					$("#ft .iconBg").css( {backgroundPosition: '0 -321px'} );
					$("#ft .iconBg:eq(" + a + ")").stop().animate({
						backgroundPosition: '0 -411px'
					}, {
						easing: "easeOutExpo",
						duration: 700
					})
				}
			break;
			case 1:
				if (a >= anterior) {
				$("#ft .iconBg").css( {backgroundPosition: '0 -501px'} );
					$("#ft .iconBg:eq(" + a + ")").stop().animate({
						backgroundPosition: '0 -411px'
					}, {
						easing: "easeOutExpo",
						duration: 700
					})
				}else if(a < anterior){
					
					$("#ft .iconBg").css( {backgroundPosition: '0 -321px'} );
					$("#ft .iconBg:eq(" + a + ")").stop().animate({
						backgroundPosition: '0 -411px'
					}, {
						easing: "easeOutExpo",
						duration: 700
					})
				}
			break;			
			case 2:
				if (a > anterior) {
				$("#ft .iconBg").css( {backgroundPosition: '0 -501px'} );
					$("#ft .iconBg:eq(" + a + ")").stop().animate({
						backgroundPosition: '0 -411px'
					}, {
						easing: "easeOutExpo",
						duration: 700
					})
				}else if(a <= anterior){
					
					$("#ft .iconBg").css( {backgroundPosition: '0 -321px'} );
					$("#ft .iconBg:eq(" + a + ")").stop().animate({
						backgroundPosition: '0 -411px'
					}, {
						easing: "easeOutExpo",
						duration: 700
					})
				}
			break;
		}
		anterior = a;
	}
	function animateOut(a,anterior , positionOut){
		
		
		switch (a){
			
			case 0:
				if ( anterior < positionOut-80){
					
					$("#ft .iconBg:eq(" + a + ")").stop().animate( {backgroundPosition: '0 -321px'},
														{easing: "easeOutExpo",duration: 700})			
				}else{
				
					$("#ft .iconBg:eq(" + a + ")").stop().animate({backgroundPosition: '0 -501px'},
													   {easing: "easeOutExpo",duration: 700})	
				}
				
			break;
			case 1:
			
				if ( anterior < positionOut-40){
					
					$("#ft .iconBg:eq(" + a + ")").stop().animate( {backgroundPosition: '0 -321px'},
														{easing: "easeOutExpo",duration: 700})			
				}else{
				
					$("#ft .iconBg:eq(" + a + ")").stop().animate({backgroundPosition: '0 -501px'},
													   {easing: "easeOutExpo",duration: 700})	
				}
				
			break;			
			case 2:
				if ( anterior < positionOut-10){
					
					$("#ft .iconBg:eq(" + a + ")").stop().animate( {backgroundPosition: '0 -321px'},
														{easing: "easeOutExpo",duration: 700})			
				}else{
				
					$("#ft .iconBg:eq(" + a + ")").stop().animate({backgroundPosition: '0 -501px'},
													   {easing: "easeOutExpo",duration: 700})	
				}
			break;
		}
	}

			$("#ft .iconBg").mouseover(function(){

				atual = $("#ft .iconBg").index(this);
				animateTo(atual);
			});
				
			
			$("#ft .iconBg").mouseout(function(){
			
				$("#ft").mousemove(function(a){
					
					positionOut = a.pageY
					return positionOut;
				})
				anterior2 = $(this).offset().top
				animateOut(atual,anterior2,positionOut);
				
			
				/*anterior = atual;
				
				$("#ft .iconBg").mouseover(function(){
					atual = $("#ft .iconBg").index(this);
					console.debug("atual Out " , atual , "anterior Out " , anterior);
				})
				
				*/
			});
	});

