// JavaScript Document

var Gallery = new Object();

Gallery.Elements = new Object();

Gallery.CurrentImage = false;

Gallery.CurrentList = false;

Gallery.UserActionsRunning = false;

Gallery.UserActionsQueue = new Array();

Gallery.PhotoPositions = new Array();

Gallery.ListPositions = new Array();

Gallery.Init = function () {
	Gallery.Elements.PhotoFrame = $('photoframe');
	Gallery.Elements.PhotoFrame.innerHTML = '';
	Gallery.Elements.Loading = new Element('div');
	Gallery.Elements.Loading.className = 'loading';
	Gallery.Elements.Loading.id = 'loading';
	Gallery.Elements.Loading.innerHTML = 'Подождите, идет загрузка';
	Gallery.Elements.Loading.style.visibility = 'hidden';
	Gallery.Elements.Loading.inject(Gallery.Elements.PhotoFrame, 'bottom');
//	Gallery.Elements.Loading.fade()
	Gallery.Elements.Loading.fade('hide');
	Gallery.Elements.Loading.style.visibility = 'visible';
	Gallery.Elements.Loading.fade('in');

	Gallery.LoadImagesData();
}

Gallery.Elements.Photos = new Array();

Gallery.DrawBasic = function () {
	if (Gallery.Images.length == 0) {
		Gallery.LoadFailure('В галерее нет фотографий.');
		return;
	}
	leftShift = Gallery.Elements.PhotoFrame.clientWidth;
	for (i=0;i<3;i++) {
		Photo = new Element('div');
		Photo.className = 'photo';
		Photo.inject(Gallery.Elements.PhotoFrame, 'bottom');
		Gallery.Elements.Photos.push(Photo);
		Gallery.Elements.Photos[i].style.left = (Math.floor((Gallery.Elements.PhotoFrame.clientWidth-Gallery.Elements.Photos[i].clientWidth)/2)-leftShift)+'px';

		leftShift = leftShift-Gallery.Elements.PhotoFrame.clientWidth;
	}
	Gallery.Elements.Photos[0].id = 'LeftPhoto';
	Gallery.Elements.Photos[1].id = 'CenterPhoto';
	Gallery.Elements.Photos[1].set('opacity', '0');
	Gallery.Elements.Photos[2].id = 'RightPhoto';

	Gallery.PhotoPositions['Left'] = Math.floor((Gallery.Elements.PhotoFrame.clientWidth-Gallery.Elements.Photos[0].clientWidth)/2)-Gallery.Elements.PhotoFrame.clientWidth;
	Gallery.PhotoPositions['Center'] = Math.floor((Gallery.Elements.PhotoFrame.clientWidth-Gallery.Elements.Photos[0].clientWidth)/2);
	Gallery.PhotoPositions['Right'] = Math.floor((Gallery.Elements.PhotoFrame.clientWidth-Gallery.Elements.Photos[0].clientWidth)/2)+Gallery.Elements.PhotoFrame.clientWidth;
	
	if (Gallery.Images.length == 1) {
		Gallery.Elements.Photos[1].style.background = 'transparent url(/i/_.gif) center repeat';
		Gallery.Elements.Photos[1].style.background = 'url('+Gallery.Images[0].photoURI+') center no-repeat';
		Gallery.Elements.Photos[1].innerHTML = '<div class="photocomment">'+Gallery.Images[0].Comment+'</div>';
		Gallery.Elements.Loading.fade('out');
		Gallery.Elements.Photos[1].fade('in');
		return;
	}
	Gallery.Elements.LeftArrow = new Element('div');
	Gallery.Elements.LeftArrow.id = 'LeftArrow';
	Gallery.Elements.LeftArrow.className = 'photoprev';
	Gallery.Elements.LeftArrow.innerHTML = '<img src="/i/_.gif">';
	Gallery.Elements.LeftArrow.inject(Gallery.Elements.PhotoFrame, 'bottom');
	Gallery.Elements.RightArrow = new Element('div');
	Gallery.Elements.RightArrow.id = 'RightArrow';
	Gallery.Elements.RightArrow.className = 'photonext';
	Gallery.Elements.RightArrow.innerHTML = '<img src="/i/_.gif">';
	Gallery.Elements.RightArrow.inject(Gallery.Elements.PhotoFrame, 'bottom');

	Gallery.Elements.LeftArrow.addEvents({
		'mouseenter': function () { Gallery.Elements.LeftArrow.className = 'photoprevover'; },
		'mouseleave': function () { Gallery.Elements.LeftArrow.className = 'photoprev'; },
		'click': Gallery.RouteUserAction
	});
	Gallery.Elements.RightArrow.addEvents({
		'mouseenter': function () { Gallery.Elements.RightArrow.className = 'photonextover'; },
		'mouseleave': function () { Gallery.Elements.RightArrow.className = 'photonext'; },
		'click': Gallery.RouteUserAction
	});
	if (Gallery.Images.length <= 7) {
		setTimeout(function () { Gallery.Elements.PhotoFrame.tween('height', 670) },250);
		Gallery.Elements.Tumbnails = new Element('div');
		Gallery.Elements.Tumbnails.id = 'tumbnailsshort';
		Gallery.Elements.Tumbnails.inject(Gallery.Elements.PhotoFrame, 'bottom');
		Gallery.Elements.TumbList = new Element('div');
		Gallery.Elements.TumbList.id = 'TumbList';
		Gallery.Elements.TumbList.className = 'list';
		Gallery.Elements.TumbList.inject(Gallery.Elements.Tumbnails, 'bottom');

		for (i=0;i<Gallery.Images.length;i++) {
			Gallery.Images[i].Element = new Element('div');
			Gallery.Images[i].Element.id = Gallery.Images[i].ID+'Link';
			Gallery.Images[i].Element.inject(Gallery.Elements.TumbList, 'bottom');
			Gallery.Images[i].Element.innerHTML = '<img src="/i/_.gif" style="background:#333333 url('+Gallery.Images[i].tumbURI+') center no-repeat;">';
			Gallery.Images[i].Element.addEvents({
				'mouseenter': Gallery.TumbnailOver,
				'mouseleave': Gallery.TumbnailOut,
				'click': Gallery.RouteUserAction
			});
		}
		Gallery.ShowPhotoByClick();
		return;
	}
	setTimeout(function () { Gallery.Elements.PhotoFrame.tween('height', 680) },250);
	Gallery.Elements.Tumbnails = new Element('div');
	Gallery.Elements.Tumbnails.id = 'tumbnails';
	Gallery.Elements.Tumbnails.inject(Gallery.Elements.PhotoFrame, 'bottom');

	Gallery.Elements.ListCounter = new Element('div');
	Gallery.Elements.ListCounter.id = 'ListCounter';
	Gallery.Elements.ListCounter.className = 'listcounter';
	Gallery.Elements.ListCounter.inject(Gallery.Elements.Tumbnails,'bottom');

	counter = 0;
	Gallery.Elements.TumbLists = new Array();
	Gallery.Elements.ListCounters = new Array();
	for (i=0;i<Gallery.Images.length;i++) {
		if (counter == 0) {
			List = new Element('div');
			List.id = 'TumbList'+Gallery.Elements.TumbLists.length;
			List.className = 'list';
			List.inject(Gallery.Elements.Tumbnails,'bottom');
			if (Gallery.Elements.TumbLists.length == 0) {
				Gallery.ListPositions['Center'] = Math.round((Gallery.Elements.Tumbnails.clientWidth-List.clientWidth)/2);
				Gallery.ListPositions['Right'] = Gallery.ListPositions['Center']*2+List.clientWidth+1;
				Gallery.ListPositions['Left'] = 0-List.clientWidth-1;
			}
			List.style.left = Gallery.ListPositions['Right']+'px';
			List.set('opacity', '0');
			Gallery.Elements.TumbLists.push(List);

			ListCount = new Element('img');
			ListCount.src = '/i/_.gif';
			ListCount.id = 'ListCounter'+Gallery.Elements.TumbLists.length;
			ListCount.inject(Gallery.Elements.ListCounter,'bottom');
//			ListCounter.set('opacity', '0');
			Gallery.Elements.ListCounters.push(ListCount);
		}
		
		Gallery.Images[i].Element = new Element('div');
		Gallery.Images[i].Element.id = Gallery.Images[i].ID+'Link';
		Gallery.Images[i].Element.inject(Gallery.Elements.TumbLists[Gallery.Elements.TumbLists.length-1], 'bottom');
		Gallery.Images[i].Element.innerHTML = '<img src="/i/_.gif" style="background:#333333 url('+Gallery.Images[i].tumbURI+') center no-repeat;">';
		Gallery.Images[i].Element.addEvents({
			'mouseenter': Gallery.TumbnailOver,
			'mouseleave': Gallery.TumbnailOut,
			'click': Gallery.RouteUserAction
		});
		
		counter++;
		if (counter > 5) counter = 0;
	}

	Gallery.Elements.ListLeftArrow = new Element('div');
	Gallery.Elements.ListLeftArrow.id = 'ListLeftArrow';
	Gallery.Elements.ListLeftArrow.className = 'listprev';
	Gallery.Elements.ListLeftArrow.innerHTML = '<img src="/i/_.gif">';
	Gallery.Elements.ListLeftArrow.inject(Gallery.Elements.PhotoFrame, 'bottom');
	Gallery.Elements.ListRightArrow = new Element('div');
	Gallery.Elements.ListRightArrow.id = 'ListRightArrow';
	Gallery.Elements.ListRightArrow.className = 'listnext';
	Gallery.Elements.ListRightArrow.innerHTML = '<img src="/i/_.gif">';
	Gallery.Elements.ListRightArrow.inject(Gallery.Elements.PhotoFrame, 'bottom');

	Gallery.Elements.ListLeftArrow.addEvents({
		'mouseenter': function () { Gallery.Elements.ListLeftArrow.className = 'listprevover'; },
		'mouseleave': function () { Gallery.Elements.ListLeftArrow.className = 'listprev'; },
		'click': Gallery.RouteUserAction
	});
	Gallery.Elements.ListRightArrow.addEvents({
		'mouseenter': function () { Gallery.Elements.ListRightArrow.className = 'listnextover'; },
		'mouseleave': function () { Gallery.Elements.ListRightArrow.className = 'listnext'; },
		'click': Gallery.RouteUserAction
	});

//	Gallery.Elements.Loading.fade('out');
	setTimeout(function () { Gallery.Elements.PhotoFrame.tween('height', 680); },250);
	Gallery.ShowPhotoByClick();

}

