var port_img_height=600;

var scroll_x=0;
var curr_scroll=0;
var stop=0;
var step=600;
var speed=70;
var end_scroll=0;

var hs_stop=0;
var hs_x=0;
var hs_speed=70;
var hs='show';

var nav_link_right='';
var nav_link_left='';

var opacity=0;

var pr_click=0;
var loading=0;

function $_id(id)
	{
		return document.getElementById(id);
	}
	
function GetXmlHttpObject()
	{
		var objXMLHttp=null;
		if (window.XMLHttpRequest)
			{
				objXMLHttp=new XMLHttpRequest();
			}
		else if (window.ActiveXObject)
			{
				objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}	
		return objXMLHttp;
	} 

function attack(k,x,attack_length)
	{
		var r=(attack_length+7)*Math.sin((3.14/2)*x/(100-k));
		return r;
	}

function init_portolio()
	{
		nav_link_right=$_id('nav_right').innerHTML;
		nav_link_left=$_id('nav_left').innerHTML;
		check_nav_links();
	}

function check_nav_links()
	{
		if(port_img_lenght==step)
			{
				$_id('nav_right').innerHTML='';
				$_id('nav_left').innerHTML='';
			}
		else if($_id('scroll_portfolio').scrollLeft==port_img_lenght-step)
			{
				$_id('nav_right').innerHTML='';
				$_id('nav_left').innerHTML=nav_link_left;
			}
		else if($_id('scroll_portfolio').scrollLeft==0)
			{
				$_id('nav_left').innerHTML='';
				$_id('nav_right').innerHTML=nav_link_right;
			}
		else
			{
				$_id('nav_right').innerHTML=nav_link_right;
				$_id('nav_left').innerHTML=nav_link_left;
			}
	}

function hide_links()
	{
		$_id('nav_left').innerHTML='';
		$_id('nav_right').innerHTML='';
	}

function scroll_folio(way)
	{
		switch(way)
			{
				case 'right':
					var scroll=attack(speed,scroll_x,step);
					var next_scroll=attack(speed,scroll_x+1,step);
					if(next_scroll >= step)
						{
							end_scroll=curr_scroll+step;
							stop=1;
						}
					if(stop==0)
						{
							hide_links();
							$_id('scroll_portfolio').scrollLeft=curr_scroll+scroll;
							setTimeout("scroll_folio('"+way+"')", 20);
						}
					else
						{
							$_id('scroll_portfolio').scrollLeft=curr_scroll+end_scroll;
							end_scroll=0;
							stop=0;
							scroll_x=0;
							curr_scroll=$_id('scroll_portfolio').scrollLeft;
							check_nav_links();
						}
				break;
				
				case 'left':
					var scroll=attack(speed,scroll_x,step);
					var next_scroll=attack(speed,scroll_x+1,step);
					if(next_scroll >= step)
						{
							end_scroll=curr_scroll-step;
							if(end_scroll==0)
								{
									end_scroll=step;
								}
							stop=1;
						}
					if(stop==0)
						{
							hide_links();
							$_id('scroll_portfolio').scrollLeft=curr_scroll-scroll;
							setTimeout("scroll_folio('"+way+"')", 20);
						}
					else
						{
							$_id('scroll_portfolio').scrollLeft=curr_scroll-end_scroll;
							end_scroll=0;
							stop=0;
							scroll_x=0;
							curr_scroll=$_id('scroll_portfolio').scrollLeft;
							check_nav_links();
						}
				break;
			}
		scroll_x++;
	}

function hs_portfolio(id, height, hide_show)
	{
		switch(hide_show)
			{
				case 'hide':
					if(hs=='show')
						{
							var move=attack(hs_speed,hs_x,height);
							var next_move=attack(hs_speed,hs_x+1,height);
							if(next_move >= height)
								{
									hs_stop=1;
								}
							if(hs_stop==0)
								{
									var num_height=height-move;
									$_id('portfolio').style.height=num_height+'px';
									setTimeout("hs_portfolio('"+id+"', "+height+", '"+hide_show+"')", 20);
								}
							else
								{
									$_id('portfolio').style.height='0px';
									hs_stop=0;
									hs_x=0;
									hs='hide';
								}
						}
				break;
				
				case 'show':
					if(hs=='hide')
						{
							var move=attack(hs_speed,hs_x,height);
							var next_move=attack(hs_speed,hs_x+1,height);
							if(next_move >= height)
								{
									hs_stop=1;
								}
							if(hs_stop==0)
								{
									var num_height=move;
									$_id('portfolio').style.height=num_height+'px';
									setTimeout("hs_portfolio('"+id+"', "+height+", '"+hide_show+"')", 20);
								}
							else
								{
									$_id('portfolio').style.height=height+'px';
									hs_stop=0;
									hs_x=0;
									hs='show';
								}
						}
				break;
			}
		hs_x++;
	}
	
