//ковыряйте на удовольствие :)
var d_x =0;
var nat_x=0;
var s_x =0;
var n=0;
var sc = 0;
var photo_top=100;
var photo_left=100;
var tmr1; 
var tmr2;
var tmr3;
var tmr4;
var tmr5;
var tmr6;
var tmr7;
var tmr8;
var tmr9;
var tmr10;
var tmr11;
var tmr12;
var tmr13;
var tmr14;
var tmr17;
var scroll_mode=0;
var phmode=0;
var menu_y=-35;
var pont_y=-29;
var tree_y=-1330;
var logo_y=-160;
var scr_x=-50;
var a1=0; a2=0; a3=0; a4=0; a5=0; a6=0;  a7=0; a8=0;
var cl_1_y=-100;
var clouds_speed=1;
var antilogo_x=-100;
var antilogo_y=-100;
var nat_bot_y=-500;
var la=0;
var cl_y=[-200, -200, -200, -200, -200, -200, -200, -200, -200, -200,];
var cl_last_y=new Array();
var cl_last_x=new Array();
var works_item=new Array();
var site_load=0;
var work_n=50;
var works_n=0;
var op=0;
var work_vis=1;
var op_stop=1;
var al=0;

//определение параметров окна, размер скроллера и прочее
window.onload=docLoaded;
function docLoaded(){
	checker();
	//work_big= [undefined,1,2,3,4,5,6,7,8,9,10];
	//work_width= [undefined,1000,600,1000,1000,1000,1000,1420,500,1400,1200];
	//work_height= [undefined,6220,849,1120,750,1370,3300,2780,600,800,900]; 
	work_big_total=work_big.length;
	//document.getElementById("loader").style.visibility='hidden';
		if (self.innerHeight) {
			doc_width = self.innerWidth;
			doc_height = self.innerHeight;
		}		
		else if (document.documentElement && document.documentElement.clientHeight) {
			doc_width = document.documentElement.clientWidth;
			doc_height = document.documentElement.clientHeight;
		}
		else if (document.body) {
			doc_width = document.body.clientWidth;
			doc_height = document.body.clientHeight;
		}
		scrlline_width = document.body.offsetWidth-100;
		site_width = parseInt(document.getElementById("site").style.width);
		natures_width = parseInt(document.getElementById("natures").style.width);
		scrlwidth = Math.round(doc_width*scrlline_width/site_width);
		document.getElementById("scrl").style.width = scrlwidth+'px';

		scrl_last_x=scrlline_width-scrlwidth; 
		doc_last_x= (site_width-doc_width)*(-1);
		nat_last_x= (natures_width-doc_width)*(-1);
		for(cl=0; cl<=9; ++ cl){
			cl_last_x[cl]=Math.round(Math.random()*site_width);
			cl_last_y[cl]=Math.round(Math.random()*(doc_height/2));
		}
		antilogo_last_x=doc_width/(-2)+150;
		antilogo_last_y=doc_height/(-2)+150;
		document.getElementById("scrl").style.visibility='visible';
		anim_go();
		cl_n=10;
}

