//Предварительная подгрузка картинок
new Image().src='/img/projscroll_left_over.gif';
new Image().src='/img/projscroll_right_over.gif';
new Image().src='/img/project.jpg';
new Image().src='/img/bigdiv.gif';
new Image().src='/img/loader.gif';
new Image().src='/img/photo_last.gif';
new Image().src='/img/photo_next.gif';
new Image().src='/img/photo_last_over.gif';
new Image().src='/img/photo_next_over.gif';
new Image().src='/img/close.gif';

//Ширина креативной области на главной
function kreativ_width()
{
	var WindowWidth;
	if(document.body){WindowWidth=document.body.clientWidth;}
	if(WindowWidth<981){document.getElementById("kreativ100").style.width="981px"; document.getElementById("kreativ").style.width="981px";}
	if(WindowWidth>=981 && WindowWidth<=1200){document.getElementById("kreativ100").style.width=WindowWidth+"px"; document.getElementById("kreativ").style.width=WindowWidth+"px";}
	if(WindowWidth>1200){document.getElementById("kreativ100").style.width=WindowWidth+"px"; document.getElementById("kreativ").style.width="1200px";}
	setTimeout("kreativ_width()",300);
}

//Наведение на проекты в портфолио
function project_over(id){document.getElementById(id).style.background="url('/img/project.jpg')"}
function project_out(id){document.getElementById(id).style.background="none"}


//********************************************************************//
//********************  Работа с лентами прокрутки  *********************//
//********************************************************************//

//Перелистывание проектов на главной
var ScrollTimeOut,projscroll_position=0,revers=0,finish=0;
function projscroll_right()
{	var width=document.getElementById('projscrolltable').width;
	if(finish==0)
	{	clearTimeout(ScrollTimeOut);
		if(projscroll_position==924-Number(width))
		{
			document.getElementById('projscrolltable').style.left="0px";
			projscroll_position=0;
		}	projscroll_right_start(); ScrollTimeOut=setTimeout("projscroll_right("+width+")",7000);
}	}
function projscroll_left()
{	var width=document.getElementById('projscrolltable').width;
	if(finish==0)
	{	clearTimeout(ScrollTimeOut);
		if(projscroll_position==0)
		{
			document.getElementById('projscrolltable').style.left=924-Number(width)+"0px";
			projscroll_position=924-Number(width);
		}	projscroll_left_start(); ScrollTimeOut=setTimeout("projscroll_right("+width+")",7000);
}	}
function projscroll_right_start(position,more)
{
	if(typeof position=='undefined'){position=projscroll_position; revers=0; more=0; finish=1;}
	if(revers==0){more=Number(more)+0.5;}
	if(revers==1 && more<=1){more=Number(more)-0.1;}
	if(revers==1 && more>1 && more<=2){more=Number(more)-0.25;}
	if(revers==1 && more>2 && more<=4){more=Number(more)-0.4;}
	if(revers==1 && more>4){more=Number(more)-0.5;}
	if(more==12.5){revers=1; more=12;}
	document.getElementById('projscrolltable').style.left=Math.round(position)+"px";
	if(more>0){ViewTimeOut=setTimeout("projscroll_right_start("+(Number(position)-more)+","+more+")",15);}
	if(more<=0){projscroll_position=Math.round(position); finish=0;}
}
function projscroll_left_start(position,more)
{
	if(typeof position=='undefined'){position=projscroll_position; revers=0; more=0; finish=1;}
	if(revers==0){more=Number(more)+0.5;}
	if(revers==1 && more<=1){more=Number(more)-0.1;}
	if(revers==1 && more>1 && more<=2){more=Number(more)-0.25;}
	if(revers==1 && more>2 && more<=4){more=Number(more)-0.4;}
	if(revers==1 && more>4){more=Number(more)-0.5;}
	if(more==12.5){revers=1; more=12;}
	document.getElementById('projscrolltable').style.left=Math.round(position)+"px";
	if(more>0){ViewTimeOut=setTimeout("projscroll_left_start("+(Number(position)+more)+","+more+")",15);}
	if(more<=0){projscroll_position=Math.round(position); finish=0;}
}

