function sandy (oDiv) {

	this.sConfig  = {slideFps : 50,slideFrames : 30,slideHeight : 525,sDirection : 1};
	this.fActive = false;
	this.oWorkspace = false;
	this.canvas = oDiv;	
	this.oLayer = false;
	if (oDiv.getAttribute("backgrounds")) this.backgrounds = oDiv.getAttribute("backgrounds").split("-");
	this.oWindow = oDiv.parentNode.insertBefore(document.createElement("DIV"),oDiv);
	sandySetProps(this.oWindow.style,"position,absolute,top,113px,left,0px,width,640px,height,490px,zIndex,10,overflow,hidden,display,none");
	this.oWindow.appendChild(document.createElement("DIV"));
	this.oPane = document.createElement("DIV");
	sandySetProps(this.oPane.style,"position,absolute,top,0px,left,0px,width,640px,height,490px,zIndex,5,overflow,hidden,visibility,visible");	
	this.fState = false;
	this.Idle = false;
	this.fTimer = null;
	this.fIndex = 0;
	this.slideActive = false;
	this.pType = false;
	this.cBack = false;
	this.canvas.style.display = 'none';
	sandyLoader.init();
	sandyBg.init(oDiv);

}

sandy.prototype.born = function () {

	this.fActive = true;
	if (document.location.hash.length > 1) {
		this.navigate(document.location.hash.substring(1),true);
	} else {
		this.navigate('index/',true);
	}

}

sandy.prototype.navigate = function (pUrl,aFirst) {

	var oRef = this;
	this.Idle = false;
	sandyLoader.start();
	sandyGallery.stop();
	this.canvas.style.display = 'none';
	var cBack = function (msg,state) {
		oRef.preload(msg,state);
	}; 	sandyXml.getString(pUrl+'?ajax='+(aFirst ? 2 : 1),cBack);

}

sandy.prototype.showError = function (eStr) {

	sandyLoader.stop();
	this.oWindow.style.display = 'none';
	this.canvas.innerHTML = eStr;
	this.canvas.style.display = 'block';
	this.Idle = true;
	this.slideActive = 0;
	return false;

}

sandy.prototype.preload = function (tData,oState) {

	var oRef = this;	
	var cBack = false;
	if (oState) {
		this.cBack = false;
		var cache = document.createElement("DIV");
		cache.innerHTML = tData;
		if ((this.oWorkspace = sandyNextSibling(cache.childNodes.item(0),'div')) && this.oWorkspace.className) {
			this.fState = this.oWorkspace.className;
			switch (this.fState) {
				case "entry":
					sandyMenu.init(this.canvas,this.oWorkspace);
					sandyGallery.create(this.oPane,this.oWorkspace);
					cBack = function () {
						oRef.transition(false);
						sandyGallery.play();
					}; mySandy.cBack = function (cBack) {sandyMenu.show(cBack)};
				break;
				case "text":
					sandyMenu.init(this.canvas,this.oWorkspace);
					cBack = sandyTextPage.init(this.oPane,this.oWorkspace);
				break;
				case "contacts":
					sandyMenu.init(this.canvas,this.oWorkspace);
					cBack = sandyContactsPage.init(this.oPane,this.oWorkspace);
				break;
				case "catalog":
					sandyMenu.init(this.canvas,this.oWorkspace);
					cBack = sandyCatalogPage.init(this.oPane,this.oWorkspace);
				break;
				case "project":
					sandyMenu.init(this.canvas,this.oWorkspace);
					cBack = sandyProjectPage.init(this.oPane,this.oWorkspace);
					sandyGallery.create(this.oPane,this.oWorkspace,sandyProjectPage.oSlides);
				break;
				default:
					return this.showError('Невозможно загрузить указанный шаблон отображения...');
			}
		} else {
			return this.showError('Невозможно загрузить указанный шаблон отображения...');
		} sandyLoader.preload(cBack);
	} else {
		this.showError('При загрузке данных с сервера произошла ошибка...');
	}

}

sandy.prototype.slide = function (oDir) {
	
	if (this.sConfig.sDirection > 0) {
		this.oLayer.style.top = Math.round(sandyMath.cubicOut(this.fIndex, 0, this.sConfig.slideHeight, this.sConfig.slideFrames) - 525) + 'px';
	} else {
		this.oLayer.style.top = (Math.round(sandyMath.cubicIn(this.fIndex, 0, this.sConfig.slideHeight, this.sConfig.slideFrames)) * - 1) + 'px';
	} this.fIndex++;
	if (this.fIndex == this.sConfig.slideFrames) {
		clearInterval(this.fTimer);
		this.oLayer.style.zIndex = 5;		
		if (this.oWindow.childNodes.length > 1) {
			this.oWindow.removeChild(this.oWindow.childNodes.item(0));
		} 
		this.slideActive = oDir ? oDir : this.sConfig.sDirection;
		if (this.slideActive) {
			this.Idle = true;
		} else {
			var oRef = this;
			var cBack = function () { oRef.show()};
			sandyBg.next(cBack);
			this.oLayer.style.visibility = 'hidden';
		} this.oLayer = false;
	}

}

sandy.prototype.transition = function (f) {

	if (f) {
		this.overlay(f);
	} else {
		if (this.slideActive) {
			this.hide();
		} else {
			this.show();
		}
	}

}

sandy.prototype.hide = function () {

	if (this.fActive) {
		this.fIndex = 0;
		this.sConfig.sDirection = 0;
		this.oLayer = this.oWindow.childNodes.item(0);
		this.fTimer = setInterval("mySandy.slide()",this.sConfig.slideFps);
	}

}