window.onresize=scrollResize;
function scrollResize(){
	//document.getElementById("loader").style.visibility='hidden';
		if (self.innerHeight) {
			doc_width = self.innerWidth;
			doc_height = self.innerHeight;
		}		
		else if (document.documentElement && document.documentElement.clientHeight) {
			doc_width = document.documentElement.clientWidth;
			doc_height = document.documentElement.clientHeight;
		}
		else if (document.body) {
			doc_width = document.body.clientWidth;
			doc_height = document.body.clientHeight;
		}
		scrlline_width = document.body.offsetWidth-100;
		site_width = parseInt(document.getElementById("site").style.width);
		natures_width = parseInt(document.getElementById("natures").style.width);
		var scrlwidth = Math.round(doc_width*scrlline_width/site_width);
		document.getElementById("scrl").style.width = scrlwidth+'px';

		scrl_last_x=scrlline_width-scrlwidth; 
		doc_last_x= (site_width-doc_width)*(-1);
		nat_last_x= (natures_width-doc_width)*(-1);
		if(parseInt(document.getElementById("site").style.left)<doc_last_x){
				document.getElementById("site").style.left=doc_last_x+'px';
				document.getElementById("natures").style.left=nat_last_x+'px';
				document.getElementById("scrl").style.left=scrl_last_x+'px';
		}
		else{
			s_x=parseInt(document.getElementById("site").style.left)*scrl_last_x/doc_last_x;
			document.getElementById("scrl").style.left=s_x+50+'px';
		}
		if(phmode==1){
			photo_last_x=doc_width-photo_width-100;
			photo_last_y=doc_height-photo_height-100;
			if(photo_width>doc_width){
				document.getElementById("photo").style.left=100+'px';
			}
			if(photo_width<=doc_width){
				ph_x=(doc_width-photo_width)/2;
				document.getElementById("photo").style.left=ph_x+'px';
			}
			if(photo_height>doc_height){
				document.getElementById("photo").style.top=100+'px';
			}
			if(photo_height<=doc_height){
				ph_y=(doc_height-photo_height)/2;
				document.getElementById("photo").style.top=ph_y+'px';
			}
		}
}
function anim_go(){
	//анимация меню
	if(menu_y<0){
		menu_y+=Math.ceil(menu_y/(-7));
		document.getElementById('menu').style.top=menu_y+'px';
	}
	if(menu_y>=0){
		document.getElementById('menu').style.top=0+'px';
		a1=1;
	}
	//анимация понтов
	if(pont_y<0){
		pont_y+=Math.ceil(pont_y/(-7));
		document.getElementById('pont').style.bottom=pont_y+'px';
	}
	if(pont_y>=0){
		document.getElementById('pont').style.bottom=0+'px';
		a2=1;
	}

	if(scr_x<0){
		scr_x+=Math.ceil(scr_x/(-7));
		document.getElementById('back').style.left=scr_x+'px';
		document.getElementById('forward').style.right=scr_x+'px';
	}
	if(scr_x>=0){
		document.getElementById('back').style.left=0+'px';
		document.getElementById('forward').style.right=0+'px';
		a3=1;
	}
	//анимация скролла
	scroll_vis();
	//анимация дерева_1
	if(tree_y<0){
		tree_y+=Math.ceil(tree_y/(-7));
		document.getElementById('tree').style.bottom=tree_y+'px';
	}
	if(tree_y>=0){
		document.getElementById('tree').style.bottom=0+'px';
		a4=1;
	}
	
	//анимация облачков
	for(cl=0; cl<=9; ++ cl){
		if(cl_y[cl]<cl_last_y[cl]){
			cl_y[cl]+=Math.ceil((cl_last_y[cl]-cl_y[cl])/7);
			document.getElementById("cloud_"+cl).style.top=cl_y[cl]+'px';
			document.getElementById("cloud_"+cl).style.left=cl_last_x[cl]+'px';
		}
		if(cl_y[cl]>=cl_last_y[cl]){
			document.getElementById("cloud_"+cl).style.top=cl_last_y[cl]+'px';
			document.getElementById("cloud_"+cl).style.left=cl_last_x[cl]+'px';
			a5=1;
		}
	}
	//анимация лого
	if(logo_y<100){
		logo_y+=Math.ceil((100-logo_y)/7);
		document.getElementById('antilogo').style.top=logo_y+'px';
	}
	if(logo_y>=100){
		document.getElementById('antilogo').style.top=100+'px';
		a6=1;
	}
	
	if(nat_bot_y<0){
		nat_bot_y+=Math.ceil(nat_bot_y/(-7));
		document.getElementById('natures').style.bottom=nat_bot_y+'px';
	}
	if(nat_bot_y>=0){
		document.getElementById('natures').style.bottom=0+'px';
		a7=1;
	}
	
	if((a1==1)&&(a2==1)&&(a3==1)&&(a4==1)&&(a5==1)&&(a6==1)&&(a7==1)&&(a8==1)){
		anim_stop();	
	}
	else{
		tmr7=setTimeout(anim_go, 100);
	}
	
}
function anim_stop(){
	k_nat=parseInt(document.getElementById("natures").style.width)/parseInt(document.getElementById("site").style.width)
	clouds_go();
	site_load=1;
	document.getElementById('loader').style.top=2000+'px';
	document.getElementById("gen").style.visibility='visible';
	document.getElementById("scroll_line").style.visibility='visible'
	clearTimeout(tmr7);
	phmode=0;
    works_go();
}

