$(document).ready(function(){
	var deg=0;
    
	var images	= $('#stage img').removeClass('default').addClass('animationReady');
	var dim		= { width:images.width(),height:images.height()};
	var cnt = images.length;
	var centerX = $('#stage').width()/2;
	var centerY = $('#stage').height()/2 - dim.height/2;
	function rotate(step,total){
		deg+=step;

		var eSin,eCos,newWidth,newHeight,q;
		for(var i=0;i<cnt;i++){
			q = ((360/cnt)*i+deg)*Math.PI/180;
			eSin		= Math.sin(q);
			eCos		= Math.cos(q);
            q = (0.6+eSin*0.3);
			

			newWidth	= q*dim.width ;
			newHeight	= q*dim.height;
			//alert(koef); 
            dimtop = dim.height - newHeight-10;
			kk =newHeight;
			if(newHeight > 229 ){ 
			koef = 1;
			}else if(newHeight > 207 &&  newHeight < 229){
			koef = 30;
			}else{
			koef = 35;
			}
			newHeight = newHeight - koef;
			newWidth = (newHeight * 1.5) - koef;
			
			
			
			//alert(q);
            images.eq(i).css({
				top			: (centerY+0*eSin)+dimtop/2+(koef/2 ),
				left		: (centerX+390*eCos)-8,
				opacity		: 0.8+eSin*0.2,
				marginLeft	: -newWidth/2,
				zIndex		: Math.round(80+eSin*20)
			}).width(newWidth).height(newHeight);
			imgs = images.eq(i);
			$(imgs).attr("alt",centerX+250*eCos);
		}
		total-=Math.abs(step);
    	if(total <= 0){
		  setTimeout(function(){rotate(5,360/cnt)},6000);
          return false;
		} 
		setTimeout(function(){rotate(step,total)},85);
	}
	rotate(5,360/cnt);
});