sandy.prototype.overlay = function (oDir) {

	if (this.fActive) {
		if (oDir == 2) {
			this.oLayer = this.oWindow.childNodes.item(0);
			this.oLayer.style.zIndex = 10;
			this.oPane.style.top = '0px';
			this.oPane.style.zIndex = 0;
			this.oWindow.appendChild(this.oPane);			
			this.sConfig.sDirection = 0;
		} else {
			this.oWindow.appendChild(this.oPane);
			this.oLayer = this.oPane;			
			this.sConfig.sDirection = 1;
			this.oLayer.style.top = (this.sConfig.slideHeight * -1)+'px';
			this.oLayer.style.zIndex = 10;
		} this.oWindow.style.display = 'block';
		this.oPane = this.oPane.cloneNode(false);
		this.fIndex = 0;		
		this.fTimer = setInterval("mySandy.slide("+oDir+")",this.sConfig.slideFps);
	}

}

sandy.prototype.show = function () {

	if (this.fActive) {
		this.oWindow.replaceChild(this.oPane,this.oWindow.childNodes.item(0));
		this.oLayer = this.oWindow.childNodes.item(0);
		this.oLayer.style.top = (this.sConfig.slideHeight * -1)+'px';
		this.oWindow.style.display = 'block';
		this.oPane = this.oPane.cloneNode(false);
		this.fIndex = 0;
		this.sConfig.sDirection = 1;
		this.fTimer = setInterval("mySandy.slide()",this.sConfig.slideFps);
	}

}

var sandyProjectPage = {

	oDiv : null,
	oSlides : null,
	oTimeout : null,
	fIndex : 0,
	mActive : null,
	fTimer : null,
	sConfig  : {slideFps : 50,slideFrames : 15,slideHeight : 193,sDirection : 1},
	
	init : function (oDiv,oWorkspace) {

		var a,b,c;
		var cBack = false;
		if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_project_page')) {
			this.mActive = 1;
			c = document.createElement("DIV");
			c.className = "InfoHouseContainer";
			c.innerHTML = a.innerHTML;
			if (this.oSlides = sandyNextSibling(c.childNodes.item(0),'div','SmallGalleryContainer')) {				
				this.oDiv = document.createElement("DIV");
				b = this.oDiv.appendChild(document.createElement("DIV"));
				b.className = 'InfoHouseBg';
				b.appendChild(document.createElement("DIV"));
				b = this.oDiv.appendChild(document.createElement("DIV"));
				b.className = 'InfoHouseIn';
				b.appendChild(c);
				oDiv.appendChild(this.oDiv);
				sandySetProps(this.oDiv.style,"width,640px,height,193px,position,absolute,zIndex,10,top,267px");
				cBack = function () {
					mySandy.transition(1);
					sandyProjectPage.oTimeout = setTimeout("sandyProjectPage.hide()",3000);
				}; mySandy.cBack = function (cBack) {sandyMenu.show(cBack)};
				mySandy.pType = 'project';
				oDiv.appendChild(this.oDiv);
				b = oDiv.appendChild(document.createElement("DIV"));
				b.className = 'InfoBoxIn';
				b.onmouseover = function (e) {sandyProjectPage.show();};				
				b = b.appendChild(document.createElement("DIV"));
				b.className = 'Return';
				b.innerHTML = '<a href="#/projects/">К списку проектов</a>';
				b.parentNode.appendChild(document.createTextNode(oWorkspace.getAttribute("title")));
				b.onclick = function (e) {return sandyProjectPage.back('/projects/');}

			}
		} return cBack;

	},
	
	back : function (oLink) {

		if (!mySandy.Idle) return false;
		mySandy.navigate(oLink);
		return true;

	},
	
	check : function (e) {

		if (!mySandy.Idle) return false;
		var target = e ? e.target : window.event.srcElement;
		do {
			if (target == this.oDiv) {
				if (this.oTimeout) {
					clearTimeout(this.oTimeout);
					this.oTimeout = 0;
				} return false;
			} 
		} while (target = target.parentNode);
		if (!this.oTimeout && this.mActive) {
			this.oTimeout = setTimeout("sandyProjectPage.hide()",1000);
		}

	},

	show : function () {

		if (!mySandy.Idle) return false;
		if (this.oTimeout) {
			clearTimeout(this.oTimeout);
			this.oTimeout = 0;
		} if (!this.mActive) {
			this.fIndex = 0;
			mySandy.Idle = false;
			this.sConfig.sDirection = 1;
			this.fTimer = setInterval("sandyProjectPage.animate()",this.sConfig.slideFps);
		}

	},
	
	hide : function () {

		if (!mySandy.Idle) return false;
		if (this.mActive) {
			this.fIndex = 0;
			mySandy.Idle = false;
			this.sConfig.sDirection = 0;
			this.fTimer = setInterval("sandyProjectPage.animate()",this.sConfig.slideFps);
		}

	},
	
	animate : function () {

		if (this.sConfig.sDirection > 0) {
			this.oDiv.style.top = (460 - Math.round(sandyMath.cubicOut(this.fIndex, 0, this.sConfig.slideHeight, this.sConfig.slideFrames))) + 'px';
		} else {
			this.oDiv.style.top = Math.round(sandyMath.cubicIn(this.fIndex, 0, this.sConfig.slideHeight, this.sConfig.slideFrames) + 267) + 'px';			
		} this.fIndex++;
		if (this.fIndex > this.sConfig.slideFrames) {
			clearInterval(this.fTimer);
			this.fTimer = 0;
			mySandy.Idle = true;
			this.mActive = this.sConfig.sDirection;
		}

	}

}

