var sandyPage = {

	oPane : null,
	oBack : null,
	oLang : null,
	oMenu : null,
	oFooter : null,
	oCanvas : null,
	oNews : null,
	fBuzy : false,	
	cHeight : 0,
	oPage : null,
	pState : 'main',
	cTop : 0,
	started : false,
	size : {w : 980,h : 700},

	init : function (oDiv) {

		oDiv.style.display = 'none';
		var pUrl = new sandyPageLink(document.location.pathname);
		if (pUrl.count() > 1) {
			document.location.replace(pUrl.rel());
			return false;
		} sandyLoader.init();
		sandyLoader.start();
		sandyLoader.defer('/img/em.gif');
		sandyEvents.add('onresize','page',function() {sandyPage.resize()});
		sandyEvents.add('onclick','page',function(e) {sandyPage.getLink(e)});
		this.oPane = oDiv.parentNode.insertBefore(document.createElement('div'),oDiv);
		sandyUtils.props(this.oPane.style,'display,block,position,absolute,overflow,hidden,height,100%,width,100%,zIndex,10');
		this.oCanvas = this.oPane.appendChild(document.createElement('div'));
		this.oCanvas.className = 'siteCanvas';
		sandyPage.resize();
		this.createPage(document.getElementById("mainLogo"));
		this.createBg(oDiv.getAttribute('rel'));		
		this.createLang(document.getElementById("languageBox"),document.getElementById("navigationPane"));
		this.createMenu(document.getElementById("siteMenu"));
		this.createFooter(document.getElementById("siteFooter"));
		if (document.getElementById("siteNews")) this.createNews(document.getElementById("siteNews"));
		this.oMenu.setState(this.pState);		
		if (pUrl.hashed()) {
			this.navigate(pUrl.href());			
		} else {
			sandyScript.reset();
			this.live();
			if (this.oNews) sandyScript.add(function () {sandyPage.oNews.show();},50);		
			sandyScript.add(function () {sandyPage.oLang.show();},200);
			sandyLoader.preload(function () {sandyScript.run()});
		}

	},

	live : function () {

		if (!this.started) {
			this.started = true;
			this.oFooter.position();
			sandyScript.add(function () {sandyPage.oBack.show();},500);
			sandyScript.add(function () {sandyPage.showMenu();},500);			
		}

	},

	getLink : function (e) {

		var oElem = !e.srcElement ? e.target : e.srcElement;
		if (!oElem.tagName) return;
		if (oElem.tagName.toLowerCase() == 'img' && oElem.parentNode && oElem.parentNode.tagName.toLowerCase() == 'a') {
			oElem = oElem.parentNode;
		} if (oElem.tagName.toLowerCase() != 'a') return;
		if (oElem.getAttribute("type") == 'menuCatalog') {
			this.oMenu.expand(oElem.getAttribute("pid"));
			sandyEvents.cancel('onclick');
		} else if (oElem.getAttribute("type") == 'menuItem') {
			sandyEvents.cancel('onclick');			
			this.oMenu.collapse(oElem.getAttribute("pid"));
			sandyScript.add(function (oId) {sandyPage.navigate(oId);},10,oElem.getAttribute("rel"));
			sandyScript.run();
		} else if (oElem.getAttribute("type") == 'mainLink') {			
			sandyEvents.cancel('onclick');
			if (this.pState != 'inside') return;			
			sandyPage.goMain(oElem.getAttribute('rel'));
		} else if (oElem.getAttribute("rel")) {
			sandyEvents.cancel('onclick');
			if (oElem.getAttribute("pid")) this.oMenu.collapse(oElem.getAttribute("pid"));
			sandyScript.add(function (oId) {sandyPage.navigate(oId);},10,oElem.getAttribute("rel"));
			sandyScript.run();
		}

	},

	navigate : function (pUrl) {

		this.fBuzy = true;
		pUrl = new sandyPageLink(pUrl);
		var cBack = function (msg,state) {
			sandyPage.preload(msg,state);
		}; 	sandyXml.getString(pUrl.href()+'?ajax=1',cBack);
		document.location.replace(pUrl.rel());

	},

	preload : function (tData,oState) {

		if (oState) {
			if (!this.oPage.loadPage(tData)) return this.showError("Unable to process template");
			this.pState = 'inside';
			this.oMenu.setState(this.pState);
			sandyScript.reset();			
			sandyScript.add(function (oId) {sandyPage.oMenu.select(oId);},10,sandyPage.oPage.pageId);
			this.live();
			sandyScript.add(function () {sandyPage.oPage.reveal();},10);
			sandyScript.add(function () {sandyPage.oLang.show();},200);
			sandyLoader.preload(function () {sandyScript.run()});
		} else {
			this.showError('An error occured while loading data from server ');
		}

	},

	showError : function (msg) {

		alert(msg);
		sandyLoader.stop();
		return false;

	},

	goMain : function (pUrl) {

		sandyScript.reset();
		document.location.hash = '';
		var scroller = function () {
			var oMove = document.body.clientHeight;
			var anim = function (a) {
				sandyPage.rollCanvas(Math.round(sandyUtils.fCubicInOut(a,0,oMove,20)),false,false);
			}; var cBack = function () {
				sandyPage.oPage.hide();
				sandyPage.pState = 'main';
				sandyPage.reserve(0,2);
				sandyPage.resize();
				sandyPage.oMenu.setState("main");
				sandyPage.oFooter.position();				
				sandyScript.run();
			}; var a = sandyUtils.animator(20,50,anim,cBack);
			a.run();
		}; sandyScript.add(scroller,10);
		sandyScript.add(function () {sandyPage.showMenu();},10); 
		if (sandyPage.oNews) {
			sandyScript.add(function () {sandyPage.oNews.show();},50); 
		} sandyScript.add(function () {sandyPage.oLang.show();},200);
		sandyPage.oLang.hide();
		sandyPage.oBack.next();
		sandyScript.run();
		

	},

	reserve : function (oHeight,oMode) {

		if (oMode == 2) {
			this.cHeight = oHeight;
		} else if (oMode == 1) {
			if (this.cHeight < oHeight) this.cHeight = oHeight;
		} else {
			this.cHeight += oHeight;
		} 

	},

	rollCanvas : function (oMove,oDir,isPerm) {

		if (oDir) {
			var a = this.cTop - oMove;
			this.oFooter.resize(oMove);
			if (isPerm) {
				this.cTop = a;
				this.cHeight += oMove;
			} 
		} else {
			var a = this.cTop + oMove;
			if (isPerm) this.cTop = a;
		} this.oCanvas.style.top = a+'px';
		if (this.oNews) this.oNews.adjust(oMove,isPerm);

	},

	showMenu : function () {

		if (this.pState == 'inside') {
			this.oMenu.show();
			var oTab = this.oCanvas;
			var oMove = document.body.clientHeight;
			var cBack = function () {
				sandyScript.run();
			}; var anim = function (a) {
				sandyPage.cTop = Math.round(sandyUtils.fCubicInOut(a,0,oMove,20) * -1 +oMove);
				oTab.style.top = sandyPage.cTop+'px';
			}; var a = sandyUtils.animator(20,50,anim,cBack);
			a.run();
		} else {
			this.oMenu.show();
			var oTab = this.oCanvas;
			var oMove = this.cHeight;
			var oSource = document.body.clientHeight;
			if (oSource < this.size.h) oSource = this.size.h;
			var cBack = function () {
				sandyScript.run();
			}; var anim = function (a) {
				sandyPage.cTop = Math.round(sandyUtils.fCubicInOut(a,0,oMove,20) * -1 +oSource);
				oTab.style.top = sandyPage.cTop+'px';
			}; var a = sandyUtils.animator(20,50,anim,cBack);
			a.run();
		}

	},

	resize : function (oSize) {

		var w = document.body.clientWidth;
		var h = document.body.clientHeight;		
		var p_w = w > this.size.w ? '100%' : this.size.w+'px';
		var p_h = h > this.size.h ? '100%' : this.size.h+'px';		
		if (this.pState == 'inside') {
			this.oCanvas.style.top = 0;
			if (h > this.cHeight) {
				sandyUtils.props(this.oPane.style,'width,'+p_w+',height,100%');
				this.oFooter.oElem.style.top = (h - 30)+'px';
			} else {
				sandyUtils.props(this.oPane.style,'width,'+p_w+',height,'+this.cHeight+'px');			
				this.oFooter.oElem.style.top = (this.cHeight - 30)+'px';
			}
		} else {
			sandyUtils.props(this.oPane.style,'width,'+p_w+',height,'+p_h);
			if (this.size.h > h) {
				this.cTop = this.size.h - this.cHeight;
			} else {
				this.cTop = h - this.cHeight;				
			} this.oCanvas.style.top = this.cTop+'px';
		}

	},

	createPage : function (oDiv) {

		if (this.oPage) return false;
		this.oPage = {

			pageId : 0,

			create : function (oDiv) {

				this.oLogo = oDiv;
				this.oLogo.onclick = function (e) {
					if (sandyPage.pState != 'inside' || sandyPage.fBuzy) return sandyUtils.block(e);					
					sandyPage.goMain(this.getAttribute('rel'));
					return sandyUtils.block(e);
				}; this.oElem = document.createElement("div");
				sandyUtils.props(this.oElem.style,'display,none,overflow,hidden,position,absolute,padding,130px 0px 0px 300px,width,660px,zIndex,10');

			},

			hide : function () {

				this.pageId = 0;
				this.oLogo.firstChild.style.cursor = 'default';
				this.oElem.style.display = 'none';

			},

			loadPage : function (oData) {

				var a;
				var cache = document.createElement("div");
				cache.innerHTML = oData;
				if ((a = sandyUtils.getElem(cache.firstChild,'div','sitePage'))) {
					if (!(this.pageId = a.getAttribute("pid"))) return false;
				} else {
					return false;
				} this.oElem.innerHTML = a.innerHTML;
				this.oElem.style.visibility = 'hidden';
				this.oElem.style.display = 'block';
				this.oCanvas = this.oElem.firstChild;
				this.oLogo.firstChild.style.cursor = 'pointer';
				return true;

			},

			reveal : function () {

				this.oElem.style.visibility = 'visible';				
				var oTab = this.oCanvas;
				sandyPage.reserve(oTab.clientHeight + 170,1);
				sandyPage.oFooter.position();
				sandyPage.resize();
				var cBack = function () {
					sandyScript.run();
				}; var anim = function (a) {
					oTab.style.left = Math.round(sandyUtils.fCubicIn(a,0,660,20) * -1 + 660)+'px';
				}; var a = sandyUtils.animator(20,50,anim,cBack);
				a.run();

			}

		}; this.oPage.create(oDiv);
		this.oCanvas.appendChild(this.oPage.oElem);

	},

	createNews : function (oDiv) {

		if (this.oNews) return false;
		this.oNews = {

			cHeight : 0,
			cTop : 0,
			shown : false,

			create : function (oDiv) {

				this.oElem = oDiv.parentNode.removeChild(oDiv);
				this.oElem.className = 'newsContainer';
				var a = sandyUtils.unshiftChild(this.oElem,'div');
				a.className = 'newsBack';
				this.elem = sandyPage.oCanvas.appendChild(this.oElem);

			},

			adjust : function (oMove,isPerm) {

				if (this.shown) {
					var a = this.cTop + oMove;
					if (isPerm) this.cTop = a;
					if (a >= 0) {
						this.hide();
					} else {
						this.oElem.style.top = a+'px';
					}
				}

			},

			show : function () {

				var a;
				if (this.shown) return sandyScript.run();				
				var oTab = this.elem;
				oTab.style.top = this.cTop;
				oTab.style.display = 'block';
				if (a = document.getElementById('news1')) {
					if (a.clientHeight > this.cHeight) this.cHeight = a.clientHeight;
				} if (a = document.getElementById('news2')) {
					if (a.clientHeight > this.cHeight) this.cHeight = a.clientHeight;
				} this.cHeight += 40;
				this.shown = true;
				oTab.style.height = this.cHeight+'px';
				oTab.firstChild.style.height = this.cHeight+'px';
				var oMove = this.cHeight;
				var cBack = function () {
					sandyScript.run();
				}; var anim = function (a) {
					sandyPage.oNews.cTop = Math.round(sandyUtils.fCubicInOut(a,0,oMove,20) * -1);
					oTab.style.top = sandyPage.oNews.cTop+'px';
				}; a = sandyUtils.animator(20,50,anim,cBack);
				a.run();

			},

			hide : function () {

				this.shown = false;
				this.cTop = 0;
				this.cHeight = 0;
				this.elem.style.display = 'none';				

			}

		}; this.oNews.create(oDiv);

	},

	createFooter : function (oDiv) {

		if (this.oFooter) return false;
		this.oFooter = {

			create : function (oDiv) {

				this.oElem = oDiv.parentNode.removeChild(oDiv);
				this.oElem.className = 'copyright';

			},

			position : function () {

				sandyPage.reserve(20);
				this.oElem.style.top = (sandyPage.cHeight - 30)+'px';

			},

			resize : function (oMove) {

				this.oElem.style.top = (sandyPage.cHeight + oMove-30)+'px';

			}

		}; this.oFooter.create(oDiv);
		this.oCanvas.appendChild(this.oFooter.oElem);

	},

	createMenu : function (oDiv) {

		if (this.oMenu) return false;
		this.oMenu = {

			sCount : 0,
			mState : "none",
			items : null,
			vFrames : 40,
			eHeight : 0,
			mHeight : 0,
			shown : false,
			cTop : 0,
			curve : false,

			create : function (oDiv) {

				var a;
				this.oElem = document.createElement("div");
				this.oElem.style.display = 'none';
				this.items = new Array();
				this.structure = new Array();
				var oItems = oDiv.getElementsByTagName("div");
				while (oItems.length) {
					a = oItems[0].parentNode.removeChild(oItems[0]);
					if (a.getAttribute("rel") == 'menuItem') {
						this.sCount++;
						this.items[this.sCount] = this.createElem(a);
					}
				} this.mState = false;				

			},
			
			show : function () {

				this.oElem.style.display = 'block';

			},

			findParent : function (oId) {

				if (!this.structure[oId]) return false;
				var a = this.structure[oId];
				while (a.parent) {
					a = this.structure[a.parent];
				} return a.id;

			},

			calcBackCurve : function (oId) {

				var ch = 0;
				var orig = ch;
				this.curve[oId][0] = new Array();
				for (var i = 1; i <= this.sCount; i++) {
					if (i == oId) {						
						ch = this.items[i].elem.clientHeight;
					} else {
						ch = this.items[i].elem.clientHeight - this.items[i].menu.offsetHeight - 10;
					} for (var b = 1; b <= 10; b++) {
						this.curve[oId][0].push(Math.round(sandyUtils.fLinear(b,0,ch,10)+orig));
					} orig += ch;
				}

			},

			calcItemCurve : function (oSrc,oElem) {
				
				var cTop = 30;
				var oAdd = cTop;
				var oMove = 180 * oElem - 125;
				var crv = new Array();
				for (var i = 1; i <= (oElem - 1) * 10; i++) {
					crv.push(Math.round(sandyUtils.fCubicOut(i,0,oMove - 55,(oElem-1)*10) * -1 + oMove));
				} this.curve[oSrc][oElem] = new Array();
				for (var i = 0; i < this.curve[oSrc][0].length; i++) {
					if (crv.length > i) {
						oAdd = cTop+this.curve[oSrc][0][i];
						this.curve[oSrc][oElem].push(oAdd+'|'+crv[i]);
					} else {
						this.curve[oSrc][oElem].push(oAdd+'|'+55);
					}
				}

			},

			createCurve : function () {

				var cHeight = 0;
				this.curve = new Array();
				for (var i = 1; i <= this.sCount; i++) {
					this.curve[i] = new Array();					
					this.calcBackCurve(i);
					for (var b = 1; b <= this.sCount; b++) this.calcItemCurve(i,b);
				} sandyScript.reset();

			},

			collapse : function (oId) {

				if (sandyPage.pState == 'inside') return false;
				if (!this.curve) this.createCurve();
				if ((oId = this.findParent(oId)) == false) return false;
				var elems = new Array();
				for (var i = 1; i <= this.sCount; i++) {
					if (i == oId) continue;
					elems[i] = {};
					elems[i].elem = this.items[i].menu;
					elems[i].size = this.items[i].menu.clientHeight
					this.items[i].menu.style.overflow = 'hidden';
				} var collapser = function () {				
					var anim = function (a) {
						for (var b in elems) {
							elems[b].elem.style.height = Math.round(sandyUtils.fCubicInOut(a,0,elems[b].size,20) * -1 +elems[b].size)+'px';
						}
					}; var cBack = function () {
						for (var b in elems) {
							elems[b].elem.style.display = 'none';
							elems[b].elem.style.overflow = 'auto';
						} sandyScript.run();
					}; var a = sandyUtils.animator(20,50,anim,cBack);
					a.run();
				}; sandyScript.add(collapser,10); 
				sandyScript.add(function (oId) {sandyPage.oMenu.rollMenu(oId);},10,oId);	
				var scroller = function () {
					var anim = function (a) {
						var b = Math.round(sandyUtils.fCubicIn(a,0,sandyPage.cTop,20));
						var c = Math.round(sandyUtils.fCubicIn(a,0,190,20));
						sandyPage.oMenu.oElem.style.top = c+'px';
						sandyPage.rollCanvas(b,true,false);
					}; var cBack = function () {
						sandyPage.rollCanvas(sandyPage.cTop,true,true);
						sandyPage.oMenu.oElem.style.top = '190px';
						sandyScript.run();
					}; var a = sandyUtils.animator(20,25,anim,cBack);
					a.run();
				}; sandyScript.add(scroller,10); 
				sandyPage.oLang.hide();

			},

			rollMenu : function (oId) {

				var elems = this.curve[oId];
				var frms = elems[0].length;
				var oMove = elems[0][frms-1];
				var oItems = this.items;
				var anim = function (a) {
					sandyPage.rollCanvas(elems[0][a],true,false);
					for (var i = 1; i < elems.length; i++) {
						var c = elems[i][a].split('|');
						sandyUtils.props(oItems[i].elem.style,'top,'+c[0]+'px,left,'+c[1]+'px');
					};
				}; var cBack = function () {
					sandyPage.rollCanvas(oMove,true,true);
					sandyScript.run();
				}; var a = sandyUtils.animator(frms,40,anim,cBack);
				a.run();

			},

			expand : function (oId) {
				
				var a;
				if (this.mState != 'inside' || !(a = this.structure[oId]) || a.parent) return false;
				if (a.selected) return false;
				var srcE,dstE,srcH,dstH;
				for (var i = 1; i <= this.sCount; i++) {
					if (this.items[i].id == a.id) {
						this.items[i].selected = true;
						dstE = this.items[i].menu;
						dstE.style.display = 'block';
						dstH = dstE.offsetHeight;
						dstE.style.overflow = 'hidden';
						dstE.style.height = '0px';
					} else if (this.items[i].selected) {
						this.items[i].selected = false;
						srcE = this.items[i].menu;
						srcH = srcE.offsetHeight;
						srcE.style.overflow = 'hidden';
					}
				} if (dstE) {
					sandyPage.fBuzy = true;
					var anim = function (a) {
						sandyUtils.props(dstE.style,'height,'+Math.round(sandyUtils.fLinear(a,0,dstH,12))+'px');
						if (srcE) sandyUtils.props(srcE.style,'height,'+Math.round(sandyUtils.fLinear(a,0,srcH,12) * -1 + srcH)+'px');
					}; var cBack = function () {						
						dstE.style.overflow = 'auto';												
						dstE.style.height = 'auto';
						if (srcE) {
							srcE.style.display = 'none';
							srcE.style.overflow = 'auto';
							srcE.style.height = 'auto';
						} sandyPage.fBuzy = false;
					}; var a = sandyUtils.animator(12,30,anim,cBack);
					a.run();
				}

			},

			setState : function (oState) {

				if (this.mState == oState) return false;
				this.mState = oState;
				switch (this.mState) {
					case "main":
						var mH = 0;
						this.eHeight = 0;
						this.cTop = 30;
						this.oElem.style.top = 0;
						this.clear();
						this.oElem.className = 'menuContainer';
						this.oElem.style.width = '100%';
						this.oElem.style.display = 'block';
						for (var i = 1; i <= this.sCount; i++) {
							this.items[i].selected = false;
							sandyUtils.props(this.items[i].elem.style,'position,absolute,width,180px,top,'+this.cTop+'px,left,'+(180 * i - 125)+'px');
							this.items[i].menu.style.display = 'block';
							if (!sandyPage.started) mH = this.items[i].menu.offsetHeight > mH ? this.items[i].menu.offsetHeight : mH;
							this.items[i].menu.style.height = 'auto';
							if (this.items[i].elem.clientHeight > this.eHeight) this.eHeight = this.items[i].elem.clientHeight;
						} this.eHeight += 40;
						sandyPage.reserve(this.eHeight);
						if (!sandyPage.started) this.mHeight = this.sCount * 36 + mH + 250;
					break;
					case "inside":
						this.cTop = 30;
						this.oElem.style.top = '190px';						
						for (var i = 1; i <= this.sCount; i++) {
							sandyUtils.props(this.items[i].elem.style,'position,relative,top,'+this.cTop+'px,left,55px');
							sandyUtils.props(this.items[i].menu.style,'height,auto,width,193px');
							if (!sandyPage.started) sandyUtils.props(this.items[i].menu.style,'display,none');
						} sandyPage.reserve(document.body.clientHeight,2);
						this.oElem.style.width = '250px';
					break;
				}

			},

			createElem : function (oDiv) {

				var oRef = {};
				oRef.id = this.sCount;
				oRef.elem = oDiv;
				oRef.parent = 0;
				oRef.pid = oDiv.firstChild.firstChild.getAttribute("pid");				
				oRef.elem.className = 'menuBox';
				this.structure[oRef.pid] = oRef;
				oRef.sCount = 0;
				oRef.selected = false;
				oRef.childs = new Array();
				oRef.menu = oDiv.firstChild.nextSibling;
				oRef.menu.style.display = 'block';
				var oChilds = oRef.menu.getElementsByTagName('a');
				for (var i = 0; i < oChilds.length; i++) {										
					if (oChilds[i].getAttribute("type") != 'menuItem') continue;
					oRef.sCount++;
					oRef.childs[oRef.sCount] = this.createChild(oChilds[i],oRef.sCount,oRef.pid);
				} if (oRef.sCount) oRef.menu = oChilds[i-1].parentNode;
				this.oElem.appendChild(oRef.elem);
				return oRef;

			},

			createChild : function (oLink,oId,oParent) {

				var a,b;
				var oRef = {};
				oRef.id = oId;
				oRef.parent = oParent;
				oRef.selected = false;
				oRef.elem = oLink;				
				oRef.elem.className = '';
				oRef.pid = oLink.getAttribute("pid");
				this.structure[oRef.pid] = oRef;
				oRef.sCount = 0;
				oRef.childs = new Array();
				oRef.menu = false;
				if ((a = oLink.nextSibling) && (a.tagName.toLowerCase() == 'div') && (a.className == 'podMenu')) {
					var oChilds = a.getElementsByTagName('a');
					for (var i = 0; i < oChilds.length; i++) {
						oRef.sCount++;
						oRef.childs[oRef.sCount] = this.createNode(oChilds[i],oRef.sCount,oRef.pid);
					} if (oRef.sCount) {
						oRef.menu = oChilds[i-1].parentNode;
						oRef.menu.style.display = 'none';
						oRef.menu.style.overflow = 'hidden';
						oRef.menu.style.width = '180px';
					}
				} return oRef;

			},

			createNode : function (oLink,oId,oParent) {

				var oRef = {};
				oRef.id = oId;
				oRef.parent = oParent;
				oRef.selected = false;
				oRef.elem = oLink;
				oRef.pid = oLink.getAttribute("pid");
				this.structure[oRef.pid] = oRef;
				return oRef;

			},

			clear : function () {

				var mState;
				for (var a = 1; a <= this.sCount; a++) {
					this.items[a].selected = false;
					this.items[a].menu.style.display = 'none';
					for (var b = 1; b <= this.items[a].sCount; b++) {
						this.items[a].childs[b].elem.className = '';
						if (this.items[a].childs[b].menu) this.items[a].childs[b].menu.style.display = 'none';
						for (c = 1; c <= this.items[a].childs[b].sCount; c++) {
							this.items[a].childs[b].childs[c].elem.className = '';
						} 
					} 
				}

			},

			select : function (oId) {

				var a,b;								
				this.clear();
				sandyPage.reserve(this.mHeight,2);
				if (!this.structure[oId] || !(a = this.structure[oId].parent)) return sandyScript.run();				
				this.structure[oId].elem.className = 'active';
				if (b = this.structure[a].parent) {
					this.structure[b].selected = true;
					this.structure[b].menu.style.display = 'block';
					this.structure[a].elem.className = 'active';
					this.structure[a].menu.style.display = 'block';
				} else {
					this.structure[a].selected = true;
					this.structure[a].menu.style.display = 'block';
					if (this.structure[oId].menu) this.structure[oId].menu.style.display = 'block';
				} sandyScript.run();

			}

		}; this.oMenu.create(oDiv);
		this.oCanvas.appendChild(this.oMenu.oElem);

	},

	createLang : function (oDiv,oNavy) {

		if (this.oLang) return false;
		this.oLang = {

			attached : false,
			oSearch : false,
			oLang : false,
			sForm : false,
			oText : false,

			create : function (oDiv,oNavy) {

				var a;
				this.oElem = oDiv.parentNode.removeChild(oDiv);
				this.oNavy = oNavy.parentNode.removeChild(oNavy);
				if (a = document.getElementById("searchPane")) {
					this.oSearch = a.parentNode.removeChild(a);
					this.sForm = this.oSearch.firstChild;
					a = this.oSearch.getElementsByTagName('td');
					if (a.length) {
						this.oText = a[0].firstChild;
						this.oLang = a[0].parentNode.appendChild(document.createElement('td'));
						this.sForm.onsubmit = function (e) {
							if (sandyPage.pState != 'inside' || sandyPage.fBuzy) return sandyUtils.block(e);
							sandyPage.oLang.search();
							return sandyUtils.block(e);
						}
					} 
				}

			},

			search : function () {

				if (this.oText.value.length) {
					var pUrl = this.sForm.getAttribute("rel");
					pUrl += '?ajax=1';
					var data = 'query='+encodeURI(this.oText.value);
					sandyPage.fBuzy = true;
					var cBack = function (msg,state) {
						sandyPage.preload(msg,state);
					}; sandyXml.postString(pUrl,data,cBack);
				}

			},

			show : function () {
				
				if (this.attached) return sandyScript.run();
				this.attached = true;
				if (sandyPage.pState == 'inside') {
					this.oNavy = sandyPage.oCanvas.appendChild(this.oNavy);					
					if (this.oLang) {
						this.oElem = this.oLang.appendChild(this.oElem);
						this.oElem.className = 'languageBoxInside';
					} else {
						this.oElem = sandyPage.oCanvas.appendChild(this.oElem);
						this.oElem.className = 'languageSwitchInside';
					} if (this.oSearch) {
						this.oSearch = sandyPage.oCanvas.appendChild(this.oSearch);
					} 
				} else {
					this.oElem.className = 'languageBox';
					this.oElem.style.visibility = 'visible';				
					this.oElem = sandyPage.oCanvas.appendChild(this.oElem);					
				} sandyScript.run();

			},

			hide : function () {

				if (this.attached) {
					this.attached = false;
					this.oElem = this.oElem.parentNode.removeChild(this.oElem);
					if (this.oNavy.parentNode) this.oNavy = this.oNavy.parentNode.removeChild(this.oNavy);
					if (this.oSearch && this.oSearch.parentNode) this.oSearch.parentNode.removeChild(this.oSearch);					
				}

			}

		}; this.oLang.create(oDiv,oNavy);

	},

	createBg : function (oImg) {

		if (this.oBack) return false;
		this.oBack = {

			current : 0,
			shown : false,
			display : false,
			size : {w : 1024,h : 920,r : 0.9},

			create : function (oDiv,oImg) {

				this.display = true;
				var a = navigator.appVersion.split("MSIE");
				var b = parseFloat(a[1])
				this.needFix = document.body.filters ? true : false;
				var a = oImg.split('|');
				this.pictures = new Array();
				for (var i = 0; i < a.length; i++) {
					sandyLoader.defer(a[i]);
					this.pictures.push(a[i]);
				} this.oDiv = oDiv.appendChild(document.createElement("div"));
				this.oDiv.className = 'BackContainer';
				this.oDiv = this.oDiv.appendChild(document.createElement("div"));
				this.oDiv.className = 'myFotoContainer';
				this.oDiv = this.oDiv.appendChild(document.createElement("div"));
				this.oDiv.className = 'myFotoCanvas';
				this.oDiv = this.oDiv.appendChild(document.createElement("div"));
				if (this.pictures.length > 1) {
					this.current = Math.floor(Math.random() * this.pictures.length);
				} this.setImage(this.pictures[this.current]);
				sandyEvents.add('onresize','bg',function() {sandyPage.oBack.adjust()});

			},

			setImage : function (oImg) {
				
				if (this.needFix) {
					this.oDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+oImg+",sizingMethod='scale')alpha(opacity=100)";
					this.oDiv.style.display = 'block';
				} else {
					var a = this.oDiv.childNodes.length ? this.oDiv.firstChild : this.oDiv.appendChild(document.createElement('img'));
					a.src = oImg;					
				} this.adjust();				

			},

			next : function () {

				if (this.pictures.length < 2) return;
				this.current++;
				if (this.current == this.pictures.length) this.current = 0;
				this.setImage(this.pictures[this.current]);

			},

			show : function () {
				
				if (this.shown) return sandyScript.run();
				sandyUtils.opacity(0,this.oDiv);
				this.oDiv.style.visibility = 'visible';				
				var cBack = function () {
					sandyPage.oBack.shown = true;
					sandyUtils.opacity(100,sandyPage.oBack.oDiv);
					sandyScript.run();
				}; var anim = function (a) {
					sandyUtils.opacity(a * 10,sandyPage.oBack.oDiv);
				}; var a = sandyUtils.animator(10,100,anim,cBack);
				a.run();

			},

			adjust : function () {

				var w = document.body.clientWidth;
				var h = document.body.clientHeight;
				if (w * this.size.r > h) {
					var i_w = w > this.size.w ? w : this.size.w;
					var i_h = Math.round(this.size.h * i_w / this.size.w);						
				} else {
					var i_h = h > this.size.h ? h : this.size.h;
					var i_w = Math.round(this.size.w * i_h / this.size.h);
				} if (this.needFix) {
					sandyUtils.props(this.oDiv.style,'width,'+i_w+'px,height,'+i_h+'px');
				} else {
					sandyUtils.props(this.oDiv.firstChild.style,'width,'+i_w+'px,height,'+i_h+'px');
				}

			}

		}; this.oBack.create(this.oPane,oImg);

	}

}