Gallery.RouteUserAction = function (e) {
	e = e || window.event;
	obj = e.srcElement || e.target;
	while (obj.id == '') { obj = obj.parentNode; }
	Gallery.UserActionsQueue.push(obj);
//	Message("OK",1);
	if (!Gallery.UserActionsRunning) Gallery.RunQueuedUserAction();
}

Gallery.RunQueuedUserAction = function () {
	if (Gallery.UserActionsQueue.length == 0) { Gallery.UserActionsRunning = false; return; }
	Gallery.UserActionsRunning = true;
	obj = Gallery.UserActionsQueue.shift();
	if (obj.id.match(/^Image\d*Link$/)) { Gallery.ShowPhotoByClick(obj); return; }
	if (obj.id == 'ListLeftArrow' || obj.id == 'ListRightArrow') { Gallery.SlideTumbnails(obj); return; }
	if (obj.id == 'LeftArrow' || obj.id == 'RightArrow') { Gallery.SlidePhoto(obj); return; }
	Gallery.RunQueuedUserAction();
}

Gallery.SlidePhoto = function (obj) {
	CurrentImageNumber = Number(Gallery.CurrentImage.ID.replace(/\D/g, ''));
	if (obj.id.indexOf('Left') > -1) {
		Direction = -1;
		NewPhotoEl = $('LeftPhoto');
		ReplacePhotoEl = $('RightPhoto');
		NewImageStartPosition = Gallery.PhotoPositions['Left'];
		CurrentImageEndPosition = Gallery.PhotoPositions['Right'];
	}
	else {
		Direction = 1;
		NewPhotoEl = $('RightPhoto');
		ReplacePhotoEl = $('LeftPhoto');
		NewImageStartPosition = Gallery.PhotoPositions['Right'];
		CurrentImageEndPosition = Gallery.PhotoPositions['Left'];
	}
	NewImageNumber = Number(CurrentImageNumber+Direction);
	if (NewImageNumber < 0) { NewImageNumber = Gallery.Images.length-1; }
	if (NewImageNumber >= Gallery.Images.length) { NewImageNumber = 0; }
	NewImage = Gallery.Images[NewImageNumber];
	var ElementsList = false;
	if (Gallery.Elements.TumbLists) {
		ElementsList = Gallery.Elements.TumbLists[Math.floor(NewImageNumber/6)];
//		Gallery.CurrentList = ElementsList;
	}
	else {
		ElementsList = Gallery.Elements.TumbList;
		Gallery.CurrentList = Gallery.Elements.TumbList;
	}
	CenterPhotoEl = $('CenterPhoto');
	CenterPhotoEl.id = ReplacePhotoEl.id;
	ReplacePhotoEl.id = NewPhotoEl.id;
	NewPhotoEl.id = 'CenterPhoto';
	ReplacePhotoEl.style.left = NewImageStartPosition+'px';
	Gallery.CurrentImage.Element.className = '';
	Gallery.CurrentImage = NewImage;
	Gallery.Elements.Loading.set('opacity',0);
	if (Gallery.CurrentList.id == ElementsList.id) {
		var myFx = new Fx.Elements(new Array(NewPhotoEl, CenterPhotoEl), {
		//	'duration':'long',
		    onComplete: function(){
//				self.location.hash = '#'+Gallery.CurrentImage.ID.replace(/\D/g, '');
				Gallery.Elements.Loading.innerHTML = '';
				Gallery.Elements.Loading.set('opacity',1);
				Gallery.CurrentImage.Element.className = 'here';
				Gallery.PreloadSideImages();
				Gallery.RunQueuedUserAction();
				return;
		    }
			}).start({
			    '0': {'left': [NewImageStartPosition, Gallery.PhotoPositions['Center']]},
		    	'1': {'left': [Gallery.PhotoPositions['Center'], CurrentImageEndPosition]}
		});
	}
	else {
		NewListNumber = Number(ElementsList.id.replace(/\D/g, ''));
		CurrentListNumber = Number(Gallery.CurrentList.id.replace(/\D/g, ''));
		Gallery.CurrentList = ElementsList;
		if (CurrentListNumber == 0 && NewListNumber == Gallery.Elements.TumbLists.length-1 && obj.id.indexOf('Left') > -1) {
			NewListStartPosition = Gallery.ListPositions['Left']; CurrentListEndPosition = Gallery.ListPositions['Right'];
		}
		else {
			if (NewListNumber < CurrentListNumber) {
				NewListStartPosition = Gallery.ListPositions['Left']; CurrentListEndPosition = Gallery.ListPositions['Right'];
			}
			else {
				NewListStartPosition = Gallery.ListPositions['Right']; CurrentListEndPosition = Gallery.ListPositions['Left'];
			}
		}
		if (obj.id.indexOf('Left') > -1) {
			if (NewListNumber > CurrentListNumber && !(NewListNumber == Gallery.Elements.TumbLists.length-1 && CurrentListNumber == 0)) {
				NewListStartPosition = Gallery.ListPositions['Right']; CurrentListEndPosition = Gallery.ListPositions['Left'];
			}
			else {
				NewListStartPosition = Gallery.ListPositions['Left']; CurrentListEndPosition = Gallery.ListPositions['Right'];
			}
			
		}
		else {
			if (NewListNumber < CurrentListNumber && !(NewListNumber == 0 && CurrentListNumber == Gallery.Elements.TumbLists.length-1)) {
				NewListStartPosition = Gallery.ListPositions['Left']; CurrentListEndPosition = Gallery.ListPositions['Right'];
			}
			else {
				NewListStartPosition = Gallery.ListPositions['Right']; CurrentListEndPosition = Gallery.ListPositions['Left'];
			}
		}
		Gallery.CurrentList.style.left = NewListStartPosition+'px';
		Gallery.CurrentList.set('opacity',1);
		for(i=0;i<Gallery.Elements.ListCounters.length;i++) { Gallery.Elements.ListCounters[i].className = ''; }
		Gallery.Elements.Loading.set('opacity',0);
		var myFx = new Fx.Elements(new Array(NewPhotoEl, CenterPhotoEl, $('TumbList'+NewListNumber), $('TumbList'+CurrentListNumber)), {
		//	'duration':'long',
		    onComplete: function(){
//				self.location.hash = '#'+Gallery.CurrentImage.ID.replace(/\D/g, '');
				Gallery.Elements.Loading.innerHTML = '';
				Gallery.Elements.Loading.set('opacity',1);
				Gallery.CurrentImage.Element.className = 'here';
				Gallery.PreloadSideImages();
				Gallery.RunQueuedUserAction();
				return;
		    }
			}).start({
			    '0': {'left': [NewImageStartPosition, Gallery.PhotoPositions['Center']]},
		    	'1': {'left': [Gallery.PhotoPositions['Center'], CurrentImageEndPosition]},
			    '2': {'left': [NewListStartPosition, Gallery.ListPositions['Center']]},
			    '3': {'left': [Gallery.ListPositions['Center'], CurrentListEndPosition]}
		});
	}
}