function hs_opacity(show_link_id, description_id, pm)
	{
		switch(pm)
			{
				case 'plus':
					if(opacity==0)
						{
							$_id(show_link_id).style.display='block';
							$_id(show_link_id).style.opacity = 0;
							$_id(show_link_id).style.filter = 'alpha(opacity=0)';
							
							$_id(description_id).style.display='block';
							$_id(description_id).style.opacity = 0;
							$_id(description_id).style.filter = 'alpha(opacity=0)';
						}
					if(opacity<=90)
						{
							opacity=opacity+10;
							$_id(show_link_id).style.opacity = opacity/100;
							$_id(show_link_id).style.filter = 'alpha(opacity='+opacity+')';
							
							$_id(description_id).style.opacity = opacity/100;
							$_id(description_id).style.filter = 'alpha(opacity='+opacity+')';
							
							setTimeout("hs_opacity('"+show_link_id+"', '"+description_id+"', '"+pm+"')", 50);
						}
				break;
				
				case 'minus':
					if(opacity==0)
						{
							$_id(show_link_id).style.display='none';
							$_id(show_link_id).style.opacity = 0;
							$_id(show_link_id).style.filter = 'alpha(opacity=0)';
							
							$_id(description_id).style.display='none';
							$_id(description_id).style.opacity = 0;
							$_id(description_id).style.filter = 'alpha(opacity=0)';
						}
					if(opacity>=10)
						{
							$_id(show_link_id).style.opacity = opacity/100;
							$_id(show_link_id).style.filter = 'alpha(opacity='+opacity+')';
							
							$_id(description_id).style.opacity = opacity/100;
							$_id(description_id).style.filter = 'alpha(opacity='+opacity+')';
							
							opacity=opacity-10;
							setTimeout("hs_opacity('"+show_link_id+"', '"+description_id+"', '"+pm+"')", 50);
						}
				break;
			}
	}

function hs_loading(uid, hide_show)
	{
		switch(hide_show)
			{
				case 'show':
					if(loading==0)
						{
							loading=1;
							$_id('loading_'+uid).style.display='block';
						}
				break;
				
				case 'hide':
					if(loading==1)
						{
							$_id('loading_'+uid).style.display='none';
							loading=0;
						}
				break;
			}
	}

function project_click(uid, description_id)
	{
		if(pr_click==0)
			{
				xmlHttp=GetXmlHttpObject();
				if(xmlHttp!=null)
					{
						xmlHttp.onreadystatechange=function()
							{
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									{
										if(xmlHttp.status==200)
											{
												var response=xmlHttp.responseText;
												$_id(description_id).innerHTML=response;
												hs_loading(uid, 'hide');
												hs_opacity('show_link', 'project_description', 'plus');
												hs_portfolio('portfolio', port_img_height, 'hide');
												pr_click=0;
											}
										else
											{
												hs_loading(uid, 'hide');
												pr_click=0;
												alert('Проблема загрузки с сервера...');
											}
									}
								else
									{
										pr_click=1;
										hs_loading(uid, 'show');
									}
							}
						xmlHttp.open('GET','./ajax.php?uid='+uid,true);
						xmlHttp.send(null);
					}
			}
	}

function show_contacts(who, what)
	{
		var manager=new Array();
		
		manager['i']=new Array();
		manager['i']['telephone']='+7 (925) 518-66-42';
		manager['i']['email']='info@eirgroup.ru';
		manager['i']['skype']='';
		manager['i']['icq']='174-776-943';
		
		document.write(manager[who][what]);
	}