//Перелистывание логотипов клиентов
var logoscroll_position=0;
function logoscroll()
{	var width=document.getElementById('clients_scroll').width;
	if(finish==0)
	{	clearTimeout(ScrollTimeOut);
		if(logoscroll_position==636-Number(width))
		{
			document.getElementById('clients_scroll').style.left="0px";
			logoscroll_position=0;
		}	logoscroll_start(); ScrollTimeOut=setTimeout("logoscroll("+width+")",7000);
}	}
function logoscroll_start(position,more)
{
	if(typeof position=='undefined'){position=logoscroll_position; revers=0; more=0; finish=1;}
	if(revers==0){more=Number(more)+0.5;}
	if(revers==1 && more<=1){more=Number(more)-0.12;}
	if(revers==1 && more>1 && more<=2){more=Number(more)-0.3;}
	if(revers==1 && more>2 && more<=4){more=Number(more)-0.4;}
	if(revers==1 && more>4){more=Number(more)-0.5;}
	if(more==9){revers=1; more=8.5;}
	document.getElementById('clients_scroll').style.left=Math.round(position)+"px";
	if(more>0){ViewTimeOut=setTimeout("logoscroll_start("+(Number(position)-more)+","+more+")",15);}
	if(more<=0){logoscroll_position=Math.round(position); finish=0;}
}


//********************************************************************//
//******************  Работа с новостями на главной  ********************//
//********************************************************************//

//Наведение на новость на главной
var NewIdout,New_contrast_control=0;
function new_over(id)
{
	if(typeof(NewTimeout)=="number" && NewIdout==id){clearTimeout(NewTimeout);}
	if(New_contrast_control==0 && document.getElementById("bignew"+id).style.display!="block")
	{
		document.getElementById("bignew"+id).style.display="block";
		new_contrast(id,0);
}	}
function new_out(id)
{
	if(New_contrast_control==0){NewTimeout=setTimeout("new_recontrast('"+id+"','100')",100); NewIdout=id;}
	if(New_contrast_control==1){NewTimeout=setTimeout("new_recontrast('"+id+"','100')",400); NewIdout=id;}
}
function news_out()
{
	if(document.getElementById("bignew1").style.display=="block"){setTimeout("new_out(1)",400)}
	if(document.getElementById("bignew2").style.display=="block"){setTimeout("new_out(2)",400)}
	if(document.getElementById("bignew3").style.display=="block"){setTimeout("new_out(3)",400)}
}

//Плавное проявление новостей на главной
function new_contrast(id,opacity)
{
	opacity=Number(opacity)+20;
	document.getElementById("bignew"+id).style.opacity=Number(opacity)/100;
	document.getElementById("bignew"+id).style.filter="alpha(opacity="+opacity+")";
	if(opacity<100){setTimeout("new_contrast("+id+","+opacity+")",30); New_contrast_control=1;}
	if(opacity==100){New_contrast_control=0;}
}
function new_recontrast(id,opacity)
{
	opacity=Number(opacity)-20;
	document.getElementById("bignew"+id).style.opacity=Number(opacity)/100;
	document.getElementById("bignew"+id).style.filter="alpha(opacity="+opacity+")";
	if(opacity>0){setTimeout("new_recontrast("+id+","+opacity+")",30); New_contrast_control=1;}
	if(opacity==0){document.getElementById("bignew"+id).style.display="none"; New_contrast_control=0;}
}