function clouds_go(){
	for(cl=0; cl<=9; ++ cl){
		cl_last_x[cl]-=1;
		document.getElementById("cloud_"+cl).style.left=cl_last_x[cl]+'px';
		if(cl_last_x[cl]<=-400){
			cl_last_x[cl]=Math.round(Math.random()*site_width);
			cl_last_y[cl]=Math.round(Math.random()*(doc_height/2));
			document.getElementById("cloud_"+cl).style.top=cl_last_y[cl]+'px';
			document.getElementById("cloud_"+cl).style.left=cl_last_x[cl]+'px';
		}
	}
	tmr8=setTimeout(clouds_go, 100);
}
//определение браузера


function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
  if(window.opera){this.isIE = true;}
}

var browser = new Browser();
var dragObj = new Object();

//проявление работ

function works_go(){
	for(work_n=50; work_n>0; --work_n){
		var work_item = document.getElementById("block_"+work_n)
		if(null != work_item){
			works_n++;
			works_item[works_n] = document.getElementById("block_"+work_n);
		}
	}
	if(work_n==0){
		wokrs_visible();	
	}
}

function wokrs_visible(){
	if (browser.isNS){
		if(op<1){
			op+=0.1;
			works_item[work_vis].style.opacity=op;
		}
		else{
			works_item[work_vis].style.opacity=1;
			op=0
			work_vis++;
		}
	}
	if (browser.isIE){
		if(op<100){
			op+=10;
			works_item[work_vis].style.filter="alpha(opacity="+op+")"
		}
		else{
			works_item[work_vis].style.filter="alpha(opacity=100)"
			op=0
			work_vis++;
		}
	}
	if(window.opera){
		if(op<1){
			op+=0.1;
			works_item[work_vis].style.opacity=op;
		}
		else{
			works_item[work_vis].style.opacity=1;
			op=0
			work_vis++;
		}
	}
	if(work_vis>works_n){
		works_stop();
	}
	else{
		tmr14=setTimeout(wokrs_visible, 100);
	}
}

function works_stop(){
	clearTimeout(tmr14);
	works_vis=1;
}


//подгрузка фотки
function load_img(url, phwidth, phheight) {
	op_stop=0;
	q= url.replace('_big.jpg','');
	q=q.replace('img/works/work_','');
	document.getElementById('indication_ph').style.top=45+'%';
	document.getElementById('photo').src = url;
	this_work =  url;
	find_preview(this_work);
	//this_work = this_work.replace('_big.jpg','');
	photo_top=100;
	photo_width=phwidth;
	photo_height=phheight;
	photo_last_x=doc_width-photo_width-100;
	photo_last_y=doc_height-photo_height-100;
	scroll_mode=1;
	if(photo_width>doc_width){
		document.getElementById("photo").style.left=100+'px';
	}
	if(photo_width<=doc_width){
		ph_x=(doc_width-photo_width)/2;
		document.getElementById("photo").style.left=ph_x+'px';
	}
	if(photo_height>doc_height){
		document.getElementById("photo").style.top=100+'px';
	}
	if(photo_height<=doc_height){
		ph_y=(doc_height-photo_height)/2;
		document.getElementById("photo").style.top=ph_y+'px';
	}
	if((photo_width>doc_width)||(photo_height>doc_height)){
		document.getElementById("photo").style.cursor="move";	
	}
		if(q==1){
			document.getElementById("next_ov").style.visibility='hidden';
			document.getElementById("next").style.visibility='hidden';
			document.getElementById("next_hide").style.visibility='visible';
			document.getElementById("pre_ov").style.visibility='visible';
			document.getElementById("pre").style.visibility='visible';
			document.getElementById("pre_hide").style.visibility='hidden';
		}
		else if(q==(work_big_total-1)){
			document.getElementById("pre_ov").style.visibility='hidden';
			document.getElementById("pre").style.visibility='hidden';
			document.getElementById("pre_hide").style.visibility='visible';
			document.getElementById("next_ov").style.visibility='visible';
			document.getElementById("next").style.visibility='visible';
			document.getElementById("next_hide").style.visibility='hidden';
		}
		else{
			document.getElementById("pre_ov").style.visibility='visible';
			document.getElementById("pre").style.visibility='visible';
			document.getElementById("pre_hide").style.visibility='hidden';
			document.getElementById("next_ov").style.visibility='visible';
			document.getElementById("next").style.visibility='visible';
			document.getElementById("next_hide").style.visibility='hidden';
		}
}