function sandyPageLink (s) {

	this.s = s;
	this.elems = new Array();
	if (s.length > 1) {
		var a = s.split('/');
		for (var i = 0; i < a.length; i++) {
			if (a[i].length) this.elems.push(a[i]);
		} 
	} 

}

sandyPageLink.prototype.count = function () {

	return this.elems.length;

}

sandyPageLink.prototype.hashed = function (s) {

	s = !s ? document.location.hash : s;
	if (s.length > 1) {
		var a = s.substring(1).split('/');
		for (var i = 0; i < a.length; i++) {
			if (a[i].length) this.elems.push(a[i]);
		} 
	} return this.elems.length > 1 ? true : false;

}

sandyPageLink.prototype.href = function () {

	if (this.elems.length) {
		return '/'+this.elems.join('/') + '/';
	} else {
		return '/';
	}

}

sandyPageLink.prototype.rel = function () {

	if (!this.elems.length) return "";
	var link = '/'+this.elems[0]+'/';
	if (this.elems.length > 1) link += '#/';
	for (var i = 1; i < this.elems.length; i++) link = link + this.elems[i]+'/';
	return link;

}

var sandyEvents = {

	events : {},
	defered : {},

	attach : function (oElem,tEvent) {

		this.events[tEvent] = {};
		this.defered[tEvent] = true;
		oElem[tEvent] = function (e) {
			return sandyEvents.handle(e);
		}; 

	},

	add : function (e,oName,cBack) {

		if (!this.events[e]) return false;
		this.events[e][oName] = cBack;

	},

	cancel : function (e) {

		if (this.defered[e]) this.defered[e] = false;

	},

	drop : function (e,oName) {

		var a = {};
		if (!this.events[e]) return false;		
		for (var b in this.events[e]) {
			if (b == oName) continue;
			a[b] = this.events[e][b];
		} this.events[e] = a;

	},

	handle : function (e) {

		e = !e ? window.event : e;
		if (sandyPage.fBuzy) {
			e.cancelBubble = true;
			return false;
		} var eType = 'on'+e.type;
		for (var a in this.events[eType]) {
			this.events[eType][a](e);
			if (!this.defered[eType]) {
				this.defered[eType] = true;
				e.cancelBubble = true;
				return false;
			}
		} return true;

	}

}