//********************************************************************//
//***************  Работа с плавающим меню на главной  ****************//
//********************************************************************//
var floatbg_id=1,floatbg_width=315,floatbg_left=0,Floatlink_control=0;
function floatlink(id)
{
	if(floatbg_id!=id && Floatlink_control==0)
	{
		document.getElementById("floatlink"+floatbg_id).className="";
		floatcont_recontrast(floatbg_id,100,id);
		setTimeout('document.getElementById("floatlink"+'+id+').className="act"',450);
		if(id==1){floatbg_move(0,floatbg_left,315,floatbg_width);}
		if(id==2){floatbg_move(360,floatbg_left,174,floatbg_width);}
		if(id==3){floatbg_move(576,floatbg_left,325,floatbg_width);}
		floatbg_id=id; Floatlink_control=1;
}	}
function floatbg_move(left,this_left,width,this_width)
{
	LeftDiff=Number(left)-Number(floatbg_left); WidthDiff=Number(width)-Number(floatbg_width);
	this_left=Number(this_left)+(LeftDiff/15); this_width=Number(this_width)+(WidthDiff/15);
	document.getElementById("floatbg").style.left=Math.round(this_left)+"px";
	document.getElementById("floatbg").style.width=Math.round(this_width)+"px";
	if(left!=Math.round(this_left) || width!=Math.round(this_width)){setTimeout("floatbg_move("+left+","+this_left+","+width+","+this_width+")",30);}
	if(left==Math.round(this_left) && width==Math.round(this_width)){floatbg_left=Math.round(this_left); floatbg_width=Math.round(this_width);}
}
function floatcont_contrast(contrast,opacity)
{
	opacity=Number(opacity)+10;
	document.getElementById("floatcontent"+contrast).style.opacity=Number(opacity)/100;
	document.getElementById("floatcontent"+contrast).style.filter="alpha(opacity="+opacity+")";
	if(opacity<100){setTimeout("floatcont_contrast("+contrast+","+opacity+")",30);}
	if(opacity==100){Floatlink_control=0;}
}
function floatcont_recontrast(recontrast,opacity,contrast)
{
	opacity=Number(opacity)-10;
	document.getElementById("floatcontent"+recontrast).style.opacity=Number(opacity)/100;
	document.getElementById("floatcontent"+recontrast).style.filter="alpha(opacity="+opacity+")";
	if(opacity>0){setTimeout("floatcont_recontrast("+recontrast+","+opacity+","+contrast+")",30);}
	if(opacity==0)
	{
		document.getElementById("floatcontent"+contrast).style.opacity="0";
		document.getElementById("floatcontent"+contrast).style.filter="alpha(opacity=0)";
		document.getElementById("floatcontent"+contrast).style.display="block";
		document.getElementById("floatcontent"+recontrast).style.display="none";
		floatcont_contrast(contrast,0);
}	}


//********************************************************************//
//*********************  Работа с фотографиями  ***********************//
//********************************************************************//
var this_folder,this_photo,photos_array=new Array();

//Запрос к предыдущей фотографии
function openphoto_last()
{
	clearTimeout(ViewTimeout);
	for(i=0;i<photos_array.length;i++)
	{
		if(this_photo==photos_array[i] && typeof photos_array[i-1]!='undefined'){open_id=photos_array[i-1]}
		if(this_photo==photos_array[i] && typeof photos_array[i-1]=='undefined'){open_id=photos_array[photos_array.length-1]}
	}
	openphoto(this_folder,open_id,photos_array)
}

//Запрос к следующей фотографии
function openphoto_next()
{
	clearTimeout(ViewTimeout);
	for(i=0;i<photos_array.length;i++)
	{
		if(this_photo==photos_array[i] && typeof photos_array[i+1]!='undefined'){open_id=photos_array[i+1]}
		if(this_photo==photos_array[i] && typeof photos_array[i+1]=='undefined'){open_id=photos_array[0]}
	}
	openphoto(this_folder,open_id,photos_array)
}

//Запрос к текущей фотографии
function openphoto(folder,id,array)
{
	this_folder=folder; this_photo=id; photos_array=array;
	document.getElementById("photoimg").style.opacity="0";
	document.getElementById("photoimg").style.filter="alpha(opacity=0)";
	document.getElementById("bigphoto").style.background="url(/img/loader.gif) no-repeat center center";
	LoadAjaxDoc("/ajax/openphoto.js.php?folder="+folder+"&id="+id+"&"+Math.random());
	if(photos_array.length==1)
	{
		document.getElementById("photolast").style.display="none";
		document.getElementById("photonext").style.display="none";
}	}


//********************************************************************//
//************************  Работа со слоями  **************************//
//********************************************************************//

//Плавная контрастность фотографии
function photoimg_contrast(opacity)
{
	opacity=Number(opacity)+10;
	if(opacity==10){document.getElementById("bigphoto").style.background="#FFFFFF";}
	document.getElementById("photoimg").style.opacity=Number(opacity)/100;
	document.getElementById("photoimg").style.filter="alpha(opacity="+opacity+")";
	if(opacity<100){setTimeout("photoimg_contrast('"+opacity+"')",15);}
}