Gallery.SlideTumbnails = function (obj) {
	CurrentListNumber = Number(Gallery.CurrentList.id.replace(/\D/g, ''));
	if (obj.id.indexOf('Left') > -1) { Direction = -1; NewListStartPosition = Gallery.ListPositions['Left']; CurrentListEndPosition = Gallery.ListPositions['Right']; }
	else { Direction = 1; NewListStartPosition = Gallery.ListPositions['Right']; CurrentListEndPosition = Gallery.ListPositions['Left']; }
	NewListNumber = CurrentListNumber+Direction;
	if (NewListNumber < 0) { NewListNumber = Gallery.Elements.TumbLists.length-1; }
	if (NewListNumber >= Gallery.Elements.TumbLists.length) { NewListNumber = 0; }
//	$('TumbList'+NewListNumber).set('opacity', '1');
	$('TumbList'+NewListNumber).set('opacity', '1');
	if (Gallery.Elements.ListCounters) {
		for(i=0;i<Gallery.Elements.ListCounters.length;i++) { Gallery.Elements.ListCounters[i].className = ''; }
//		$('ListCounter'+(NewListNumber+1)).className = 'here';
	}

	
	Gallery.CurrentList = $('TumbList'+NewListNumber);
	var myFx = new Fx.Elements(new Array($('TumbList'+NewListNumber), $('TumbList'+CurrentListNumber)), {
//	'duration':'long',
    onComplete: function(){
		Gallery.PreloadSideImages();
		Gallery.RunQueuedUserAction();
		return;
    }
	}).start({
	    '0': {'left': [NewListStartPosition, Gallery.ListPositions['Center']]},
	    '1': {'left': [Gallery.ListPositions['Center'], CurrentListEndPosition]}
	});
	
}