var sandyScript = {

	count : 0,
	items : null,

	reset : function () {

		this.count = 0;
		this.items = new Array();

	},
	
	add : function (cBack,w,a) {

		var o = {};
		o.cBack = cBack;
		o.wait = w ? w : 0;
		o.arg = a ? a : false;
		o.active = true;
		this.items[this.count++] = o;

	},

	rollback : function () {

		if (!this.count) return false;
		for (var i = 0; i < this.count; i++) {
			if (this.items[i].active) {
				if (i) {
					this.items[i-1].active = true;
					return false;
				}
			}
		} this.items[this.count-1].active = true;
		return false;

	},

	run : function () {

		if (!this.count) return false;
		sandyPage.fBuzy = true;
		for (var i = 0; i < this.count; i++) {
			if (this.items[i].active) {
				this.items[i].active = false;
				var cBack = function () {
					sandyScript.items[i].cBack(sandyScript.items[i].arg);
				}; setTimeout(cBack,this.items[i].wait);
				return false;
			}
		} sandyPage.fBuzy = false;
		
	}

}

var sandyLoader = {

	oElem : null,
	fCount : 8,	
	oSrc : '/loader/loader',
	oExt : 'gif',
	oDim : {x : 50, y : 50},
	fIndex : 0,
	uSec : 60,
	fTimer : null,
	cBack : false,

	init : function (oDiv) {		
		
		this.oElem = oDiv ? oDiv.appendChild(document.createElement("DIV")) : document.body.appendChild(document.createElement("DIV"));
		sandyUtils.props(this.oElem.style,"display,none,position,absolute,top,50%,marginTop,-"+Math.round(this.oDim.y/2)+"px,marginLeft,-"+Math.round(this.oDim.x/2)+"px,left,50%,zIndex,100,width,"+this.oDim.x+"px,height,"+this.oDim.y+"px");
		for (var i = 0; i < this.fCount; i++) {
			var oImg = document.createElement("img");
			sandyUtils.props(oImg.style,"width,"+this.oDim.x+"px,height,"+this.oDim.y+"px,padding,0px,margin,0px,display,none");
			oImg.src = this.oSrc+(i+1)+'.'+this.oExt;
			this.oElem.appendChild(oImg);
		} this.fTimer = null;

	},

	attach : function (oDiv) {

		this.oElem = oDiv.appendChild(this.oElem.parentNode.removeChild(this.oElem));

	},

	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();
			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();
			this.cBack();
		}

	},

	start : function () {

		if (this.fTimer) clearInterval(this.fTimer);
		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.uSec);

	},

	stop : function () {

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

	}

}

