////////////радиусы элипса траектории
var Rx=380;
var Ry=60;
////////////абсолютные координаты центра врещения
var delta_x=500;
var delta_y=400;
////////////массивы точек верхней дуги вращения
var top_x=Array();
var top_y=Array();
////////////массивы точек нижней дуги вращения
var bottom_x=Array();
var bottom_y=Array();
///////////изначальные размеры елементов
var b_element_start_width=510;
var b_element_start_height=553;
var s_element_start_width=190;
var s_element_start_height=206;

var ss_element_start_width=100;
var ss_element_start_height=105;

////////////процентные соотношения координаты точки маршрута, относительно начала координат объекта
var object_dx=0.5;
var object_dy=0.83;

///////////массивы размеров элементов в точках маршрута для нижней дуги
var element_width=Array();
var element_height=Array();
////////////массив координат left, top для объектов на всем маршруте для нижней дуги
var objects_left=Array();
var objects_top=Array();

///////////массивы размеров элементов в точках маршрута для нижней дуги
var top_element_width=Array();
var top_element_height=Array();
////////////массив координат left, top для объектов на всем маршруте для нижней дуги
var top_objects_left=Array();
var top_objects_top=Array();
////////////прозрачность
var bottom_pr=Array();
////////////массив объектов экрана
var objects=Array();
////////////шаг обработки
step=60;
time_out=10;
////////////прозрачность
alfa=0.5;
////////////
hide_top_x_left=150;
hide_top_x_right=Rx-60;
/////////временные переменные
var tmp1=0;
var el;
var is_run=false;
var r_n=0;
var b_n=1;
var l_n=2;


function top_image_left() {
	top_img.src=objects_arr[r_n].src_b.src;
	l_n=b_n;
	b_n=r_n;
	r_n++;
	if (r_n>all_count) r_n=0;
	top_img.src=objects_arr[r_n].src_b.src; ///потом оно станет right
	top_img.alt=objects_arr[r_n].oname;
	
}

function top_image_right() {
	r_n=b_n;
	b_n=l_n;
	l_n--;
	if (l_n<0) l_n=all_count;
	top_img.src=objects_arr[l_n].src_b.src; ///потом оно станет left
	top_img.alt=objects_arr[l_n].oname;
}