var sandyCatalogPage = {
	
	oDiv : null,
	pCount : 0,
	oScroll : null,
	iScroll : false,
	sConfig : {dHeight : 460,pCount : 6, rSize : 77},
	
	init : function (oDiv,oWorkspace) {

		var a,b;
		var cBack = false;
		this.pCount = 0;
		this.iScroll = false;
		if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_catalog_page')) {
			if (oWorkspace.getAttribute("pid")) {
				sandyMenu.select(oWorkspace.getAttribute("pid"));
			} if (b = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_catalog_pdf')) {
				oDiv.innerHTML = b.innerHTML;
			} b = document.createElement("DIV");
			b.className = "TextIn";
			b.innerHTML = a.innerHTML;
			if (this.oDiv = sandyNextSibling(b.childNodes.item(0),'div','CatalogRight')) {
				var projects = this.oDiv.getElementsByTagName("span");
				while (projects.length) {
					this.pCount++;
					c = this.oDiv.removeChild(projects[0]);
					this.oDiv.appendChild(this.createItem(c));
				}
			} if (this.pCount > 6) {
				this.counter(this.oDiv);
			} oDiv.appendChild(b);
			if (mySandy.pType == 'project') {
				cBack = function () {mySandy.transition(2)};
			} else {
				cBack = function () {mySandy.transition(false)};					
			} mySandy.cBack = function (cBack) {sandyMenu.show(cBack)};
			mySandy.pType = 'catalog';
		} return cBack;

	},

	counter : function (oElem) {

		this.sConfig.height = this.pCount * 77;
		this.sConfig.sDistance = this.sConfig.height - this.sConfig.dHeight;
		this.sConfig.size = Math.round(this.sConfig.dHeight * this.sConfig.pCount / this.pCount);
		if (this.sConfig.size < this.sConfig.rSize) this.sConfig.size = this.sConfig.rSize;
		this.sConfig.distance = this.sConfig.dHeight - this.sConfig.size;
		var a = document.createElement("DIV");
		oElem.parentNode.replaceChild(a,oElem);
		a.className = 'CatalogRight';
		oElem.className = 'CatalogScroll';
		oElem.style.height= this.sConfig.height+'px';
		a.appendChild(oElem);
		this.oScroll = a.appendChild(document.createElement("DIV"));		
		this.oScroll.className = 'scrollPointer';
		a = this.oScroll.appendChild(document.createElement("IMG"));
		sandySetProps(a,"width,11,height,11,src,/img/sc_up.gif");
		a = this.oScroll.appendChild(document.createElement("DIV"));
		sandySetProps(a.style,"width,9px,margin,0px 1px,height,"+(this.sConfig.size - 22)+"px,background,#799e00");
		a = this.oScroll.appendChild(document.createElement("IMG"));
		sandySetProps(a,"width,11,height,11,src,/img/sc_dn.gif");
		a = this.oScroll.parentNode.appendChild(document.createElement("DIV"));
		a.className = 'scrollArea';
		a.onmousedown = function (e) {			
			var sOffset = e ? e.clientY : window.event.clientY;			
			var sPos = e ? (e.layerY ? e.layerY : e.offsetY) : window.event.offsetY;
			sandyCatalogPage.sConfig.offset = sOffset - sPos;
			sandyCatalogPage.iScroll = true;
			mySandy.Idle = false;
			return sandyBlockEvent(e);
		}; document.onmousemove = function (e) { 
			if (sandyCatalogPage.iScroll) {
				sandyCatalogPage.align(e);
			} return sandyBlockEvent(e);
		}; document.onmouseup = function (e) {
			if (sandyCatalogPage.iScroll) {
				sandyCatalogPage.iScroll = false;
				mySandy.Idle = true;
			} return sandyBlockEvent(e);
		};

	},

	align : function (e) {
		
		var sPos = e ? e.clientY : window.event.clientY;
		sPos = sPos - this.sConfig.offset;
		if (sPos < this.sConfig.size / 2) sPos = Math.round(this.sConfig.size/2);
		if (sPos > (460 - this.sConfig.size / 2)) sPos = Math.round(460 - this.sConfig.size/2);
		this.oScroll.style.top = Math.round(sPos - this.sConfig.size/2)+'px';
		dPos = Math.round(sPos - this.sConfig.size/2);
		dPos = Math.round(this.sConfig.sDistance*dPos/this.sConfig.distance) * -1;
		this.oDiv.style.top = dPos+'px';

	},

	createItem : function (oElem) {

		var oDiv = document.createElement("DIV");
		oDiv.style.cursor = 'pointer';
		var a = oDiv.appendChild(document.createElement("DIV"));
		a.appendChild(document.createElement("DIV"));
		a.className = "ActiveHouse";
		a.style.display = 'none';
		a = oDiv.appendChild(document.createElement("DIV"));
		a.appendChild(document.createElement("DIV"));
		a.className = "ActiveFrame";
		a.style.display = 'none';
		a = oDiv.appendChild(document.createElement("DIV"));
		a.className = "HouseList";
		sandyLoader.defer(oElem.getAttribute("picture"));
		a.innerHTML = '<img src="'+oElem.getAttribute("picture")+'" width="100" alt=""/>'+oElem.innerHTML;
		a = oDiv.appendChild(document.createElement("DIV"));
		a.className = "SpacerList";
		a.appendChild(document.createElement("DIV"));
		oDiv.onmouseover = function (e) {if (!mySandy.Idle) return false; oDiv.childNodes.item(0).style.display = 'block'; oDiv.childNodes.item(1).style.display = 'block';}
		oDiv.onmouseout = function (e) {if (!mySandy.Idle) return false; oDiv.childNodes.item(0).style.display = 'none'; oDiv.childNodes.item(1).style.display = 'none';}
		var oLink = oElem.getAttribute("title");
		oDiv.onclick= function () {return sandyCatalogPage.click(oLink);}
		return oDiv;

	},

	click : function (oLink) {

		if (!mySandy.Idle) return false;
		document.location.href = '#'+oLink;		
		mySandy.navigate(oLink);
		return true;

	}

}