function photohiden(ph_sh){
	if(ph_sh==1){
		document.getElementById("photo").style.visibility='visible';
		document.getElementById('indication_ph').style.top=2000+'px';
		phmode=1;
		vis_work();
		removeSelection()
	}
	if(ph_sh==0){
		scroll_mode=0;
		phmode=0;
		document.getElementById("photo").style.cursor="default";
		document.getElementById("photo").style.visibility='hidden';
		document.getElementById("photo").style.opacity=0;
		document.getElementById("photo").style.filter="alpha(opacity=0)";
		document.getElementById("next_work").style.visibility='hidden';
		document.getElementById("next_ov").style.visibility='hidden';
		document.getElementById("next").style.visibility='hidden';
		document.getElementById("next_hide").style.visibility='hidden';
		document.getElementById("pre_work").style.visibility='hidden';
		document.getElementById("pre_ov").style.visibility='hidden';
		document.getElementById("pre").style.visibility='hidden';
		document.getElementById("pre_hide").style.visibility='hidden';
		al=0;
		site_stop();
		hide_vis_stop();
	}
}
//формирование почты
function mail_send(user,domain,zone) {
	document.location.href = 'mailto:'+user+'@'+domain+'.'+zone;
}
//скрытие и проявление слоя при просмотре картинок
function showOrHide(val){
	if(val==0){
    	document.getElementById("scroller").style.visibility='visible';
		document.getElementById("hd").style.visibility='hidden';
		document.getElementById("pre_work").style.visibility='hidden';
		document.getElementById("photo").style.visibility='hidden';
		document.getElementById("next_work").style.visibility='hidden';
	}
	else if(val==1) {		   
    	document.getElementById("scroller").style.visibility='hidden';
		document.getElementById("hd").style.visibility='visible';
		document.getElementById("pre_work").style.visibility='visible';
		document.getElementById("next_work").style.visibility='visible';
	}
}
//скрытие и проявление скроллера при наведении на кпопки промотки
function showOrHideScr(val){
	if(val==0){
		if(sc==0){
			document.getElementById("scroll_line").style.visibility='hidden';
		}
	}
	else if((val==1)&&(site_load==1)) {
		document.getElementById("scroll_line").style.visibility='visible';
	}
}
//обработчик события жамкания на кнопки
var tmr1;
var tmr2;
function scrollforward(y){
	if(site_load==1){
		if(d_x>doc_last_x){
			d_x -=100 ;
			nat_x = k_nat*d_x;
			s_x= d_x*scrl_last_x/doc_last_x+50;
			document.getElementById("site").style.left =d_x+'px';
			document.getElementById("natures").style.left =nat_x+'px';
			document.getElementById("scrl").style.left =s_x+'px';
		}
		if(parseInt(document.getElementById("site").style.left)<=doc_last_x){
			d_x=doc_last_x;
			nat_x = k_nat*d_x;
			s_x=scrl_last_x+50
			document.getElementById("site").style.left =d_x+'px';
			document.getElementById("natures").style.left =nat_x+'px';
			document.getElementById("scrl").style.left =s_x+'px';
		}
		tmr1=setTimeout(scrollforward, 100);
		if (browser.isIE){
			document.attachEvent("onmouseup",stop_scrolling);
		}
		if (browser.isNS){
			document.addEventListener("mouseup", stop_scrolling,   true);
			event.preventDefault();
		}
	}
}
function scrollback(w){
	if(site_load==1){
		if(parseInt(document.getElementById("site").style.left)<0){
			d_x +=100 ;
			nat_x = k_nat*d_x;
			s_x= d_x*scrl_last_x/doc_last_x+50;
			document.getElementById("site").style.left =d_x+'px';
			document.getElementById("natures").style.left =nat_x+'px';
			document.getElementById("scrl").style.left =s_x+'px';
		}
		if(parseInt(document.getElementById("site").style.left)>=0){
			d_x=0;
			s_x=50;
			nat_x = 0;
			document.getElementById("site").style.left =d_x+'px';
			document.getElementById("natures").style.left =nat_x+'px';
			document.getElementById("scrl").style.left =s_x+'px';
		}
		
		tmr2=setTimeout(scrollback, 100);
		if (browser.isIE){document.attachEvent("onmouseup",stop_scrolling);}
		if (browser.isNS){
			document.addEventListener("mouseup", stop_scrolling,   true);
			event.preventDefault();
		}
	}
}
function stop_scrolling(){
	clearTimeout(tmr1);
	clearTimeout(tmr2);
}


