//-------------------------------
var D = document;
var C;
var sprt = (document.getElementById || document.all);
var sprtL = (sprt || document.layers);
var ownMode = (top == self);
if (!ownMode) top.location.href = './';
//-------------------------------
String.prototype.trim = function() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
//-------------------------------
function E(id) {return D.getElementById(id);}
function V(id) {return E(id).value;}
function vS(id,val) {E(id).value = val;} //
function d0(id) {E(id).style.display = "none";}
function d1(id) {E(id).style.display = "block";}
function U(v) {return typeof v == "undefined";}
function M(a) {return a.length;}
//-------------------------------
var C = {
	init: function(a) {
		this.br = ["opera","msie","applewebkit","firefox","camino","mozilla"],
		this.sys = ["x11;","macintosh","windows"],
		this.ver = [7,5.5,125,0.8,1,7],
		this.type = -1; this.os = -1; this.version = 0; this.revision = 0;
		var a = a.toLowerCase();
		for (var b = 0; b < M(this.br); b++) {
			var c = this.br[b];
			if (a.indexOf(c)!=-1) {
				this.type = b;
				var d = new RegExp(c+"[ /]?([0-9]+(.[0-9]+)?)");
				if (d.exec(a)) {
					this.version = parseFloat(RegExp.$1);
				}
				break;
			}
		}
		for (var b=0; b<M(this.sys); b++) {
			var c = this.sys[b];
			if (a.indexOf(c)!=-1) {
				this.os = b;
				break;
			}
		}
		if (this.OK() && /\brv:\s*(\d+\.\d+)/.exec(a)) {
			this.revision = parseFloat(RegExp.$1);
		}
	},
	OK: function () {return this.type==3 || this.type==5 || this.type==4},
	sprt: function () {
		for (var b = 0; b < M(this.ver); b++)
			if (this.type==b) return this.version >= this.ver[b];
		return false;
	}
};
C.init(navigator.userAgent);
//-------------------------------
/*function goDeeper(el, ratio) {
	if (el.childNodes.length > 0)
		el.getChildren().each(function(sub_el){
			if (sub_el.nodeName == 'IMG') {
				width = sub_el.getStyle('width').toInt();
				sub_el.setStyle('width', (width * ratio).round() + 'px');
			}
			goDeeper(sub_el, ratio);
		});
}*/
function nav_repos() {
	var inbetween = 20;
	var bg = $('contentWrap');
	if (bg == null) return;
	var cn = $('content');
	if (cn == null) return;
	
	//paddingLeft = cn.getStyle('padding-left').toInt();
	//paddingTop = cn.getStyle('padding-top').toInt();
	var halfHeight = (cn.getSize().y / 2).round();
	var halfWidth = (cn.getSize().x / 2).round();

	var offset = halfWidth;
	var list = $$('#content div.nav');
	list.reverse();
	var count = 0;
	list.setStyle('visibility', 'hidden');
	list.each(function(el) {
		if (el.id.indexOf('level')>-1) {
			height = el.getSize().y;
			if (height > cn.getSize().y - 90) {
				height = cn.getSize().y - 90;
				el.setStyle('height', height);
				$('slider').setStyle('display','block');
				if ($('slider') !== null) {
					var Slide = new Slider($('slider'), $('knob'), {	
						steps: el.scrollHeight - height,
						mode: 'vertical',
						onChange: function(step){
							el.scrollTop = step;
						}
					}).set(0);
				}
			}
			middle = (height / 2).round();
/*			if (count>0 && count < list.length-1) {
				el.setStyle('width', '50px');
				el.getFirst().getChildren().each(function(subs){
					subs.oldWidth = subs.getStyle('width');
					subs.setStyle('overflow', 'hidden');
					subs.setStyle('width', '50px');
				});
			}*/
			width = el.getSize().x;
			if (count>0) offset -= width + inbetween;
			el.setStyle('top', halfHeight - middle + 'px');
			el.setStyle('left', offset + 'px');
			el.setStyle('overflow','hidden');
			count++;
			imgs = $$('#'+el.id+' img');
			imgs.each(function(img){
				img.oldSrc = img.src;
				img.newSrc = img.src.replace(/\/1(\d+)\//,'/1$1/on/');
				img.onmouseover = function (){
					img.src = img.newSrc;
					//li = img.getParent().getParent();
					//li.setStyle('width', '100px');
				};
				img.onmouseout = function (){
					img.src = img.oldSrc;
					//li = img.getParent().getParent();
					//li.setStyle('width', '50px');
				};
			});
		}
	});
	list.setStyle('visibility', 'visible');
/*	offset += inbetween;
	level1 = $('level1');
	height = (level1.getSize().y / 2).round();
	width = level1.getSize().x;
	level1.setStyle('top', halfHeight - height + 'px');
	level1.setStyle('left', offset + 'px');
	*/
	//hide_all(false);
}

function hide_all(hide) {
	list = $$('#content div');
	list.each(function(el) {
		if (el.id.indexOf('level')>-1) {
			el.setStyle('visibility', (hide===true?'hidden':'visible'));
		}
	});
}

window.addEvent('domready', function(){
	//hide_all(true);
});
window.addEvent('load', function(){
	nav_repos();
});