//Открытие плашки фотографии
function photo_correct(width,height,nottop)
{
	X=(document.body.clientWidth-width-24)/2+document.body.scrollLeft;
	Y=(document.body.clientHeight-height-50)/2+document.body.scrollTop;
	X_window=document.body.clientWidth+document.body.scrollLeft;
	Y_window=document.body.scrollHeight;
	if(Y<document.body.scrollTop){Y=document.body.scrollTop+14;}
	if((Number(Y)+Number(height)+3)>Y_window){Y=Number(Y_window)-Number(height)-64;}
	document.getElementById("bigdiv").style.width=X_window+"px";
	document.getElementById("bigdiv").style.height=Y_window+"px";
	document.getElementById("underbigphoto").style.left=(Number(X)-14)+"px";
	document.getElementById("underbigphoto").style.width=Number(width)+48+"px";
	document.getElementById("underbigphoto").style.height=Number(height)+78+"px";
	document.getElementById("bigphoto").style.left=X+"px";
	document.getElementById("bigphoto").style.width=Number(width)+20+"px";
	document.getElementById("bigphoto").style.height=Number(height)+50+"px";
	document.getElementById("photoimg").style.width=width+"px";
	document.getElementById("photoimg").style.height=height+"px";
	document.getElementById("photolast").style.top=(Number(height)/2-28)+"px";
	document.getElementById("photonext").style.top=(Number(height)/2-28)+"px";
	if(typeof nottop=='undefined')
	{
		document.getElementById("underbigphoto").style.top=(Number(Y)-14)+"px";
		document.getElementById("underbigphoto").style.display="block";
		document.getElementById("bigphoto").style.top=Y+"px";
		document.getElementById("bigphoto").style.display="block";
	}	ViewTimeout=setTimeout("photo_correct('"+width+"','"+height+"','nottop')",500);
}

//Закрытие плашки фотографии
function closephoto(opacity){photoimg_recontrast(100); clearTimeout(ViewTimeout);}
function photoimg_recontrast(opacity)
{
	opacity=Number(opacity)-10;
	document.getElementById("photoimg").style.opacity=Number(opacity)/100;
	document.getElementById("photoimg").style.filter="alpha(opacity="+opacity+")";
	if(opacity>0){setTimeout("photoimg_recontrast('"+opacity+"')",15);}
	if(opacity==0)
	{
		document.getElementById("bigphoto").style.display="none";
		document.getElementById("underbigphoto").style.display="none";
		document.getElementById("bigdiv").style.display="none";
}	}

//Открытие информационного сообщения
function myalert(text)
{
	X=(document.body.clientWidth-450)/2+document.body.scrollLeft;
	Y=(document.body.clientHeight-200)/2+document.body.scrollTop;
	X_window=document.body.clientWidth+document.body.scrollLeft;
	Y_window=document.body.scrollHeight;
	document.getElementById("bigdiv").style.width=X_window+"px";
	document.getElementById("bigdiv").style.height=Y_window+"px";
	document.getElementById("undermyalert").style.left=(Number(X)-12)+"px";
	document.getElementById("undermyalert").style.top=(Number(Y)-12)+"px";
	document.getElementById("myalert").style.left=X+"px";
	document.getElementById("myalert").style.top=Y+"px";
	if(text.length>0)
	{
		document.getElementById("bigdiv").style.display="block";
		document.getElementById("undermyalert").style.display="block";
		document.getElementById("myalert").style.display="block";
		document.getElementById("alert_text").innerHTML=text;
	}
	ViewTimeout=setTimeout("myalert('')",500);
}

//Закрытие информационного сообщения
function myalert_close()
{
	document.getElementById("myalert").style.display="none";
	document.getElementById("undermyalert").style.display="none";
	document.getElementById("bigdiv").style.display="none";
	clearTimeout(ViewTimeout); 
}


//*******************************************************************//
//**********************  Работа с полями форм  **********************//
//*******************************************************************//

//Проверка корректности Email адреса
function emailvalid(email){return(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);}

//Функция для запуска формы заказа сайта
function ordersite_submit()
{
	var field_error_1="",field_error_2="",correct_error="",ordersite_fields_1=new Array("name","text"),ordersite_fields_2=new Array("phone","mail");
	for(var key in ordersite_fields_1){if(document.getElementById("order_"+ordersite_fields_1[key]).value==""){field_error_1="1"}}
	for(var key in ordersite_fields_2){if(document.getElementById("order_"+ordersite_fields_2[key]).value==""){field_error_2=Number(field_error_2)+1}}
	if(document.getElementById("order_mail").value.length>0 && field_error_1=="" && field_error_2!="2" && emailvalid(document.getElementById("order_mail").value)==false){correct_error="1"}
	if(field_error_1=="1"){myalert("Вами были заполнены не все обязательные поля.<br>Заполните поля, помеченные красной звездочкой.")}
	if(field_error_1=="" && field_error_2=="2"){myalert("Вами не были указаны контактные данные.<br>Заполните одно из полей, помеченное синей звездочкой.")}
	if(field_error_1=="" && field_error_2!="2" && correct_error=="1"){myalert("Вами был введен некорректный email-адрес.<br>Перезаполните соответствующее поле.")}
	if(field_error_1=="" && field_error_2!="2" && correct_error==""){document.getElementById("ordersite_form").submit()}
}