var sandyContactsPage = {

	init : function (oDiv,oWorkspace) {
	
		var a,b,c;
		var oRef = this;
		var cBack = false;
		if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_contacts_page')) {
			if (oWorkspace.getAttribute("pid")) {
				sandyMenu.select(oWorkspace.getAttribute("pid"));
			} b = document.createElement("DIV");
			b.className = "TextIn";
			b.innerHTML = a.innerHTML;
			c = b.getElementsByTagName("form");
			if (c.length) c[0].onsubmit = function (e) {return false;}
			oDiv.appendChild(b);
			cBack = function () {mySandy.transition(false)};
			mySandy.cBack = function (cBack) {sandyMenu.show(cBack)};
			mySandy.pType = 'contacts';
		} return cBack;

	}

}

var sandyTextPage = {

	blocks : null,
	inside : null,
	oDiv : null,

	init : function (oDiv,oWorkspace) {

		var a,b,c,d,z;
		var cBack = false;
		this.inside = false;
		if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_text_page')) {
			this.oDiv = oDiv;
			if (oWorkspace.getAttribute("pid")) {
				sandyMenu.select(oWorkspace.getAttribute("pid"));
			} b = document.createElement("DIV");
			b.className = "TextIn";
			b.innerHTML = a.innerHTML;			
			oDiv.appendChild(b);
			if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_text_info')) {
				if (c = sandyNextSibling(a.childNodes.item(0),'div','RightColumnPad')) {
					this.blocks = new Array();
					for (var i = 0; i < c.childNodes.length; i++) {
						if (c.childNodes.item(i).tagName && c.childNodes.item(i).tagName.toLowerCase() == 'div') {
							this.blocks.push(this.createBlock(c.childNodes.item(i)));
						}
					} if (c = sandyNextSibling(a.childNodes.item(0),'div','LeftNumbers')) {
						d = c.appendChild(document.createElement("ul"));
						d.className = 'GreenNumbers';
						for (var i = 0; i < this.blocks.length; i++) {
							d.appendChild(this.blocks[i].oLink);
						} a.className = 'TextInBlocks';
						oDiv.appendChild(a);
						a.style.visibility = 'hidden';
						var oLinks = oDiv.childNodes.item(0).getElementsByTagName("a");
						for (var i = 0; i < oLinks.length; i++) {							
							oLinks[i].onclick = function (e) { 
								var target = e ? e.target : window.event.srcElement;
								return sandyTextPage.show(target.hash.substring(1)); 
							}
						}
					}
				}
			} cBack = function () {mySandy.transition(false)};
			mySandy.cBack = function (cBack) {sandyMenu.show(cBack)};
			mySandy.pType = 'text';
		} return cBack;

	},

	createBlock : function (oElem) {

		var a;
		var block = {};
		block.id = oElem.getAttribute("id");
		if (a = sandyNextSibling(oElem.childNodes.item(0),'p','SubTitle')) block.title = a.innerHTML;
		block.oDiv = oElem;
		sandySetProps(block.oDiv.style,"position,absolute,top,0,visibility,hidden,width,362px");
		block.oLink = document.createElement("li");
		a = block.oLink.appendChild(document.createElement("img"));
		sandySetProps(a,"width,23,height,23,src,/img/em.gif");
		a.className = block.id;
		a = block.oLink.appendChild(document.createElement("a"));
		a.innerHTML = block.title;
		a.setAttribute("href","#");
		a.onclick = function (e) { return sandyTextPage.show(block.id); }
		return block;

	},

	show : function (oId) {

		if (!this.inside) {
			this.inside = true;
			this.oDiv.childNodes.item(0).style.visibility = 'hidden';
			this.oDiv.childNodes.item(1).style.visibility = 'visible';
		} for (var i = 0; i < this.blocks.length; i++) {
			if (oId == this.blocks[i].id) {
				this.blocks[i].oDiv.style.visibility = 'visible';
				this.blocks[i].oLink.className = 'active';
			} else {
				this.blocks[i].oDiv.style.visibility = 'hidden';
				this.blocks[i].oLink.className = '';
			}
		} return false;

	}

}

var sandyBg = {

	oDiv : null,
	backgrounds : null,
	fActive : false,
	fTimer : null,
	fCount : 50,
	fIndex : 0,
	fRate : 50,
	cBack : false,

	init : function (oDiv) {
		
		if (this.oDiv = document.getElementById("DeepForestTable")) {
			if (oDiv.getAttribute("backgrounds")) {
				this.backgrounds = oDiv.getAttribute("backgrounds").split("-");
				this.fActive = true;
			} 
		}

	},

	next : function (cBack) {

		this.cBack = cBack;
		if (!this.fActive) {
			this.cBack();
		} else {
			this.fIndex = 0;
			var b = this.backgrounds.shift();
			this.backgrounds.push(b);
			a = this.oDiv.childNodes.item(0).childNodes.item(0).appendChild(document.createElement("TD"));
			a.appendChild(document.createElement("DIV"));
			a = this.oDiv.childNodes.item(0).childNodes.item(0).appendChild(document.createElement("TD"));
			a.className = 'Tree';
			a = a.appendChild(document.createElement("DIV"));
			a = a.appendChild(document.createElement("IMG"));
			sandySetProps(a,"width,640,src,/images/id"+b+"/");
			this.fTimer = setInterval("sandyBg.animate()",this.fRate);
		}

	},

	animate : function () {

		var pos = Math.round(sandyMath.cubicInOut(this.fIndex, 0, 1280, this.fCount)) * -1;
		this.oDiv.parentNode.style.left = pos+'px';
		this.fIndex++;		
		if (this.fIndex == this.fCount) {
			if (this.fTimer) clearInterval(this.fTimer);
			this.fTimer = null;
			var c = this.oDiv.childNodes.item(0).childNodes.item(0);
			c.removeChild(c.childNodes.item(0));
			c.removeChild(c.childNodes.item(0));
			this.oDiv.parentNode.style.left = '0px';
			this.first = false;
			this.cBack();
		}

	}

}

