for (j = 0; j <= galleries.length - 1; j++) {
	for (i = 0; i <= galleries[j].photos.length - 1; i++)
		document.write('<a class="fancybox" rel="' + galleries[j].id + '" href="' + galleries[j].photos[i] + '"></a>');
}

var counter = 0;
var loaded_images = new Array();
for(i = 1; i <= 3; i++)
	for (j = 0; j < pun[i].length - 1; j++)
		for (k = 0; k < pun[i][j].photos.length - 1; k++) {
			document.write('<img onload="iAmLoaded()" src="' + pun[i][j].photos[k].min + '">');
			counter++;
		}

var count = counter;

function iAmLoaded() {
	document.getElementById("progress_bar").style.width = Math.ceil(100 - 100*(--counter / count)) + '%';
	if (0 == counter)
		showContent();
}

var speed = 70;
var cmargin = 0;
var cimg = 0;	
var cursize2 = [];
var curmm2 = [];	
var cursize2 = [];
var shag = 0;
var curcol2 = [];
var okopm1 = 0;
var initspeed = 0;
var idealmnu2 = 0;
var curpol = 0;
var tops = [999, 235, 277, 319];
var _height = 21;

var curmenucolumn2;
function initright(fid, sed) {
	$("#content").fadeOut(300);
	
	setTimeout('iniright2(' + fid + ',' + sed + ')', 450);
}

function showimages() {

 document.getElementById('rar').style.display = 'none';
		document.getElementById('lar').style.display = 'none';
			
		if(pun[okopm1][curmenucolumn2].photos.length < 7) {
			document.getElementById('rar').style.display = 'none';
			document.getElementById('lar').style.display = 'none';
			
		} else {
		 
			document.getElementById('lar').style.display = 'none';
			document.getElementById('rar').style.display = 'block';
		}	
			
	document.getElementById('roll2').style.display = 'block';
	imagescount = pun[okopm1][curmenucolumn2].photos.length - 1;
	if(imagescount>5)
		imagescount=5;
	for (i = 0; (i <= imagescount); i++) {
		setTimeout('$("#miu" + ' + i + ').fadeIn(100);', speed*i);
	}

}

function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1)
		return false;
	else
		return true;
}

function iniright2(fid, sed) {
	curmenucolumn2 = sed;
	document.getElementById('rar').style.display = 'none';
	document.getElementById('lar').style.display = 'none';
	document.getElementById("title").innerHTML = (pun[fid][sed].zag);
	document.getElementById("text").innerHTML = "";
	if (pun[fid][sed].text)
		document.getElementById("text").innerHTML = pun[fid][sed].text;

	document.getElementById('roll2').innerHTML = '';
	if (pun[fid][sed].photos.length > 0) {
		document.getElementById('roll').style.display = 'block';
		document.getElementById('roll2').style.display = 'none';

		

		document.getElementById("text").style.marginTop = '0px';
		document.getElementById("title").style.marginTop = '0px';

		sss = '';
		j = 0;
		l = 0;
		for (i = 0; i <= pun[fid][sed].photos.length - 1; i++) {
			if (isArray(pun[fid][sed].photos[i].url)) {
				j++;
				rel = 'rel' + j + 'rel';
				for (k = 0; k < pun[fid][sed].photos[i].url.length; k++) {
					sss += '<a rel="' + rel + '"';
					sss += ' style="display:none;"';
					sss += ' id="miu' + (l) + '" href="' + pun[fid][sed].photos[i].url[k] + '">';
					if (k == 0)
						sss += '<img src="' + pun[fid][sed].photos[i].min + '" style="width: 60px;">';
					sss += '</a>';
				}

				$("a[rel*=" + rel + "]").fancybox({
					frameWidth: 1000,
					frameHeight: 500,
					overlayShow: true,
					overlayOpacity: 0.9
				});
			} else {
				sss += '<a rel="fancybox"';
				sss += ' style="display:none;"';
				sss += ' id="miu' + (l) + '" href="' + pun[fid][sed].photos[i].url + '"><img src="' + pun[fid][sed].photos[i].min + '"></a>';
			}
			l++;
		}

		document.getElementById('roll2').innerHTML = sss;

		while (j > 0) {
			rel = "rel" + j-- + "rel";

			$("a[rel*=" + rel + "]").fancybox({
				frameWidth: 1000,
				frameHeight: 500,
				overlayShow: true,
				overlayOpacity: 1
			});
		}

		$("a[rel*=fancybox]").fancybox({
			frameWidth: 1000,
			frameHeight: 500,
			overlayShow: true,
			overlayOpacity: 1
		});

		for (i = 0; i <= pun[fid][sed].photos.length - 1; i++) {
			document.getElementById("miu" + i).onmouseover = function() {
				thisid = (this.id.substr(3));
				document.getElementById("title").innerHTML = (pun[okopm1][curmenucolumn2].photos[thisid].headline);
				document.getElementById("text").innerHTML = (pun[okopm1][curmenucolumn2].photos[thisid].text);
				$('.fancybox').fancybox({
					frameWidth: 1000,
					frameHeight: 500,
					overlayShow: true,
					overlayOpacity: 1
				});
			}
		}

		document.getElementById('roll2').style.marginLeft = '0px';
		t=setTimeout('showimages()', 200);
	} else {
		document.getElementById("text").style.marginTop = '-23px';	
		document.getElementById("title").style.marginTop = '54px';	
		document.getElementById('roll').style.display = 'none';
		document.getElementById('lar').style.display = 'none';
		document.getElementById('rar').style.display = 'none'; 
	}

	cimg = 0;
	cmargin = 0;
	$('.fancybox').fancybox({
		frameWidth: 1000,
		frameHeight: 500,
		overlayShow: true,
		overlayOpacity: 1
	}); 

	$("#content").fadeIn(300);
}