function init() {
	///////инициализация точек маршрута
	var c=0;
	for (x=(-1)*Rx; x<=Rx; x++) {
		bottom_x[c]=x+delta_x;
		bottom_y[c]=Math.round(Math.sqrt(1-((x*x)/(Rx*Rx)))*Ry)+delta_y;	
		
		top_x[c]=x+delta_x;
		top_y[c]=delta_y-Math.round(Math.sqrt(1-((x*x)/(Rx*Rx)))*Ry);	

		c++;
	}
	//alert(c);
	/////////////////////////////////для нижней дуги
	/////расчет размеров элементов по всем точкам маршрута нижней дуги
	dx=(b_element_start_width-s_element_start_width)/Rx;
	dy=(b_element_start_height-s_element_start_height)/Rx;
	
	element_width[0]=s_element_start_width;
	element_height[0]=s_element_start_height;
	bottom_pr[0]=alfa;
	for(i=1;i<=Rx;i++) {
		
		element_width[i]=Math.round(s_element_start_width+dx*i);
		element_height[i]=Math.round(s_element_start_height+dy*i);
		bottom_pr[i]=(i/Rx)/2+alfa;
	}
	
	element_width[Rx]=b_element_start_width;
	element_height[Rx]=b_element_start_height;
	bottom_pr[Rx]=1;
	
	for(i=Rx+1;i<(2*Rx);i++) {
		element_width[i]=Math.round(b_element_start_width-(dx*(i-Rx)));
		element_height[i]=Math.round(b_element_start_height-(dy*(i-Rx)));
		bottom_pr[i]=((2*Rx-i)/Rx)/2+alfa;
	}
	
	element_width[(2*Rx)]=s_element_start_width;
	element_height[(2*Rx)]=s_element_start_height;
	bottom_pr[(2*Rx)]=alfa;
	
	////////////расчет координат left, top для объектов на всем маршруте
	for(i=0;i<element_width.length;i++) {
		objects_left[i]=Math.round(bottom_x[i]-(element_width[i]*object_dx));
		objects_top[i]=Math.round(bottom_y[i]-(element_height[i]*object_dy));
	}
	/////////////////////////////////////////////////
	/////////////////////////////////////////////////
	/////////////////////////////////////////////////
	/////////////////////////////////////////////////
	/////////////////////////////////////////////////
	
	/////////////////////////////////для верхней дуги
	/////расчет размеров элементов по всем точкам маршрута верхней дуги
	dx=(s_element_start_width-ss_element_start_width)/Rx;
	dy=(s_element_start_height-ss_element_start_height)/Rx;
	
	top_element_width[0]=s_element_start_width;
	top_element_height[0]=s_element_start_height;
	for(i=1;i<Rx;i++) {
		
		top_element_width[i]=Math.round(s_element_start_width-dx*i);
		top_element_height[i]=Math.round(s_element_start_height-dy*i);
	}
	
	top_element_width[Rx]=ss_element_start_width;
	top_element_height[Rx]=ss_element_start_height;
	
	for(i=Rx+1;i<(2*Rx);i++) {
		top_element_width[i]=Math.round(ss_element_start_width+(dx*(i-Rx)));
		top_element_height[i]=Math.round(ss_element_start_height+(dy*(i-Rx)));
	}
	
	top_element_width[(2*Rx)]=s_element_start_width;
	top_element_height[(2*Rx)]=s_element_start_height;
	
	
	////////////расчет координат left, top для объектов на всем маршруте
	for(i=0;i<top_element_width.length;i++) {
		top_objects_left[i]=Math.round(top_x[i]-(top_element_width[i]*object_dx));
		top_objects_top[i]=Math.round(top_y[i]-(top_element_height[i]*object_dy));
	}
	/////////////////////////////////////////////////
	
	left_object=document.getElementById('kv1');
	bottom_object=document.getElementById('kv2');
	right_object=document.getElementById('kv3');
	top_object=document.getElementById('kv4');
	
	
	left_img=document.getElementById('i1');
	bottom_img=document.getElementById('i2');
	right_img=document.getElementById('i3');
	top_img=document.getElementById('i4');
	
	
	left_link=document.getElementById('left_link1');
	
	right_link=document.getElementById('right_link1');
	center_title=document.getElementById('center_title1');
	left_title=document.getElementById('center_title1');
	right_title=document.getElementById('center_title1');
	
	
	
	
	
	center_description=document.getElementById('center_description1');
	center_params=document.getElementById('center_params1');
	center_link=document.getElementById('center_link1');
	
	
	
	l_n=all_count-1;
	left_img.src=objects_arr[l_n].src_b.src;
	left_link.innerHTML=objects_arr[l_n].oname;
	left_img.alt=objects_arr[l_n].oname;
	
	r_n=0;
	right_img.src=objects_arr[r_n].src_b.src;
	right_link.innerHTML=objects_arr[r_n].oname;
	right_img.alt=objects_arr[r_n].src_b.oname;
	
	b_n=all_count;
	bottom_img.src=objects_arr[b_n].src_b.src;
	bottom_img.alt=objects_arr[b_n].oname;
	
	center_title.innerHTML=objects_arr[b_n].oname;
	
	center_link.innerHTML=objects_arr[b_n].link_title;
	center_link.href=objects_arr[b_n].link_href;
	
	
	center_params.innerHTML=objects_arr[b_n].params;
	center_description.innerHTML=objects_arr[b_n].text;
	
	top_img.src=objects_arr[1].src_b.src;
	
	
	Element.setOpacity('i1', alfa);
	Element.setOpacity('i3', alfa);
	Element.setOpacity('i4', alfa);
	top_object.style.display='none';
	document.getElementById('begunok').style.display='none';
	Element.show($('header_promo_block'));
	Element.show($('main2'));
	////////////////////////////////////////////////
	el=document.getElementById('tmp_id');
}