var sandyGallery = {

	oGallery : null,
	oNavigation : null,
	sCount : 0,
	sIndex : 0,
	slides : null,
	fTimer : null,	
	fDirection : 0,
	fIndex : 0,
	fSlideshow : 0,
	sConfig  : {
		slideFps : 40,
		slideFrames : 30,
		slideWidth : 640,
		slideshow : 7000
	}, 

	create : function (oDiv,oWorkspace,oSlides) {

		var a,p,s;
		var sRef = false;
		var oRef = this;
		this.sCount = 0;
		if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_gallery')) {
			if (oSlides) {
				sRef = oSlides.appendChild(document.createElement("UL"));
				sRef.className = 'SmallGallery';
			} this.slides = new Array();
			var slides = a.getElementsByTagName("img");
			for (var i = 0; i < slides.length; i++) {
				this.slides.push(this.createSlide(slides[i],sRef));
				if (this.sCount) {
					this.slides[this.sCount].prev = this.slides[this.sCount-1];
					this.slides[this.sCount-1].next= this.slides[this.sCount];
				} this.sCount++;
			} if (this.sCount) {				
				this.oGallery = document.createElement("div");
				this.oGallery.setAttribute("id","SliderIn");
				this.oGallery = this.oGallery.appendChild(document.createElement("DIV"));
				sandySetProps(this.oGallery.style,"width,1920px,height,460px,position,relative,top,0px,left,-640px,zIndex,5");
				for (i = 0; i < 3; i++) {
					p = this.oGallery.appendChild(document.createElement("img"));
					sandySetProps(p,"style.float,left,src,/img/em.gif,width,640,height,460");
				} sandySetProps(this.oGallery.childNodes.item(1),"src,"+this.slides[this.sIndex].src+",title,"+this.slides[this.sIndex].title);
				this.oGallery.childNodes.item(1).src = this.slides[this.sIndex].src;
				sandyLoader.defer(this.slides[this.sIndex].src);
				oDiv.appendChild(this.oGallery.parentNode);
				if (this.sCount > 1) {
					this.slides[0].prev = this.slides[this.sCount-1];
					this.slides[this.sCount-1].next = this.slides[0];
					if (oSlides) this.slides[0].thumb.className = 'active';
					this.oNavigation = oDiv.appendChild(document.createElement("DIV"));
					this.oNavigation.className = 'TurnOut';
					p = this.oNavigation.appendChild(document.createElement("div"));
					p.className = 'TurnLeft';
					if (oSlides) p.onmousemove = function (e) {sandyProjectPage.check(e);}
					p = p.appendChild(document.createElement("a"));
					p.href = '#';
					p.onclick = function (e) {return oRef.prev(e);}
					p = p.appendChild(document.createElement("img"));
					sandySetProps(p,"src,/img/em.gif,width,35,height,35,title,Предыдущее фото");
					p = this.oNavigation.appendChild(document.createElement("div"));
					p.className = 'TurnRight';					
					if (oSlides) p.onmousemove = function (e) {sandyProjectPage.check(e);}
					p = p.appendChild(document.createElement("a"));
					p.href = '#';
					p.onclick = function (e) {return oRef.next(e);}					
					p = p.appendChild(document.createElement("img"));
					sandySetProps(p,"src,/img/em.gif,width,35,height,35,title,Следующее фото");
					if (oSlides) {
						p = this.oNavigation.appendChild(document.createElement("div"));
						p.className = 'TurnBottom';
						p.onmouseover = function (e) {sandyProjectPage.show();}
						p = p.appendChild(document.createElement("img"));
						sandySetProps(p,"src,/img/em.gif,width,640,height,60");						
					} oDiv.appendChild(this.oNavigation);
					sandySetProps(this.oGallery.childNodes.item(0),"src,"+this.slides[this.sIndex].prev.src+",title,"+this.slides[this.sIndex].prev.title);
					sandySetProps(this.oGallery.childNodes.item(2),"src,"+this.slides[this.sIndex].next.src+",title,"+this.slides[this.sIndex].next.title);
				}
			} 
		}

	},

	createSlide : function (oElem,oPreview) {

		var slide = {next : false,prev : false,thumb: false};
		slide.src = oElem.getAttribute("src");		
		slide.title = oElem.getAttribute("title") ? oElem.getAttribute("title") : "";
		slide.preview = oElem.getAttribute("preview") ? oElem.getAttribute("preview") : false;
		if (slide.preview && oPreview) {
			sandyLoader.defer(slide.preview);
			slide.thumb = oPreview.appendChild(document.createElement("LI"));
			var a = slide.thumb.appendChild(document.createElement("DIV"));
			a = slide.thumb.appendChild(document.createElement("IMG"));
			sandySetProps(a,"src,"+slide.preview+",width,70,title,"+slide.title);
			var oIndex = this.sCount;
			var oRef = this;
			slide.thumb.onclick = function (e) {return oRef.select(oIndex);}
		} return slide;

	},

	next : function (e) {

		this.stop();
		if (this.sCount < 2 || this.fTimer) return false;
		this.sIndex++;
		if (this.sIndex == this.sCount) this.sIndex = 0;
		this.fDirection = -1;
		this.fIndex = 0;
		this.fTimer = setInterval("sandyGallery.animate()",this.sConfig.slideFps);
		return false;

	},

	prev : function (e) {

		this.stop();
		if (this.sCount < 2 || this.fTimer) return false;
		if (this.sIndex) {
			this.sIndex --;
		} else {
			this.sIndex = this.sCount - 1;
		} this.fDirection = 1;
		this.fIndex = 0;
		this.fTimer = setInterval("sandyGallery.animate()",this.sConfig.slideFps);
		return false;

	},

	animate : function () {

		var pos = Math.round(sandyMath.cubicInOut(this.fIndex, 0, this.sConfig.slideWidth, this.sConfig.slideFrames)) * this.fDirection - this.sConfig.slideWidth;
		this.oGallery.style.left = pos+'px';
		this.fIndex++;		
		if (this.fIndex == this.sConfig.slideFrames) {
			if (this.fTimer) clearInterval(this.fTimer);			
			this.fTimer = null;
			sandySetProps(this.oGallery.childNodes.item(1),"src,"+this.slides[this.sIndex].src+",title,"+this.slides[this.sIndex].title);
			sandySetProps(this.oGallery.childNodes.item(2),"src,"+this.slides[this.sIndex].next.src+",title,"+this.slides[this.sIndex].next.title);
			this.oGallery.style.left = '-640px';
			sandySetProps(this.oGallery.childNodes.item(0),"src,"+this.slides[this.sIndex].prev.src+",title,"+this.slides[this.sIndex].prev.title);
			if (this.slides[this.sIndex].thumb) {
				for (var i = 0; i < this.sCount; i++) this.slides[i].thumb.className = (i == this.sIndex ? 'active' : '');
			}
		}		

	},

	play : function () {
		
		if (this.sCount > 1) {
			if (this.fTimer) return false;
			if (!this.fSlideshow) { 
				this.fSlideshow = setInterval("sandyGallery.play()",this.sConfig.slideshow);
			} else {
				this.sIndex++;
				if (this.sIndex == this.sCount) this.sIndex = 0;
				this.fDirection = -1;
				this.fIndex = 0;
				this.fTimer = setInterval("sandyGallery.animate()",this.sConfig.slideFps);
			}			
		}

	},

	stop : function () {

		if (this.fSlideshow) {
			clearInterval(this.fSlideshow);			
			this.fSlideshow = 0;
		}

	},

	select : function (sId) {

		this.stop();
		if (this.sCount < 2 || this.fTimer) return false;
		this.sIndex = sId;
		this.fDirection = -1;
		this.fIndex = 0;
		sandySetProps(this.oGallery.childNodes.item(2),"src,"+this.slides[this.sIndex].src+",title,"+this.slides[this.sIndex].title);
		this.fTimer = setInterval("sandyGallery.animate()",this.sConfig.slideFps);

	}

}