//драг скроллера, написал почти сам)

function dragStart(event, id) {
	if(site_load==1){
		var el;
		var x;
		var y;
		if(id) dragObj.elNode = document.getElementById(id);
		else {
			if (browser.isIE)
      		dragObj.elNode = window.event.srcElement;
    		if (browser.isNS)
      		dragObj.elNode = event.target;
    		if (dragObj.elNode.nodeType == 3)
      		dragObj.elNode = dragObj.elNode.parentNode;
		}

		if (browser.isIE) {
			x = window.event.clientX + document.documentElement.scrollLeft+ document.body.scrollLeft;
			y = window.event.clientY + document.documentElement.scrollTop+ document.body.scrollTop;
		}
		if (browser.isNS) {
			x = event.clientX + window.scrollX;
			y = event.clientY + window.scrollY;
			
		}

		dragObj.cursorStartX = x;
		dragObj.cursorStartY = y;
		dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
		dragObj.elStartTop  = parseInt(dragObj.elNode.style.top, 10);

		if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
		if (isNaN(dragObj.elStartTop)) dragObj.elStarTop = 0;


		if (browser.isIE) {
    		document.attachEvent("onmousemove", dragGo);
    		document.attachEvent("onmouseup",   dragStop);
    		window.event.cancelBubble = true;
    		window.event.returnValue = false;
		}
		if (browser.isNS) {
    		document.addEventListener("mousemove", dragGo,   true);
    		document.addEventListener("mouseup",   dragStop, true);
    		event.preventDefault();
		}
	}
}

function dragGo(event) {
	if(site_load==1){
		var x;
		removeSelection()
		sc = 1;
  		if (browser.isIE) {
    		x = window.event.clientX + document.documentElement.scrollLeft+ document.body.scrollLeft;
			y = window.event.clientY + document.documentElement.scrollTop+ document.body.scrollTop;
  		}
  		if (browser.isNS) {
    		x = event.clientX + window.scrollX;
			y = event.clientY + window.scrollY;
		}
		if(phmode==1){
			if(photo_width>doc_width){
				p_x=dragObj.elStartLeft + x - dragObj.cursorStartX;
				dragObj.elNode.style.left = p_x + "px";
				if(parseInt(dragObj.elNode.style.left)>100){
					dragObj.elNode.style.left = 100+'px';
					p_x=100;
				}
				if(parseInt(dragObj.elNode.style.left)<photo_last_x){
					dragObj.elNode.style.left = photo_last_x+'px';	
					p_x=photo_last_x;
				}
				document.getElementById("photo").style.left=p_x+'px';
			}
			if(photo_height>doc_height){
				p_y=dragObj.elStartTop + y - dragObj.cursorStartY;
				dragObj.elNode.style.top = p_y + "px";
				if(parseInt(dragObj.elNode.style.top)>100){
					dragObj.elNode.style.top = 100+'px';
					p_y=100;
				}
				if(parseInt(dragObj.elNode.style.top)<photo_last_y){
					dragObj.elNode.style.top = photo_last_y+'px';
					p_y=photo_last_y;
				}
				document.getElementById("photo").style.top= p_y+'px';
				photo_top = parseInt(dragObj.elNode.style.top);
			}
			if (browser.isIE){
    			window.event.cancelBubble = true;
    			window.event.returnValue = false;
			}
			if (browser.isNS)
    			event.preventDefault();
		}
		else{
			s_x=dragObj.elStartLeft + x - dragObj.cursorStartX;
			d_x=(s_x-50)/(scrl_last_x)*doc_last_x;
			nat_x = k_nat*d_x;
			dragObj.elNode.style.left = s_x + "px";
			if(parseInt(dragObj.elNode.style.left)<50){
				dragObj.elNode.style.left = 50 + "px";
				s_x=50;
				d_x=0;
				nat_x=0;
			}
			if(parseInt(dragObj.elNode.style.left)>scrl_last_x+50){
				dragObj.elNode.style.left = scrl_last_x+50 + "px";
				s_x=scrl_last_x;
				d_x=doc_last_x;
				nat_x = k_nat*d_x;
			}
			document.getElementById("site").style.left=d_x+'px'
			document.getElementById("natures").style.left=nat_x+'px'
			if (browser.isIE) {
    			window.event.cancelBubble = true;
    			window.event.returnValue = false;
			}
			if (browser.isNS)
    			event.preventDefault();
		}
	}
}