Gallery.ShowPhotoByClick = function (obj) {
	if (!obj) {
		obj = Gallery.Images[0].Element;
		hash = Number(self.location.hash.replace(/\D/g, ''));
		if (hash && hash <= Gallery.Images.length && hash > 0) {
			obj = Gallery.Images[hash-1].Element;
			$('photonumber').innerHTML = 'Фотография '+hash;
			$('photonumber').href = '/gallery/#'+hash;
		}
		else { 
			$('photonumber').innerHtml = 'Фотография 1';
			$('photonumber').href = '/gallery/#1';
		}
	}
	if (Gallery.Elements.TumbLists) {
		ElementsList = Gallery.Elements.TumbLists[Math.floor(Number(obj.id.replace(/\D/g, ''))/6)];
		Gallery.CurrentList = ElementsList;
		ElementsListCounter = Gallery.Elements.ListCounters[Math.floor(Number(obj.id.replace(/\D/g, ''))/6)];
	}
	else {
		ElementsList = Gallery.Elements.TumbList;
		Gallery.CurrentList = Gallery.Elements.TumbList;
	}
	Gallery.NewImage = Gallery.Images[Number(obj.id.replace(/\D/g, ''))];
	if (Gallery.CurrentImage) {
		if (Gallery.CurrentImage.ID == Gallery.NewImage.ID) { Gallery.RunQueuedUserAction(); return; }
		CurrentImageList = Gallery.Elements.TumbLists[Math.floor(Number(Gallery.CurrentImage.Element.id.replace(/\D/g, ''))/6)];
		if (CurrentImageList != ElementsList) {
			CurrentImageList.fade('out');
			ElementsList.fade('in');
			Gallery.CurrentList = ElementsList;
		}
		
		Gallery.Elements.Loading.set('opacity',0);
		$('CenterPhoto').set('tween', {
			onComplete: function() {
				Gallery.CurrentImage.Element.className = '';
				Gallery.NewImage.Element.className = 'here';
				if (Gallery.Elements.ListCounters) {
					ElementsListCounter = Gallery.Elements.ListCounters[Math.floor(Number(Gallery.NewImage.Element.id.replace(/\D/g, ''))/6)];
					for(i=0;i<Gallery.Elements.ListCounters.length;i++) {
						Gallery.Elements.ListCounters[i].className = '';
					}
					if (ElementsListCounter) { ElementsListCounter.className = 'here'; }
				}
				Gallery.CurrentImage = Gallery.NewImage;
//				self.location.hash = '#'+(Number(Gallery.NewImage.ID.replace(/\D/g, '')));
				$('CenterPhoto').style.background = 'transparent url(/i/_.gif) center repeat';
				$('CenterPhoto').style.background = 'url('+Gallery.NewImage.photoURI+') center no-repeat';
				$('CenterPhoto').innerHTML = '<div class="photocomment">'+Gallery.NewImage.Comment+'</div>';
				$('CenterPhoto').set('tween', {
					onComplete: function() {
						Gallery.Elements.Loading.innerHTML = '';
						Gallery.Elements.Loading.set('opacity',1);
						Gallery.PreloadSideImages();
						Gallery.RunQueuedUserAction();
						return;
					}
				});
				$('CenterPhoto').tween('opacity', '1');
			}
		});
		$('CenterPhoto').tween('opacity', '0');
	}
	else {
		ElementsList.style.left = Gallery.ListPositions['Center']+'px';
		ElementsList.set('opacity', '1');
		obj.className = 'here';
		if (ElementsListCounter) { ElementsListCounter.className = 'here'; }
		Gallery.Elements.Loading.fade('out');
		$('CenterPhoto').style.background = 'transparent url(/i/_.gif) center repeat';
		$('CenterPhoto').style.background = 'url('+Gallery.NewImage.photoURI+') center no-repeat';
		$('CenterPhoto').innerHTML = '<div class="photocomment">'+Gallery.NewImage.Comment+'</div>';
		Gallery.CurrentImage = Gallery.NewImage;
		$('CenterPhoto').set('tween', {
			onComplete: function() {
				Gallery.Elements.Loading.innerHTML = '';
				Gallery.Elements.Loading.set('opacity',1);
				Gallery.PreloadSideImages();
				Gallery.RunQueuedUserAction();
				return;
			}
		});
		$('CenterPhoto').tween('opacity', '1');
	}
	
	
}