var sandyMenu = {

	oMenu : null,
	oLogo : null,
	oHeadline : null,
	oActive : null,
	oState : false,
	oStage : null,
	fTimer : null,
	cBack : null,
	fRate : 50,
	stages : Array (500,1000,3000,100,100,100),
	frameline : Array (20,20,15,25,15,0),
	heap : {
		start : false
	},

	init : function (oDiv,oWorkspace) {

		var a;
		if (this.oState) return true;
		if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','site_top_menu')) {
			this.oMenu = document.createElement("DIV");
			sandySetProps(this.oMenu,"style.visibility,hidden,id,TopMenuOut")
			this.oMenu.innerHTML = a.innerHTML;
			var oLinks = this.oMenu.getElementsByTagName("a");			
			for (var i = 0; i < oLinks.length; i++) {				
				oLinks[i].href = '#/'+(oLinks[i].pathname.substring(0,1) == '/' ? oLinks[i].pathname.substring(1) : oLinks[i].pathname);
				oLinks[i].onclick = function (e) {return sandyMenu.click(e);};
			} oDiv.parentNode.insertBefore(this.oMenu,oDiv);						
			this.oLogo = document.createElement("DIV");
			a = this.oLogo.appendChild(document.createElement("IMG"));
			sandySetProps(a,"width,229,height,66,src,/img/mammutti.png");
			sandyLoader.defer('/img/mammutti.png');
			sandySetProps(this.oLogo.style,"position,absolute,width,229px,height,66px,zIndex,10,top,200px,left,205px,display,block,visibility,hidden");			
			oDiv.parentNode.insertBefore(this.oLogo,oDiv);
			if (a = sandyNextSibling(oWorkspace.childNodes.item(0),'div','element_headline')) {
				this.oHeadline = document.createElement("DIV");
				this.oHeadline.className = 'Name';
				sandySetProps(this.oHeadline.style,"position,absolute,width,640px,zIndex,10,top,326px,left,0px,display,block,visibility,hidden,textAlign,center");
				this.oHeadline.innerHTML = a.innerHTML;				
				oDiv.parentNode.insertBefore(this.oHeadline,oDiv);
			} this.oStage = 0;
			this.oState = true;
			return true;
		} return false;

	},

	select : function (pId) {

		var cname;
		var oLinks = this.oMenu.getElementsByTagName("a");
		for (var i = 0; i < oLinks.length; i++) {
			cname = oLinks[i].getAttribute("pid") == pId ? 'active' : '';
			if (oLinks[i].parentNode.tagName.toLowerCase() == 'li') {
				oLinks[i].parentNode.className = cname;
			} else {
				oLinks[i].parentNode.parentNode.className = cname;
			}
		} 

	},

	show : function (cBack) {
		
		if (!this.oState) return false;
		this.cBack = cBack;
		setTimeout("sandyMenu.animate()",this.stages[this.oStage]);

	},

	click : function (e) {

		if (!mySandy.Idle) return false;
		var target = e ? e.target : window.event.srcElement;		
		var pUri = target.href.replace(/^.*#/, '')
		if (document.location.hash.length > 1 && document.location.hash.substring(1) == pUri) return false;
		mySandy.navigate(pUri);
		return true;

	},

	animate : function () {

		switch (this.oStage) {
			case 0:
				if (!this.heap.start) {
					this.heap = {start : true, total : this.frameline[this.oStage], current : 0};
					sandySetOpacity(0,this.oLogo);
					this.oLogo.style.visibility = 'visible';						
					this.fTimer = setInterval("sandyMenu.animate()",this.fRate);
				} else {
					this.heap.current++;
					sandySetOpacity(sandyMath.cubicIn(this.heap.current, 0, 100, this.heap.total),this.oLogo);					
					if (this.heap.current == this.heap.total) {
						clearInterval(this.fTimer);
						this.heap.start = false;
						this.oStage++;
						if (!this.oHeadline) this.oStage += 2;
						setTimeout("sandyMenu.animate()",this.stages[this.oStage]);
					} 
				}
			break;
			case 1:
				if (!this.heap.start) {
					this.heap = {start : true, total : this.frameline[this.oStage], current : 0, e_x : 60, e_y : 90, s_x : 60, s_y : 416};
					sandySetOpacity(0,this.oHeadline);
					sandySetProps(this.oHeadline.style,"visibility,visible,left,"+this.heap.s_x+"px,top,"+this.heap.s_y+"px");								
					this.oHeadline.style.visibility = 'visible';
					this.fTimer = setInterval("sandyMenu.animate()",this.fRate);
				} else {					
					this.heap.current++;
					this.heap.c_x = Math.round(this.heap.s_x - sandyMath.cubicOut(this.heap.current,0,this.heap.e_x,this.heap.total));
					this.heap.c_y = Math.round(this.heap.s_y - sandyMath.cubicOut(this.heap.current,0,this.heap.e_y,this.heap.total));
					sandySetProps(this.oHeadline.style,"left,"+this.heap.c_x+"px,top,"+this.heap.c_y+"px");
					sandySetOpacity(sandyMath.cubicIn(this.heap.current, 0, 100, this.heap.total),this.oHeadline);					
					if (this.heap.current == this.heap.total) {
						clearInterval(this.fTimer);
						this.heap.start = false;
						this.oStage++;
						setTimeout("sandyMenu.animate()",this.stages[this.oStage]);
					} 
				}
			break;
			case 2:
				if (!this.heap.start) {
					this.heap = {start : true, total : this.frameline[this.oStage], current : 0};
					this.fTimer = setInterval("sandyMenu.animate()",this.fRate);
				} else {					
					this.heap.current++;
					sandySetOpacity(100 - sandyMath.cubicIn(this.heap.current, 0, 100, this.heap.total),this.oHeadline);					
					if (this.heap.current == this.heap.total) {
						this.oHeadline.parentNode.removeChild(this.oHeadline);
						clearInterval(this.fTimer);
						this.heap.start = false;
						this.oStage++;
						setTimeout("sandyMenu.animate()",this.stages[this.oStage]);
					} 
				}
			break;
			case 3:
				if (!this.heap.start) {
					this.heap = {start : true, total : this.frameline[this.oStage], current : 0, e_x : 205, e_y : 175, s_x : 205, s_y : 200};					
					this.fTimer = setInterval("sandyMenu.animate()",this.fRate);
				} else {					
					this.heap.current++;
					this.heap.c_x = Math.round(this.heap.s_x - sandyMath.cubicOut(this.heap.current,0,this.heap.e_x,this.heap.total));
					this.heap.c_y = Math.round(this.heap.s_y - sandyMath.cubicOut(this.heap.current,0,this.heap.e_y,this.heap.total));
					sandySetProps(this.oLogo.style,"left,"+this.heap.c_x+"px,top,"+this.heap.c_y+"px");					
					if (this.heap.current == this.heap.total) {
						clearInterval(this.fTimer);
						this.heap.start = false;
						this.oStage++;
						setTimeout("sandyMenu.animate()",this.stages[this.oStage]);
					} 
				}
			break;
			case 4:
				if (!this.heap.start) {
					this.heap = {start : true, total : this.frameline[this.oStage], current : 0};
					sandySetOpacity(0,this.oMenu.childNodes.item(0));
					this.oMenu.style.visibility = 'visible';						
					this.fTimer = setInterval("sandyMenu.animate()",this.fRate);
				} else {					
					this.heap.current++;
					sandySetOpacity(sandyMath.linear(this.heap.current, 0, 100, this.heap.total),this.oMenu.childNodes.item(0));					
					if (this.heap.current == this.heap.total) {
						clearInterval(this.fTimer);
						this.heap.start = false;
						this.oStage++;
						setTimeout("sandyMenu.animate()",this.stages[this.oStage]);
					} 
				}
			break;
			case 5:
				if (this.cBack) {
					setTimeout(this.cBack,this.stages[this.oStage]);
				}
			break;
			default:
				if (this.fTimer) {
					clearInterval(this.fTimer);
				} 
		}		

	}

}