function dragStop(event) {
	sc = 0;
  	if (browser.isIE) {
    	document.detachEvent("onmousemove", dragGo);
    	document.detachEvent("onmouseup",   dragStop);
  	}
  	if (browser.isNS) {
    	document.removeEventListener("mousemove", dragGo,   true);
    	document.removeEventListener("mouseup",   dragStop, true);
  	}
}
//запрет на выделение такста исходник: http://habrahabr.ru/blog/webdev/33130.html
function removeSelection(){
    if (window.getSelection) { window.getSelection().removeAllRanges(); }
    else if (document.selection && document.selection.clear)
      document.selection.clear();
}
//скроллинг колеса, исходник http://adomas.org/javascript-mouse-wheel/
function handle(delta) {
	//промотка сайта
	if(site_load==1){
	if(scroll_mode==0){
		if(window.opera){
			if (delta > 0){
				if(parseInt(document.getElementById("site").style.left)>doc_last_x){
					d_x -=100 ;
					nat_x = k_nat*d_x;
					s_x= d_x*scrl_last_x/doc_last_x+50;
					document.getElementById("site").style.left =d_x+'px';
				}
				if(parseInt(document.getElementById("site").style.left)<=doc_last_x){
					d_x=doc_last_x;
					nat_x = k_nat*d_x;
					s_x=scrl_last_x+50
					document.getElementById("site").style.left =doc_last_x+'px';
				}
				document.getElementById("natures").style.left =nat_x+'px';
				document.getElementById("scrl").style.left =s_x+'px';
			}
			if (delta < 0){
				if(parseInt(document.getElementById("site").style.left)<0){
					d_x +=100 ;
					nat_x = k_nat*d_x;
					s_x= d_x*scrl_last_x/doc_last_x+50;
					document.getElementById("site").style.left =d_x+'px';
				}
				if(parseInt(document.getElementById("site").style.left)>=0){
					d_x=0;
					nat_x=0;
					s_x=50;
					document.getElementById("site").style.left =d_x+'px';
				}
				document.getElementById("natures").style.left =nat_x+'px';
				document.getElementById("scrl").style.left =s_x+'px';
			}
		}	
		else{
			if (delta < 0){
				if(parseInt(document.getElementById("site").style.left)>doc_last_x){
					d_x -=100 ;
					nat_x = k_nat*d_x;
					s_x= d_x*scrl_last_x/doc_last_x+50;
					document.getElementById("site").style.left =d_x+'px';
				}
				if(parseInt(document.getElementById("site").style.left)<=doc_last_x){
					d_x=doc_last_x;
					nat_x = k_nat*d_x;
					s_x=scrl_last_x+50
					document.getElementById("site").style.left =doc_last_x+'px';
				}
				document.getElementById("natures").style.left =nat_x+'px';
				document.getElementById("scrl").style.left =s_x+'px';
			}
			if (delta > 0){
				if(parseInt(document.getElementById("site").style.left)<0){
					d_x +=100 ;
					nat_x = k_nat*d_x;
					s_x= d_x*scrl_last_x/doc_last_x+50;
					document.getElementById("site").style.left =d_x+'px';
				}
				if(parseInt(document.getElementById("site").style.left)>=0){				
					d_x=0;
					nat_x=0;
					s_x=50;
					document.getElementById("site").style.left =0+'px';
				}
				document.getElementById("natures").style.left =nat_x+'px';
				document.getElementById("scrl").style.left =s_x+'px';
			}	
		}
	}
	//тут начинается промотка картинки в режиме расширенного просмотра.
	if(scroll_mode==1){
		if(window.opera){
			if (delta < 0){
				if(photo_height>doc_height){
					if(photo_top<100)
						photo_top+=100;
					if(photo_top>=100)
						photo_top=100;
					document.getElementById('photo').style.top=photo_top+'px';
				}
			}
			if (delta > 0){
				photo_last_y=doc_height-photo_height-100;
				if(photo_height>doc_height){
					if(photo_top>photo_last_y)
						photo_top-=100;
					if(photo_top<=photo_last_y)
						photo_top=photo_last_y;
					document.getElementById('photo').style.top=photo_top+'px';
				}
			}	
		}
		else{
			if (delta < 0){
				photo_last_y=doc_height-photo_height-100;
				if(photo_height>doc_height){
					if(photo_top>photo_last_y)
						photo_top-=100;
					if(photo_top<=photo_last_y)
						photo_top=photo_last_y;
					document.getElementById('photo').style.top=photo_top+'px';
				}
			}
			if (delta > 0){
				if(photo_height>doc_height){
					if(photo_top<100)
						photo_top+=100;
					if(photo_top>=100)
						photo_top=100;
					document.getElementById('photo').style.top=photo_top+'px';
				}
			}	
		}
	}
	}
}