//*******************************************************************//
//*****************  Функции вставки боковых баннеров  ****************//
//*******************************************************************//
function banner_up()
{
	var banner_insert=0;
	if(document.body!=null && document.getElementById('banner_up')!=null && document.getElementById('banner_up_code')!=null)
	{
		var required_height=Number(document.body.scrollHeight)-Number(document.getElementById("leftmenu").scrollHeight);
		if(required_height>580){document.getElementById('banner_up').style.display="block"; document.getElementById('banner_up').innerHTML=document.getElementById('banner_up_code').value; banner_insert=1;}
	}	if(banner_insert==0){setTimeout("banner_up()",500)}
}	banner_up();

function banner_down()
{
	var banner_insert=0;
	if(document.body!=null && document.getElementById('banner_down')!=null && document.getElementById('banner_down_code')!=null)
	{
		var required_height=Number(document.body.scrollHeight)-Number(document.getElementById("leftmenu").scrollHeight);
		if(required_height>850){document.getElementById('banner_down').style.display="block"; document.getElementById('banner_down').innerHTML=document.getElementById('banner_down_code').value; banner_insert=1;}
	}	if(banner_insert==0){setTimeout("banner_down()",500)}
}	banner_down();


//*******************************************************************//
//*****************  Функция вставки Flash-анимации  *******************//
//*******************************************************************//
function showFlash(o){var bg,q,s,v;
if(o.bgcolor){bg=o.bgcolor;}else{bg="#FFFFFF";}
if(o.quality){q=o.quality;}else{q="high";}
if(o.scale){s=o.scale;}else{s="noscale";}
if(o.ver){v=o.ver;}else{v=6;}
var str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+v+',0,0,0" ';
str+='id="'+o.id+'" ';
if(o.base){str+='base="'+o.base+'" ';}
if(o.align){str+='align="'+o.align+'" ';}
str+='width="'+o.width+'" height="'+o.height+'"><param name="movie" value="'+o.name+'"/><param name="bgcolor" value="'+bg+'"/><param name="quality" value="'+q+'"/>';
if(o.flashvars){str+='<param name="flashvars" value="'+o.flashvars+'"/>';}
if(o.allowScriptAccess){str+='<param name="allowScriptAccess" value="'+o.allowScriptAccess+'"/>';}
if(o.salign){str+='<param name="salign" value="'+o.salign+'"/>';}
str+='<param name="wmode" ';
if(o.bgcolor.length>0){str+='value="opaque" ';} if(o.bgcolor.length==0){str+='value="transparent" ';}
str+='/><param name="scale" value="'+s+'"/><embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="'+o.id+'-embed" src="'+o.name+'" bgcolor="'+bg+'" ';
if(o.flashvars){str+='flashvars="'+o.flashvars+'" ';}
if(o.swLiveConnect){str+='swLiveConnect="'+o.swLiveConnect+'" ';}
if(o.allowScriptAccess){str+='allowScriptAccess="'+o.allowScriptAccess+'" ';}
str+='quality="'+q+'" ';
if(o.base){str+='base="'+o.base+'" ';}
if(o.salign){str+='salign="'+o.salign+'" ';}
str+='scale="'+s+'" width="'+o.width+'" height="'+o.height+'" ';
if(o.bgcolor.length>0){str+='wmode="opaque" ';} if(o.bgcolor.length==0){str+='wmode="transparent" ';}
str+='/></embed></object>';
document.writeln(str);}


//*******************************************************************//
//**************************  Движок аякса  ***************************//
//*******************************************************************//
function LoadAjaxDoc(url)
{
    var req=getXmlHttp()  
    req.open('GET',url,true);
    req.onreadystatechange=function()
	{
		if(req.readyState==4)
		{
            if(req.status==200){eval(req.responseText);}
			else{window.alert("Ошибка: не удалось получить данные!");}
	}	}
    req.send(null);
}
function getXmlHttp()
{
	var xmlhttp; try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e)
	{
		try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		catch(E){xmlhttp=false;}
	}
	if(!xmlhttp && typeof XMLHttpRequest!='undefined'){xmlhttp=new XMLHttpRequest();}
	return xmlhttp;
}