function _rotate_left(pos) {
	if (pos<=Rx) {
		///меняем Z-Index
		if (pos==1) {
			top_image_left();
			right_img.onclick=function() {return false;}
			left_img.onclick=function() {return false;}
			bottom_img.onclick=function() {return false;}
			top_img.onclick=function() {return false;}
			left_img.style.cursor="default";
			right_img.style.cursor="default";
			bottom_img.style.cursor="default";
			top_img.style.cursor="default";
			
			///скрываем надписи
			new Effect.Opacity('left_title1', { from: 1.0, to: 0, duration: 0.2 });
			new Effect.Opacity('right_title1', { from: 1.0, to: 0, duration: 0.2 });
			new Effect.Opacity('center_title1', { from: 1.0, to: 0, duration: 0.2 });
			
			//new Effect.Opacity(right_img, { from: alfa, to: 1, duration: 0.3 });
			
			//new Effect.Opacity(bottom_img, { from: 1.0, to: alfa, duration: 0.9 });
			left_object.style.zIndex="500";	
			
			
		}
		if (pos>hide_top_x_left && left_object.style.display!='none') left_object.style.display='none';
		if (pos>hide_top_x_right && top_object.style.display=='none') top_object.style.display='inline';
		///перемещаем объекты
		
		left_object.style.left=top_objects_left[pos]+"px";
		left_object.style.top=top_objects_top[pos]+"px";
		
		
		bottom_object.style.left=objects_left[(Rx-pos)]+"px";
		bottom_object.style.top=objects_top[(Rx-pos)]+"px";
		
		Element.setOpacity(bottom_img, bottom_pr[(Rx-pos)]);
		
		right_object.style.left=objects_left[(2*Rx-pos)]+"px";
		right_object.style.top=objects_top[(2*Rx-pos)]+"px";
		
		Element.setOpacity(right_img, bottom_pr[(2*Rx-pos)]);
		
		top_object.style.left=top_objects_left[(Rx+pos)]+"px";
		top_object.style.top=top_objects_top[(Rx+pos)]+"px";
		
		///изменяем размеры
		
		left_object.style.width=top_element_width[pos]+"px";
		left_object.style.height=top_element_height[pos]+"px";
		
		bottom_object.style.width=element_width[(Rx-pos)]+"px";
		bottom_object.style.height=element_height[(Rx-pos)]+"px";
		
		right_object.style.width=element_width[(2*Rx-pos)]+"px";
		right_object.style.height=element_height[(2*Rx-pos)]+"px";
		
		top_object.style.width=top_element_width[(Rx+pos)]+"px";
		top_object.style.height=top_element_height[(Rx+pos)]+"px";
		
		///изменяем картинки
		left_img.style.width=top_element_width[pos]+"px";
		left_img.style.height=top_element_height[pos]+"px";
		
		bottom_img.style.width=element_width[(Rx-pos)]+"px";
		bottom_img.style.height=element_height[(Rx-pos)]+"px";
		
		right_img.style.width=element_width[(2*Rx-pos)]+"px";
		right_img.style.height=element_height[(2*Rx-pos)]+"px";
		
		top_img.style.width=top_element_width[(Rx+pos)]+"px";
		top_img.style.height=top_element_height[(Rx+pos)]+"px";
		/////////установка прозрачностьи
		
		pos+=step;
		setTimeout("_rotate_left("+pos+")", time_out);
		
	} else {
		pos=Rx;
		left_object.style.left=top_objects_left[pos]+"px";
		left_object.style.top=top_objects_top[pos]+"px";
		
		bottom_object.style.left=objects_left[(Rx-pos)]+"px";
		bottom_object.style.top=objects_top[(Rx-pos)]+"px";
		Element.setOpacity(bottom_img, bottom_pr[(Rx-pos)]);
		
		right_object.style.left=objects_left[(2*Rx-pos)]+"px";
		right_object.style.top=objects_top[(2*Rx-pos)]+"px";
		Element.setOpacity(right_img, bottom_pr[(2*Rx-pos)]);
		
		top_object.style.left=top_objects_left[(Rx+pos)]+"px";
		top_object.style.top=top_objects_top[(Rx+pos)]+"px";
		
		///изменяем размеры
		left_object.style.width=top_element_width[pos]+"px";
		left_object.style.height=top_element_height[pos]+"px";
		
		bottom_object.style.width=element_width[(Rx-pos)]+"px";
		bottom_object.style.height=element_height[(Rx-pos)]+"px";
		
		right_object.style.width=element_width[(2*Rx-pos)]+"px";
		right_object.style.height=element_height[(2*Rx-pos)]+"px";
		
		
		top_object.style.width=top_element_width[(Rx+pos)]+"px";
		top_object.style.height=top_element_height[(Rx+pos)]+"px";
		
		///изменяем картинки
		left_img.style.width=top_element_width[pos]+"px";
		left_img.style.height=top_element_height[pos]+"px";
		
		bottom_img.style.width=element_width[(Rx-pos)]+"px";
		bottom_img.style.height=element_height[(Rx-pos)]+"px";
		
		right_img.style.width=element_width[(2*Rx-pos)]+"px";
		right_img.style.height=element_height[(2*Rx-pos)]+"px";
		
		top_img.style.width=top_element_width[(Rx+pos)]+"px";
		top_img.style.height=top_element_height[(Rx+pos)]+"px";
			
		//////смена объектов
		
		tmp=left_img;
		left_img=bottom_img;
		bottom_img=right_img;
		right_img=top_img;
		top_img=tmp;
		
		//////смена картинок
		tmp=left_object;
		left_object=bottom_object;
		bottom_object=right_object;
		right_object=top_object;
		top_object=tmp;
		
		right_object.style.zIndex="1000";
		/////восстанавливаем заголовки
		right_link.innerHTML=objects_arr[r_n].oname;
		left_link.innerHTML=objects_arr[l_n].oname;
		center_title.innerHTML=objects_arr[b_n].oname;
		center_description.innerHTML=objects_arr[b_n].text;
		center_params.innerHTML=objects_arr[b_n].params;
		center_link.innerHTML=objects_arr[b_n].link_title;
		center_link.href=objects_arr[b_n].link_href;
		
		
		
		new Effect.Opacity('left_title1', { from: 0, to: 1, duration: 0.1 });
		new Effect.Opacity('right_title1', { from: 0, to: 1, duration: 0.1 });
		new Effect.Opacity('center_title1', { from: 0, to: 1, duration: 0.1 });
		
		right_img.onclick=function() {_rotate_left(1);}		
		bottom_img.onclick=function() {return false;}
		top_img.onclick=function() {return false;}
		left_img.onclick=function() {_rotate_right(1);}
		right_img.style.cursor="pointer";
		left_img.style.cursor="pointer";
	}
}