function wheel(event){
        var delta = 0;
        if (!event)
                event = window.event;
        if (event.wheelDelta) {
                delta = event.wheelDelta/120;

                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { 

                delta = -event.detail/3;
        }

        if (delta)
                handle(delta);
				
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

if (window.addEventListener)
        window.addEventListener('DOMMouseScroll', wheel, false);
		window.onmousewheel = document.onmousewheel = wheel;
//закрывашка
function close_ov(){
	document.getElementById("close_ov").style.visibility='visible';
}
function clos(){
	document.getElementById("close_ov").style.visibility='hidden';	
}
function work_scroll(next_pre){
	if(op_stop==1){
	for(q=0; q<work_big_total; ++q){
		loading_work="img/works/work_"+work_big[q]+"_big.jpg";
		if(this_work==loading_work){
			if(next_pre==1){
				loading_work="img/works/work_"+work_big[q-1]+"_big.jpg";
				loading_width=work_width[q-1];
				loading_height=work_height[q-1];
			}
			if(next_pre==0){
				loading_work="img/works/work_"+work_big[q+1]+"_big.jpg";
				loading_width=work_width[q+1];
				loading_height=work_height[q+1];
			}
			if(loading_work != "img/works/work_undefined_big.jpg"){
				hide_work();
				break;
			}
		}
	}
	}
}
function find_preview(){
	for(w=0; w<work_big_total; ++w){
		loading_work="img/works/work_"+work_big[w]+"_big.jpg";
		if(this_work==loading_work){
			this_preview=work_big_total-w;
			target_x=800+ 500*this_preview+205;
			d_x=parseInt(document.getElementById("site").style.left);
			go_x=(doc_width/2)-(target_x+d_x);
			scroll_site();
		}
	}
}
function scroll_site(){
	if(go_x != 0){	
		go_x=Math.floor((doc_width/2)-(target_x+d_x))+1;
		d_x=d_x + (go_x/4);
		nat_x = k_nat*d_x;
		s_x= d_x*scrl_last_x/doc_last_x+50;
		document.getElementById("site").style.left =d_x + 'px';
		document.getElementById("natures").style.left =nat_x+'px';
		document.getElementById("scrl").style.left =s_x+'px';
		tmr17=setTimeout(scroll_site, 100);
	}
	else{
		site_stop();	
	}
	if(d_x<=doc_last_x){
		d_x=doc_last_x;
		nat_x = k_nat*d_x;
		s_x=scrl_last_x+50;
		document.getElementById("site").style.left=doc_last_x+'px';
		document.getElementById("natures").style.left =nat_last_x+'px';
		document.getElementById("scrl").style.left =s_x+'px';
		site_stop();
	}
		
}
function site_stop(){
	clearTimeout(tmr17);	
}