var t;
function initm() {
	curm2 = 0;
	cursize2 = [];
	curcol2 = [];
	curmm2 = [];
	curpol = 0;

	s = "";
	for (i = 0; i <= pun[okopm1].length - 1; i++) {
		s += ('<li id="msu' + i + '"');
		if (i == 0) {
			s += ' style="font-size: 25px; color: black;"';
		}
		s += ('>' + pun[okopm1][i].headline + '</li>');
		cursize2[i] = 16;
		curcol2[i] = 148;
		curmm2[i] = 0;
	}

	curmm2[0] = 1;
	initright(okopm1, 0);
	document.getElementById("menu2").innerHTML = s;
	document.getElementById("menu2").style.top = tops[okopm1] + "px";
	document.getElementById("menu2").style.marginTop = "0px";
	$('#msu0' ).css("line-height", "30px");
	setTimeout("$('#menu2').fadeIn(300);", 200);

	for (i = 0; i <= pun[okopm1].length - 1; i++) {
		document.getElementById("msu" + i).onclick = function() {
			thisid = (this.id.substr(3));

			if (thisid > 0)
				curmm2[0] = 0;

			document.getElementById('rar').style.display = 'none';
			document.getElementById('lar').style.display = 'none';
			if (thisid != curm2) {
				$('#msu' + curm2).css("line-height", "21px");
				$('#msu' + curm2).animate({
					fontSize: '16px' 
				});
				curm2 = thisid;
				$('#msu' + curm2).css("line-height", "30px");
				$('#msu' + curm2).animate({
					fontSize: '25px'
				});
			}
			idealmnu2 = -1*((thisid)*_height);
			initspeed = curpol;

			new_margin = Math.round(idealmnu2) + "px";
			$('#menu2').animate({
				marginTop: new_margin
			},  { duration: 300, easing: 'easeOutBack' });	
			
			curstep = Math.abs(idealmnu2 - curpol)*0.05;
			shag = 0;
			initright(okopm1, thisid);
			return false;
		}
	}

	for (i = 0; i <= pun[okopm1].length - 1; i++) {
		document.getElementById("msu" + i).onmouseover = function() {
			thisid = (this.id.substr(3));
			curmm2[thisid] = 1;
		}
	}

	for (i = 0; i <= pun[okopm1].length - 1; i++) {
		document.getElementById("msu" + i).onmouseout = function() {
			thisid = (this.id.substr(3));
			curmm2[thisid] = 0;
		}
	}

	document.getElementById("content").style.top = (-45 + tops[okopm1]) + "px";
}

var status = 0;		
var d = 10;
var c = 0; 
curm1 = 0;		
var curstep = 0.5;
curm2 = 1;
var timer1;
var curm = ['нулябрь', 0, 0, 0];	

var curcol1 = [148, 148, 148];		
var cursize1 = [35, 35, 35];		

document.getElementById("mnu1").onclick = function() {
	status = 0;
	curm1 = 1;
	bambustatus=0;
	$("#content").fadeOut(300);
	$('#menu2').fadeOut(300);
	okopm1 = curm1;
	clearInterval(timer1);
	timer1 = setTimeout("initm()", 600);
	document.getElementById('rar').style.display = 'none';
	document.getElementById('lar').style.display = 'none';
};

document.getElementById("mnu2").onclick = function() {
	status = 0;
	curm1 = 2;
	bambustatus=0;
	clearInterval(timer1);
	$("#content").fadeOut(300);
	$('#menu2').fadeOut(300);
	okopm1 = curm1;
	timer1 = setTimeout("initm()", 600);
	document.getElementById('rar').style.display = 'none';
	document.getElementById('lar').style.display = 'none';
};

document.getElementById("mnu3").onclick = function() {
	status = 0;
	curm1 = 3;
	bambustatus=0;
	clearInterval(timer1);
	$("#content").fadeOut(300);
	$('#menu2').fadeOut(300);
	okopm1 = curm1;
	timer1 = setTimeout("initm()", 600);
	document.getElementById('rar').style.display = 'none';
	document.getElementById('lar').style.display = 'none';
};