function _rotate_right(pos) {
	if (pos<=Rx) {
		///меняем Z-Index
		if (pos==1) {
			top_image_right();
			left_img.onclick=function() {return false;}
			right_img.onclick=function() {return false;}
			bottom_img.onclick=function() {return false;}
			top_img.onclick=function() {return false;}
			left_img.style.cursor="default";
			right_img.style.cursor="default";
			bottom_img.style.cursor="default";
			top_img.style.cursor="default";
			
			///скрываем надписи
			new Effect.Opacity('left_title1', { from: 1.0, to: 0, duration: 0.2 });
			new Effect.Opacity('right_title1', { from: 1.0, to: 0, duration: 0.2 });
			new Effect.Opacity('center_title1', { from: 1.0, to: 0, duration: 0.2 });
			
			//new Effect.Opacity(left_img, { from: alfa, to: 1, duration: 0.3 });
			
			//new Effect.Opacity(bottom_img, { from: 1.0, to: alfa, duration: 0.9 });
			right_object.style.zIndex="500";	
			
		}
		///перемещаем объекты
		if (pos>hide_top_x_left && top_object.style.display=='none') top_object.style.display='inline';
		if (pos>hide_top_x_right && right_object.style.display!='none') right_object.style.display='none';
		
		
		left_object.style.left=objects_left[pos]+"px";
		left_object.style.top=objects_top[pos]+"px";
		Element.setOpacity(left_img, bottom_pr[pos]);
		
		bottom_object.style.left=objects_left[(Rx+pos)]+"px";
		bottom_object.style.top=objects_top[(Rx+pos)]+"px";
		Element.setOpacity(bottom_img, bottom_pr[(Rx+pos)]);
		
		right_object.style.left=top_objects_left[(2*Rx-pos)]+"px";
		right_object.style.top=top_objects_top[(2*Rx-pos)]+"px";
		
		top_object.style.left=top_objects_left[(Rx-pos)]+"px";
		top_object.style.top=top_objects_top[(Rx-pos)]+"px";
		
		///изменяем размеры
		left_object.style.width=element_width[pos]+"px";
		left_object.style.height=element_height[pos]+"px";
		
		bottom_object.style.width=element_width[(Rx+pos)]+"px";
		bottom_object.style.height=element_height[(Rx+pos)]+"px";
		
		right_object.style.width=top_element_width[(2*Rx-pos)]+"px";
		right_object.style.height=top_element_height[(2*Rx-pos)]+"px";
		
		top_object.style.width=top_element_width[(Rx-pos)]+"px";
		top_object.style.height=top_element_height[(Rx-pos)]+"px";
		///изменение размеров картинки
		left_img.style.width=element_width[pos]+"px";
		left_img.style.height=element_height[pos]+"px";
		
		bottom_img.style.width=element_width[(Rx+pos)]+"px";
		bottom_img.style.height=element_height[(Rx+pos)]+"px";
		
		right_img.style.width=top_element_width[(2*Rx-pos)]+"px";
		right_img.style.height=top_element_height[(2*Rx-pos)]+"px";
		
		top_img.style.width=top_element_width[(Rx-pos)]+"px";
		top_img.style.height=top_element_height[(Rx-pos)]+"px";
		
		pos+=step;
		setTimeout("_rotate_right("+pos+")", time_out);
		
	} else {
		pos=Rx;
		left_object.style.left=objects_left[pos]+"px";
		left_object.style.top=objects_top[pos]+"px";
		
		bottom_object.style.left=objects_left[(Rx+pos)]+"px";
		bottom_object.style.top=objects_top[(Rx+pos)]+"px";
		
		right_object.style.left=top_objects_left[(2*Rx-pos)]+"px";
		right_object.style.top=top_objects_top[(2*Rx-pos)]+"px";
		
		top_object.style.left=top_objects_left[(Rx-pos)]+"px";
		top_object.style.top=top_objects_top[(Rx-pos)]+"px";
		
		///изменяем размеры
		left_object.style.width=element_width[pos]+"px";
		left_object.style.height=element_height[pos]+"px";
		
		bottom_object.style.width=element_width[(Rx+pos)]+"px";
		bottom_object.style.height=element_height[(Rx+pos)]+"px";
		
		right_object.style.width=top_element_width[(2*Rx-pos)]+"px";
		right_object.style.height=top_element_height[(2*Rx-pos)]+"px";
		
		top_object.style.width=top_element_width[(Rx-pos)]+"px";
		top_object.style.height=top_element_height[(Rx-pos)]+"px";
			
		///изменение размеров картинки
		left_img.style.width=element_width[pos]+"px";
		left_img.style.height=element_height[pos]+"px";
		
		bottom_img.style.width=element_width[(Rx+pos)]+"px";
		bottom_img.style.height=element_height[(Rx+pos)]+"px";
		
		right_img.style.width=top_element_width[(2*Rx-pos)]+"px";
		right_img.style.height=top_element_height[(2*Rx-pos)]+"px";
		
		top_img.style.width=top_element_width[(Rx-pos)]+"px";
		top_img.style.height=top_element_height[(Rx-pos)]+"px";
		
		//////смена координат
		tmp=left_object;
		left_object=top_object;
		top_object=right_object;
		right_object=bottom_object;
		bottom_object=tmp;
		//////смена картинок
		tmp=left_img;
		left_img=top_img;
		top_img=right_img;
		right_img=bottom_img;
		bottom_img=tmp;
		
		
		left_object.style.zIndex="1000";
		/////восстанавливаем заголовки
		left_link.innerHTML=objects_arr[l_n].oname;
		right_link.innerHTML=objects_arr[r_n].oname;
		center_title.innerHTML=objects_arr[b_n].oname;
		center_description.innerHTML=objects_arr[b_n].text;
		center_params.innerHTML=objects_arr[b_n].params;
		center_link.innerHTML=objects_arr[b_n].link_title;
		center_link.href=objects_arr[b_n].link_href;
		
		new Effect.Opacity('left_title1', { from: 0, to: 1, duration: 0.1 });
		new Effect.Opacity('right_title1', { from: 0, to: 1, duration: 0.1 });
		new Effect.Opacity('center_title1', { from: 0, to: 1, duration: 0.1 });
		
		right_img.onclick=function() {_rotate_left(1);}
		bottom_img.onclick=function() {return false;}
		left_img.onclick=function() {_rotate_right(1);}
		top_img.onclick=function() {return false;}
		right_img.style.cursor="pointer";
		left_img.style.cursor="pointer";
	}
}

function pre_round() {
	 Effect.Opacity('id_of_element', { from: 1.0, to: 0.7, duration: 0.5 });
}