Gallery.TumbnailOver = function (e) {
	e = e || window.event;
	obj = e.srcElement || e.target;
	while (obj.id == '') { obj = obj.parentNode; }
	if (obj.className != 'here') obj.className = 'over';
}

Gallery.TumbnailOut = function (e) {
	e = e || window.event;
	obj = e.srcElement || e.target;
	while (obj.id == '') { obj = obj.parentNode; }
	if (obj.className != 'here') obj.className = '';
}


Gallery.LoadFailure = function (message) {
	Gallery.Elements.Loading.style.background = 'url(/i/failure.gif) top no-repeat';
	Gallery.Elements.Loading.innerHTML = message;
	Gallery.Elements.Loading.fade('in');
}

Gallery.Images = new Array()

Gallery.LoadImagesData = function () {
	Gallery.CurrentRequest = new Request({
		url: '/gallery/list.html',
		method: 'get',
		onComplete: function(responseText) {
			strings = responseText.split("\n");
			for (i=0;i<strings.length;i++) {
				if (strings[i].search(/\|\|/g) > -1) {
					values = strings[i].split("||");
					values[0] = values[0].replace(/(^(\s)*|(\s)*$)/g, "");
					values[1] = values[1].replace(/(^(\s)*|(\s)*$)/g, "");
					values[2] = values[2].replace(/(^(\s)*|(\s)*$)/g, "");
//					if (Gallery.Images.length == 7) break;
					Gallery.Images.push(new Gallery.Photo(values[0],values[1],values[2]));
				}
			}
			Gallery.DrawBasic();
		},
		onFailure: function(transport) {
			Gallery.Elements.Loading.fade('out')
			Gallery.LoadFailure('Ошибка. Не удалось загрузить данные фотографий.');
		}
	}).send();
}

