function gallery(){
	var uls = document.getElementsByTagName('ul');
	var p = document.getElementsByTagName('p');
	var div = document.getElementsByTagName('div');
	var a = document.getElementsByTagName('a');
	//var rightScroll = document.getElementById('scroll-right');
	//var leftScroll = document.getElementById('scroll-left');
	var closeGall = document.getElementById('close');
	var gallPlace = document.getElementById('gallery-place');
	var photo = document.getElementById('photo');
	var closePos = document.getElementById('closePos');
	 if(!closePos) return;
	var next = document.getElementById('foto-str-r');
	var previous = document.getElementById('foto-str-l');
	var filter = []; 
	var infra = [];
	var filterLi = [];
	var shadow = [];
	var web = [];
	var desc = [];
	var ulGall = [];
	var lies = [];
	var cam = [];
	var gall = [];
	var webc = [];
	var myLies = []; 
	var myDiv = [];
	var rightScroll = [];
	var leftScroll = [];
	var rightDiv = [];
	var leftDiv = [];
	
	var ulWidth;
	var scrolling;
	var borders;
	
	
	closePos.style.width = 400 + 'px';
	for (var i=0;i<uls.length;i++){
		if ((" "+uls[i].className+" ").indexOf(' gallery-infra ') != -1){ulGallInfra.push(uls[i]);}
	}
	for (var i=0;i<uls.length;i++){
		if ((" "+uls[i].className+" ").indexOf(' gallery ') != -1){ulGall.push(uls[i]);}
		if ((" "+uls[i].className+" ").indexOf(' filter ') != -1){filter.push(uls[i]);}
	}
	for (var i=0;i<a.length;i++){
		if ((" "+a[i].className+" ").indexOf(' right-button ') != -1){rightScroll.push(a[i]);}
		if ((" "+a[i].className+" ").indexOf(' left-button ') != -1){leftScroll.push(a[i]);}
	}
	for (var d=0;d<ulGall.length;d++){
	//for (var i=0;i<ulGall.length;i++){
		lies = ulGall[d].getElementsByTagName('li');
	//}
	for (var i=0;i<p.length;i++){
		if ((" "+p[i].className+" ").indexOf(' desc ') != -1){desc.push(p[i]);}
	}
	/*********************web************************/
	for (var i=0;i<div.length;i++){
		if ((" "+div[i].className+" ").indexOf(' shadow-horizontal ') != -1){shadow.push(div[i]);}
		if (((" "+div[i].className+" ").indexOf(' left ') != -1) && ((" "+div[i].parentNode.className+" ").indexOf(' shadow ') != -1)){leftDiv.push(div[i]);}
		if (((" "+div[i].className+" ").indexOf(' right ') != -1) && ((" "+div[i].parentNode.className+" ").indexOf(' shadow ') != -1)){rightDiv.push(div[i]);}
		if ((" "+div[i].className+" ").indexOf(' action ') != -1){myDiv.push(div[i]);}
	}
	/*for (var i=0;i<myDiv.length;i++){
		myDiv[i].style.height = 1 +  'px';
	}*/
	if(!lies[0]) return;
	var liLength = lies[0].offsetWidth;
	var margin = 100;
	var widthM;
	 
	
	
	
	
	for (var i=1;i<lies.length;i++){
		lies[i].style.left = margin + 'px';
		liLength = liLength + (lies[i].offsetWidth - (lies[i].offsetWidth-100));
		margin = margin + 100;
		widthM = margin + lies[i].offsetWidth-100;
		
	}
	
	for (var n=0;n<ulGall.length;n++){
		ulGall[n].style.left = 0;
		
	}
	ulWidth =widthM;
	for (var i=0;i<shadow.length;i++){
		shadow[i].style.width = parseInt(ulGall[n].parentNode.offsetWidth) + 'px';
	}
	var left = 0;
	for (var n=0;n<ulGall.length;n++){
		var rightBord = ulGall[n].parentNode.offsetWidth;
	}
	var interval = null;
	for (var n=0;n<ulGall.length;n++){
		if(typeof ulWidth != 'undefined')
			ulGall[n].style.width = ulWidth + 'px';
		var right = ulGall[n].offsetWidth - parseInt(ulGall[n].parentNode.offsetWidth);
	}
	for (var i=0;i<lies.length;i++){
		lies[i].onmouseover = function(){
			this.style.marginLeft = - (this.offsetWidth-100) / 2 + 'px';
			if (this == lies[lies.length-1]){this.style.marginLeft = 0 + 'px';}
			if (this == lies[0]){this.parentNode.style.left = (this.offsetWidth-100) / 2 + 'px';}
		}
		lies[i].onmouseout = function(){
			this.style.marginLeft = 0 + 'px';
			if (this == lies[0]){this.parentNode.style.left = 0 + 'px';}
		}
	}
		
	//console.log(lies);
	if (ulWidth < ulGall[d].parentNode.offsetWidth){
		ulGall[d].parentNode.parentNode.style.width = ulWidth + 'px';
		ulGall[d].parentNode.style.width = ulWidth + 'px';
		rightScroll[d].style.display = 'none';
		leftScroll[d].style.display = 'none';
	}
	else{
		rightScroll[d].style.display = 'block';
		leftScroll[d].style.display = 'block';
		for (var j=0;j<leftDiv.length;j++){
			leftDiv[j].style.left = 12 + 'px';
		}
		for (var j=0;j<rightDiv.length;j++){
			rightDiv[j].style.right = 15 + 'px';
		}
	}
	
	var leftPosition = parseInt(ulGall[d].style.left);
	
	for (var i=0;i<lies.length;i++){
				lies[i].onclick = function(){
					gallPlace.style.display = 'block';
					//gallPlace.style.top = as.getElementPosition(this).top + 360 + 'px';
					for (var j=0;j<lies.length;j++){
						lies[j].className = lies[j].className.replace(/\bactive\b/gi,'');
					}
					//this.className += ' active';
					for (var j=0;j<desc.length;j++){
						desc[j].style.display = 'none';
						if ((" "+desc[j].id+" ").match(" "+this.id+" ")){
							desc[j].style.display = 'block';
							desc[j].style.left = as.getElementPosition(this).left - 10 + 'px';
							desc[j].style.top = as.getElementPosition(this).top - 515 + 'px';
							desc[j].style.width = this.offsetWidth + 'px';
							
						}
					}
					//photo.src = this.firstChild.src;
					photo.src = '/i/p1.gif';
					
					//closePos.style.width = parseInt(photo.parentNode.offsetWidth) + 'px';
					photo.onload = function(){
						closePos.style.width = photo.offsetWidth + 'px';
					}
				}
			}
	
	var scrollingNow = false;
	function scrollLeft(p){
		console.log("!");
		for (var i=0;i<lies.length;i++){
			scrolling = (lies[i].offsetWidth - (lies[i].offsetWidth-100)) * 4;
		}
		if (ulWidth - ulGall[p].parentNode.offsetWidth + leftPosition < scrolling ){scrolling =  ulWidth - ulGall[p].parentNode.offsetWidth + leftPosition;}
		scrollingNow = true;
		for (var i=0;i<scrolling;i++) {
			(function(i) {
				setTimeout(function() {
					scrollingLeft(p);
					if (i==scrolling-1){scrollingNow = false;}
				},i);
			})(i);
		}
	}
	function scrollingLeft(p){
		leftPosition -= 1;
		//for (var k=0;k<ulGall.length;k++){
			//if (k==p){
			ulGall[p].style.left = leftPosition + 'px';
		//	}
			
		//}
	}
	
	
	}
	function scrollRight(p){
		for (var i=0;i<lies.length;i++){
			scrolling = (lies[i].offsetWidth - (lies[i].offsetWidth-100)) * 4;
		}
		if (-leftPosition < scrolling ){scrolling =  -leftPosition;}
		scrollingNow = true;
		for (var i=0;i<scrolling;i++) {
			(function(i) {
				setTimeout(function() {
					scrollingRight(p);
					if (i==scrolling-1){scrollingNow = false;}
				},i);
			})(i);
		}
	}
	function scrollingRight(p){
		leftPosition += 1;
		//for (var k=0;k<ulGall.length;k++){
		ulGall[p].style.left = leftPosition + 'px';
		//}
	}
	for (var p=0;p<rightScroll.length;p++){
		(function(p) {
					rightScroll[p].onclick = function (e){
						stopEvent(e);
						if (scrollingNow){stopEvent(e);}
						else{
							if (leftPosition <= -right){clearInterval(interval);}
							else {scrollLeft(p);}
							for (var j=0;j<desc.length;j++){
								desc[j].style.display = 'none';
							}
						}
						//scrollingNow = true;
					}
					leftScroll[p].onclick = function (e){
						stopEvent(e);
						if (scrollingNow){stopEvent(e);}
						else{
							if (leftPosition >= left){clearInterval(interval);}
							else {scrollRight(p);}
							for (var j=0;j<desc.length;j++){
								desc[j].style.display = 'none';
							}
						}
						//scrollingNow = true;
					}
		})(p)
	
	}
	for (var i=0;i<myDiv.length;i++){
		myDiv[i].style.display ='none';
	}
	/*********************1*********************/
	
	closeGall.onclick = function(e){
		stopEvent(e);
		gallPlace.style.display = 'none';
		
	}
	
	
}

function stopEvent(e){
	var event = e || window.event;
	event.preventDefault ? event.preventDefault() : event.returnValue = false;
}
function superOnload(fnName) {
	var ol = window.onload;
	if (typeof ol == "function") {
		window.onload = function() {
			ol();
			fnName();
		}
	}
	else {
		window.onload = fnName;
	}
}
function StartSlideShow()
{
	var st=document.getElementById('start');
	if(typeof st != 'undefined' && st!=null)
	{
		st.offsetParent.onclick();
		st.onclick();
	}
}
superOnload(gallery);
superOnload(StartSlideShow);