var sandyXml = {

	fetchString:function(u){var r=this.c(u);if(r.e)return false;return r.d()},
	getString:function(u,f){var r=this.c(u,0,f);if(r.e)return false;return r.d()},
	sendString:function(u,d){var r=this.c(u,0,false,d);if(r.e)return false;r.d();return true},
	postString:function(u,d,f){var r=this.c(u,0,f,d);if(r.e)return false;r.d();return true},
	fetchXml:function(u){var r=this.c(u,1);if(r.e)return false;return r.d()},	
	getXml:function(u,f){var r=this.c(u,1,f);if(r.e)return false;r.d();return true},
	c:function(){
		var a=arguments;
		var r={e:false,u:a.length?a[0]:false,t:a.length>1?a[1]:0,a:a.length>2?true:false,c:a.length>2?a[2]:false,m:a.length>3?"POST":"GET",b:a.length>3?a[3]:null};
		try{r.x=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){try{r.x=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{r.x=new XMLHttpRequest()}catch(e){r.e=true;return false}}}
		r.d=function(){r.x.open(this.m,this.u,this.a);
		if(this.m == "POST"){r.x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");r.x.setRequestHeader("Content-length", this.b.length);r.x.setRequestHeader("Connection", "close")}
		if(this.a && this.c){r.x.onreadystatechange=function(){if(r.x.readyState != 4){return}clearTimeout(r.timeout);
		if(r.x.status != 200){if(r.timeout){r.c(new Error(101,'XML_BAD_REQUEST'),false)}else{r.c(new Error(102,'XML_SERVER_TIMEOUT'),false)}}else{r.c(r.t?r.x.responseXML:r.x.responseText,true)}};
		r.timeout=setTimeout(function(){r.timeout=false;r.x.abort()},15000);r.x.send(this.b);
		}else{r.x.send(this.b);if(r.x.status != 200){throw new Error(101,'XML_BAD_REQUEST')}return this.t?r.x.responseXML:r.x.responseText}
		}; return r;			
	} 

}

var sandyUtils = {

	block : function (e) {e = !e ? window.event : e;e.cancelBubble = true;return false;},	
	unshiftChild : function (o,t) {if (o.childNodes.length) return o.insertBefore(document.createElement(t),o.childNodes[0]);return o.appendChild(document.createElement(t));},
	fLinear : function (t, b, c, d) {return c*t/d + b;},
	fCubicIn : function (t, b, c, d) {return c*((t=t/d-1)*t*t + 1) + b;},
	fCubicOut : function (t, b, c, d) {return c*(t/=d)*t*t + b;},
	fCubicInOut : 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;},
	getElem : function (o,t,c) {var p = o;do{if (p.tagName && p.tagName.toLowerCase() == t) {if (c) {if (p.className == c || p.getAttribute("id") == c) return p} else {return p}}} while (p = p.nextSibling);return false},
	animator : function (f,u,c,k,z) {var o = {};o.f = f;o.u = u;o.c = c;o.k = k;o.z = z ? z : 0;o.a = function () {if (o.b == o.f) {clearInterval(o.i);if (o.k) {if (o.z) {setTimeout(o.k,o.z);} else {o.k();}}return;} o.c(o.b);o.b++;}; o.run = function () {o.b = 0;o.i = setInterval(o.a,o.u);}; return o;},
	png : function (o,i) {var a = navigator.appVersion.split("MSIE");var b = parseFloat(a[1]);if ((b >= 5.5) && (document.body.filters)) {o.src = '/img/em.gif';o.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + i + "', sizingMethod='scale')";} else {o.src = i;}},
	props : function (o,s) {var h = s.split(",");for (var i = 0; i < h.length; i+=2) eval('o.'+h[i]+' = "'+h[i+1]+'"');},
	opacity : function (v,o) {if (o.filters) {if (!o.filters.length) {o.style.filter = "alpha(opacity=" + v + ")";} if (v == 100) {o.filters("alpha").enabled = false;} else {o.filters("alpha").opacity = v;o.filters("alpha").enabled = true;}} else {o.style.opacity = (v / 100);}}

}

window.onload = function () {
	var oPane;
//	return true;
	if ((oPane = document.getElementById("sitePane"))) {
		sandyEvents.attach(window,'onresize');
		sandyEvents.attach(window.document,'onclick');
		sandyPage.init(oPane);
	} 

}