Gallery.Photo = function (photoURI, tumbURI, Comment) {
	this.photoURI = photoURI;
	this.tumbURI = tumbURI;
	this.Comment = Comment;
	this.Loaded = false;
	this.ID = 'Image'+Gallery.Images.length;
	return this;
}

Gallery.PreloadSideImages = function () {
	num = Gallery.CurrentImage.ID.replace(/\D/g, '');
	$('photonumber').innerHTML = 'Фотография '+(num*1+1);
	$('photonumber').href = '/gallery/#'+(num*1+1);
	right = num*1+1;
	if (right >= Gallery.Images.length) right = 0;
	left = num-1;
	if (left < 0) left = Gallery.Images.length-1;
	$('LeftPhoto').style.background = 'transparent url(/i/_.gif) center repeat';
	$('LeftPhoto').style.background = 'url('+Gallery.Images[left].photoURI+') center no-repeat';
	$('LeftPhoto').innerHTML = '<div class="photocomment">'+Gallery.Images[left].Comment+'</div>';
	$('RightPhoto').style.background = 'transparent url(/i/_.gif) center repeat';
	$('RightPhoto').style.background = 'url('+Gallery.Images[right].photoURI+') center no-repeat';
	$('RightPhoto').innerHTML = '<div class="photocomment">'+Gallery.Images[right].Comment+'</div>';
	for (i=0;i<Gallery.Elements.TumbLists.length;i++) {
		if (Gallery.CurrentList.id != Gallery.Elements.TumbLists[i].id){
			Gallery.Elements.TumbLists[i].set('opacity','0');
			Gallery.Elements.TumbLists[i].set('left',Gallery.ListPositions['Center']);
		}
		else {
			$('ListCounter'+(i+1)).className = 'here';
		}
	}
}


Gallery.FadeIn = function (obj, func) {
	func = func || function () { return; }
	obj.set('tween', { onComplete: func })
	obj.tween('opacity', '1');
}

Gallery.FadeOut = function (obj, func) {
	func = func || function () { return; }
	obj.set('tween', { onComplete: func })
	obj.tween('opacity', '0');
}


window.addEvent('domready', Gallery.Init);
