$(document).ready(function(){
	
	$('#c .t h4').hover(
		function () {
			animate("ove", this, 0);
      }, function () {
			animate("out", this, 300);
      }
    );
	
	$('#c .t .o').hover(
		function () {
			animate("ove", this, 0);
      }, function () {
			animate("out", this, 300);
      }
    );
	
	$('#c .t p a').hover(
		function () {
			animate("ove", this, 0);
      }, function () {
			animate("out", this, 300);
      }
    );
	
	xpos = ($(window).width() * 0.7)  - 498;
	xpos2 = ($(window).width() * 0.6)  - 510;
	$('.o').css("right", xpos);
	
	$(window).resize(function() { 
	  xpos = ($(window).width() * 0.7)  - 498;
	  xpos2 = ($(window).width() * 0.6)  - 510;
	  
	  $('.o').css("right", xpos);
	  
	});
	
	$('.t .o').css({opacity: 0}); 	

	
});

var xpos;
var xpos2;


function animate(_a, _t, _d) {
	//alert("lol");
	
	var nt = $(_t).closest('li');
	var id = $(nt).attr('id').substring(2);
	
	//alert ( id );
	
	var na = false;
	var height;
	var top;
	var opacity;
	var opos;
	var paddingTop;
	var paddingRight;
	
	if(_a == "ove")
	{
		ove_array[id-1]++;
		
		if(id==1) {
			animate("", $('.t #t-2 .fir'), 100);
		} else {
			animate("", $('.t #t-1 .fir'), 100);
		}
		
	} else if(_a == "out") {
		out_array[id-1]++;
		
	}
	
	
	if(ove_array[id-1] > out_array[id-1]) {
		
		
		
		na = true;
		height = 130;
		top = 0;
		opacity = 1;
		paddingTop = 70;
		paddingRight = 40;
		//alert(xpos);
		
		opos = xpos2;

		
	} else if (ove_array[id-1] == out_array[id-1]) {
		
		
		
		na = true;
		
		height = 60;
		top = -70;
		opacity = 0;
		paddingTop = 0;
		paddingRight = 30;
		
		opos = xpos;
		
		//alert("lol" + ove_array[id-1] +"/"+ out_array[id-1]);
		
		
			
	}
	

	
	if(na==true) {
		
		//alert( ove_array[id-1] +"/" + out_array[id-1] );
		
		var delay = _d;
		
		$(nt).stop();
		$(nt).animate({
			opacity: 1
		}, _d, 'linear', function() {
			
			
			
			if(height < 100) {
				$(nt).removeClass("t-over"); 
			} else {
				$(nt).addClass("t-over"); 
			}
			
			
			$(".o", nt).stop();
			$(".o", nt).animate({
				height: height,
				opacity: opacity,
				right: opos
			}, 300, 'easeOutQuad', function() {
				
					
			});
			
			$('.test', nt).stop();
			$('.test', nt).animate({
				top: top
			}, 300, 'easeOutQuad', function() {
					
			});
			
			$('p .sec', nt).stop();
			$('p .sec', nt).animate({
				paddingLeft: paddingRight + "%"
			}, 300, 'easeOutQuad', function() {
				
			});
			
			$('p .fir', nt).stop();
			$('p .fir', nt).animate({
				paddingTop: paddingTop,
				paddingLeft: paddingRight + "%"
			}, 300, 'easeOutQuad', function() {
				
				
			});
			
			
			
		});
		
		
		
	}
	
	
}



var ove_array = new Array(0,0);
var out_array = new Array(0,0);