document.getElementById("mnu1").onmouseover = function() {
	curm[1] = 1;
};

document.getElementById("mnu2").onmouseover = function() {
	curm[2] = 1;
};

document.getElementById("mnu3").onmouseover = function() {
	curm[3] = 1;
};

document.getElementById("mnu1").onmouseout = function() {
	curm[1] = 0;
};

document.getElementById("mnu2").onmouseout = function() {
	curm[2] = 0;
};

document.getElementById("mnu3").onmouseout = function() {
	curm[3] = 0;
};

document.getElementById("rar").onclick = function() {
};

document.getElementById("lar").onclick = function() {
};

var timer2;
document.getElementById("rar").onmousedown = function() {
	incri();
	timer2 = setInterval("incri()", 600);
};

document.getElementById("rar").onmouseup = function() {
	clearInterval(timer2);
};

document.getElementById("lar").onmousedown = function() {
	decri();
};

document.getElementById("lar").onmouseup = function() {
	clearInterval(timer2);
};

function incri() {
	if (activani == 1)
		return;
	activani = 1;

	if (cimg + 6 >= pun[okopm1][curmenucolumn2].photos.length)
		return;

	for (i = cimg + 6; i <= pun[okopm1][curmenucolumn2].photos.length - 1; i++) {
		document.getElementById("miu" + i).style.display = "none";
	}

	for (i = 0; i < 6; i++)
		$("#miu" + (cimg + i)).hide();
	
	cimg += 6;

	setTimeout("incrishow()", 400);
}

var activani = 0;
function incrishow() {
	for (i = 0; i < 6; i++)
		setTimeout('$("#miu" + ' + (cimg + i) + ').fadeIn(100);', speed*i);
 
	setTimeout('activani = 0', 900);
	if (cimg + 6 >= pun[okopm1][curmenucolumn2].photos.length) {
		document.getElementById('rar').style.display = 'none';
	} else { 
		document.getElementById('rar').style.display = 'block';
	}
	document.getElementById('lar').style.display = 'block';
}

function decri() {
	if (activani == 1)
		return;
	activani = 1;

	if (cimg <= 1)
		return;
	for (i = 0; i <= cimg - 1; i++) 	{
		document.getElementById("miu" + i).style.display = "none";
	}

	for (i = 0; i < 6; i++)
		$("#miu" + (cimg + i)).hide();
	cimg -= 6;

	setTimeout("decrishow()", 400);
}

function decrishow() {
	for (i = 0; i < 6; i++)
		setTimeout('$("#miu" + ' + (cimg + i) + ').fadeIn(100);', speed*i);

	setTimeout('activani = 0', 900);
	document.getElementById('rar').style.display = 'block'; 
	if (cimg >= 6) {
		document.getElementById('lar').style.display = 'block';
	} else {
		document.getElementById('lar').style.display = 'none';
	}
}
var bambustatus=0;
function step() {
	if (cmargin = (cimg * -70)) {
	}

	for (i = 1; i <= 3; i++) {
		c = curcol1[i - 1];
		if (curm[i] == 1) {
			if (c > 0)
				c -= 10;
		} else {
			if ((i != curm1) && c < 148)
				c += 10;
		}	

		curcol1[i - 1] = c;
		document.getElementById('mnu' + i).style.color = 'rgb(' + c + ',' + c + ',' + c + ')';

		c = cursize1[i - 1];
		if (i == curm1) {
			if (c < 50)
				c += 1;
			if (c == 50) {
			bambustatus=1;
			if(bambustatus=1)
			{
			
			}
			
				okopm1 = curm1;
				status = 1;
			}
		} else {
			if (c > 35)
				c -= 1;
		}
		cursize1[i - 1] = c;
		document.getElementById('mnu' + i).style.fontSize = c + 'px';
	}

	if (status == 1) {
		for (i = 0; i <= pun[okopm1].length - 1; i++) {
			c = curcol2[i];
			if (curmm2[i] == 1) {
				if(c > 0)
					c -= 10;
			} else {
				if ((i != curm2) && c < 148)
					c += 10;
			}
			curcol2[i] = c;
			try {
				document.getElementById('msu' + i).style.color = 'rgb(' + c + ',' + c + ',' + c + ')';
			} catch(err) {
			}
		}
	}

}

function step2() {
clearTimeout(timer3);
	if (cmargin > (cimg * -70)) {
		cmargin -= 4;
		document.getElementById('roll2').style.marginLeft = cmargin + 'px';
		clearTimeout(timer3);
		timer3 = setTimeout('step2()', 20);
	}

	if (cmargin < (cimg * -70)) {
		cmargin += 4;

		document.getElementById('roll2').style.marginLeft = cmargin + 'px';
		clearTimeout(timer3);
		timer3 = setTimeout('step2()', 20);
	}
}

var timer3;
var timer = setInterval("step()", 20);	

function showContent() {
	document.getElementById('loader').style.display = 'none';
	setTimeout("document.getElementById('_content').style.display = 'block';", 500);
}