var sandyMath = {

	linear : function (t, b, c, d) {
	
		return c*t/d + b;

	},

	cubicIn : function (t, b, c, d) {

		return c*(t/=d)*t*t + b;

	},

	cubicOut : function (t, b, c, d) {
	
		return c*((t=t/d-1)*t*t + 1) + b;

	},

	cubicInOut : function (t, b, c, d) {
		
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;

	}

}

var sandyLoader = {

	oElem : null,
	fCount : 12,
	fIndex : 0,
	fRate : 100,
	fTimer : null,
	pictures : null,
	lCount : 0,
	cBack : false,

	init : function () {		
		
		this.oElem = document.body.appendChild(document.createElement("DIV"));
		sandySetProps(this.oElem.style,"display,none,position,absolute,top,50%,marginTop,-25px,marginLeft,-25px,left,50%,zIndex,100,width,50px,height,50px");
		for (var i = 0; i < this.fCount; i++) {
			var oImg = document.createElement("img");
			sandySetProps(oImg.style,"width,50px,height,50px,padding,0px,margin,0px,display,none");
			oImg.src = '/engine/loader/frame'+(i+1)+'.png';
			this.oElem.appendChild(oImg);
		} this.fTimer = null;

	},

	animate : function () {
		
		this.oElem.childNodes.item(this.fIndex).style.display = 'none';
		this.fIndex++;
		if (this.fIndex == this.fCount) this.fIndex = 0;
		this.oElem.childNodes.item(this.fIndex).style.display = 'inline';

	},

	defer : function (pUrl) {

		this.pictures.push(pUrl);

	},

	preload : function (cBack) {

		var a;
		this.cBack = cBack;
		if (this.pictures.length == 0) {
			this.stop();
			mySandy.cBack(this.cBack);
		} else {
			this.lCount = this.pictures.length;			
			this.items = new Array();
			for (var i = 0; i < this.pictures.length; i++) {
				this.items.push(new Image());
				this.items[i].onload = function () { sandyLoader.loaded(); }
				this.items[i].src = this.pictures[i];
			}
		}

	},
	
	loaded : function () {

		this.lCount--;
		if (this.lCount <= 0 && this.cBack) {			
			this.stop();
			mySandy.cBack(this.cBack);
		}

	},

	start : function () {

		if (this.fIndex) {
			this.oElem.childNodes.item(this.fIndex).style.display = 'none';
		} this.fIndex = 0;
		this.pictures = new Array();
		this.oElem.childNodes.item(this.fIndex).style.display = 'inline';
		this.oElem.style.display = 'block';
		this.fTimer = setInterval("sandyLoader.animate()",this.fRate);

	},

	stop : function () {

		if (this.fTimer) clearInterval(this.fTimer);
		this.fTimer = null;
		this.oElem.style.display = 'none';

	}

}

var sandyXml = {

	fetchString : function (u) {
		var r = this.createXml(u);
		if (r.error) return false;
		return r.perform();
	},

	getString : function (u,f) {
		var r = this.createXml(u,0,f);
		if (r.error) return false;
		return r.perform();
	},

	sendString : function (u,d) {
		var r = this.createXml(u,0,false,d);
		if (r.error) return false;
		r.perform();
		return true;
	},

	postString : function (u,d,f) {
		var r = this.createXml(u,0,f,d);
		if (r.error) return false;
		r.perform();
		return true;
	},

	fetchXml : function (u) {
		var r = this.createXml(u,1);
		if (r.error) return false;
		return r.perform();
	},
	
	getXml : function (u,f) {
		var r = this.createXml(u,1,f);
		if (r.error) return false;	
		r.perform();
		return true;
	},

	createXml : function () {
		var req = {
			error: false,
			url: arguments.length ? arguments[0] : false,
			type: arguments.length > 1 ? arguments[1] : 0,
			async: arguments.length > 2 ? true : false,
			callback: arguments.length > 2 ? arguments[2] : false,
			method: arguments.length > 3 ? "POST" : "GET",
			data: arguments.length > 3 ? arguments[3] : null
		}; try {
			req.xml = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			try {
				req.xml = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					req.xml = new XMLHttpRequest();
				} catch (e) {
					req.error = true;
					return false;
				}				
			}
		} req.perform = function () {
			req.xml.open(this.method,this.url,this.async);
			if (this.method == "POST") {
				req.xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				req.xml.setRequestHeader("Content-length", this.data.length);
				req.xml.setRequestHeader("Connection", "close");
			} if (this.async && this.callback) {
				req.xml.onreadystatechange = function () {
					if (req.xml.readyState != 4) {
						return;
					} clearTimeout(req.timeout);
					if (req.xml.status != 200) {
						if (req.timeout) {
							req.callback(new Error(101,'XML_BAD_REQUEST'),false);
						} else {
							req.callback(new Error(102,'XML_SERVER_TIMEOUT'),false);
						}
					} else {						
						req.callback(req.type ? req.xml.responseXML : req.xml.responseText,true);
					}
				}; req.timeout = setTimeout (
					function () {
						req.timeout = false;
						req.xml.abort();
					},
				15000);
				req.xml.send(this.data);
			} else {
				req.xml.send(this.data);
				if (req.xml.status != 200) {
					throw new Error(101,'XML_BAD_REQUEST');
				} return this.type ? req.xml.responseXML : req.xml.responseText;
			}
		}; return req;
			
	} 

}

function sandySetProps(oElem,oItems) {

	var oHash = oItems.split(",");
	for (var i = 0; i < oHash.length; i+=2) {
		eval('oElem.'+oHash[i]+' = "'+oHash[i+1]+'"');
	}

}

function sandySetOpacity(opacity,oElem) {

	if (opacity == 100) {
		if (o.style.removeAttribute) o.style.removeAttribute('filter');
	} else {
		oElem.style.filter = "alpha(opacity=" + opacity + ")";
	} oElem.style.opacity = (opacity / 100);

}

function sandyBlockEvent (e) {
    
	e = !e ? window.event : e;
    e.cancelBubble = true;
    return false;

}

function sandyNextSibling (oDiv,oTag,oClass) {

	var p = oDiv;
	do	{
		if (p.tagName && p.tagName.toLowerCase() == oTag) {
			if (oClass) {
				if (p.className == oClass) return p;
			} else {
				return p;
			}
		}
	} while (p = p.nextSibling);
	return false;

}

window.onload = function () {
	if (o = document.getElementById("sandyCanvas")) {
		document.oncontextmenu = sandyBlockEvent;
		document.ondrag = sandyBlockEvent;
		document.onselectstart = sandyBlockEvent;
		mySandy = new sandy(o);
		mySandy.born();
	}
}