// info ------------------------------------------
// 
// VARs:
// 	doc.x
// 	doc.y
// 	path2photo
// 	path_up
// 	Pnum
// 	Pquant
// 	PP_place_w
// 	PP_place_h
// 	prev_pg
// 	steps2photos
// 	next_pg
// 	Qrows
// 	Qcols
// 
// Arrays:
//	themes
// 	groups
// 	items
// 
// ----------------------------------------------

function count_PP_table() {
	get_doc_dimentions(doc);
	Qcols=div(doc.x,PP_place_w);
	if (Qcols == 0) Qcols=1;
	Qrows=div(doc.y-62,PP_place_h);
	if (Qrows == 0) Qrows=1;
	Pplaces=Qrows*Qcols;
}

function page_redraw() {
	oldQcols=Qcols;
	oldQrows=Qrows;
	count_PP_table();
	if (doc.x < 500 || doc.y < 300) {Qcols=oldQcols; Qrows=oldQrows;}
	else if (oldQcols != Qcols	|| oldQrows != Qrows) document.location=document.location;
}

function wrt_body(n) {
	main(n);
	if (n == 0) ini_previews();
	wrt_header();
//- previews
	if (n == 0) previews()
	else wrt_info();
	wrt_footer();
}

function menu_items() {
	wrt("<span id=Mitems class='drop_menu'>");
	if (steps2photos < 2) {
		wrt("<span class='line'"+MC_prevent+">"+cur_group_legend+"</span><br>");
		menu_tablewrtbegin();
		for(var i =0; i < (items.length); i+=3) {
			if (items[i] == 'separator') wrt("<em></em>")
			else {
				wrt("<a href='");
				for(var j =1; j > steps2photos; j--) wrt("../");
				wrt(items[i]+"/' title='"+items[i+2]+"'>&nbsp;"+items[i+1]+"</a>");
			}
		}
		menu_tablewrtend();
	}
	wrt("</span>");
	if ((steps2photos < 2) && (cur_group_legend != "...")) wrt("<a onMouseOver='Mopen(\"Mitems\")'>"+cur_group_legend+"</a> » ");
}

function menu_groups() {
	wrt("<span id=Mgroups class='drop_menu'>");
	if (steps2photos < 3) {
		wrt("<span class='line'"+MC_prevent+">"+cur_theme_legend+"</span><br>");
		menu_tablewrtbegin();
		for(var i =0; i < (groups.length); i+=3) {
			if (groups[i] == 'separator') wrt("<em></em>")
			else {
				wrt("<a href='");
				for(var j =2; j > steps2photos; j--) wrt("../");
				wrt(groups[i]+"/' title='"+groups[i+2]+"'>&nbsp;"+groups[i+1]+"</a>");
			}
		}
		menu_tablewrtend();
	}
	wrt("</span>");
	if ((steps2photos < 3) && (cur_theme_legend != "...")) wrt("<a onMouseOver='Mopen(\"Mgroups\")'>"+cur_theme_legend+"</a> » ");
}

function menu_themes() {
	wrt("<span id=Mthemes class='drop_menu'>"
	+"<span class='line'"+MC_prevent+">"+title_photo+"</span><br>");
	menu_tablewrtbegin();
	for(var i =0; i < (themes.length); i+=3) {
		if (themes[i] == 'separator') wrt("<em></em>")
		else {
			wrt("<a href='");
			for(var j =3; j > steps2photos; j--) wrt("../");
			wrt(themes[i]+"/' title='"+themes[i+2]+"'>&nbsp;"+themes[i+1]+"</a>");
		}
	}
	menu_tablewrtend();
	wrt("</span><a onMouseOver='Mopen(\"Mthemes\")'>"+title_photo+"</a> » ");
}

function menu_tablewrtbegin() {
	wrt("<table"+MC_prevent+"><tr height=11><td width=11 class='tl'><td class='t'><td width=11 class='tr'><tr><td class='l'><td class='c'>");
}
function menu_tablewrtend() {
	wrt("<td class='r'><tr height=11><td class='bl'><td class='b'><td class='br'></table>");
}

function menu_pg_selector() {
	wrt("<span id=pg_selector class='drop_menu'"+MC_prevent+">"
	+"<p>");
	for(var i =0; i < Math.ceil(Pquant/Pplaces); i+=1) {
		if (lang == 'en')
			wrt("<a href='?"+(i*Pplaces+1)+"'>&nbsp;&deg;&nbsp;Page&nbsp;"+(i+1)+"</a>")
		else
			wrt("<a href='?"+(i*Pplaces+1)+"'>&nbsp;&deg;&nbsp;Страница&nbsp;"+(i+1)+"</a>");
	}
	wrt("</p></span>");
}

function Mopen(Mname) {
	close_menus();
	document.getElementById(Mname).style.display='';
}
function Mclose(Mname) {
	document.getElementById(Mname).style.display='none';
}
function close_menus() {
	if (previewing) Mclose('pg_selector');
	if (touched_menu) {
		Mclose('Mthemes');
		Mclose('Mgroups');
		Mclose('Mitems');
	}
	else {
		touched_menu=true;
		if (steps2photos < 3) {
			Mclose('Mthemes');
			if (steps2photos < 2) {
				Mclose('Mgroups');
				if (steps2photos < 1) Mclose('Mitems');
			}
		}
	}
}

function close_in_time() {
	closing_timer=setTimeout("close_menus()",300)
}

function previews(){
wrt("<table class=pp_holder cellspacing='5px'>");
for(var i =1; i <= Qrows; i++){
wrt("<tr>");
for(var j =1; j <= Qcols; j++){
	wrt("<td class=pp_holder align='center' valign='middle'>");
	if ((i==1) && (j==1) && (Pnum > 1)) wrt("<a class=pg_turners style='left: 3px;' href='?"+prev_pg+"'><img src='../../../pics/pg_prev_pp.gif' alt='-'></a>");
	if ((i==Qrows) && (j==Qcols) && (Pnum < Pquant)) wrt("<a class=pg_turners style='right: 3px;' href='?"+next_pg+"'><img src='../../../pics/pg_next_pp.gif' alt='+'></a>");
	wrt("<table width=120 height=90><tr>"
		+"<td>");
		if (Pnum <= Pquant) {
			n=(Pnum-1)*2+1;
			if (photos[n] == "") photos[n]="...";
			wrt("<span class='prevtorn'><a href='show.shtml?photo="+photos[n-1]+"'><img src='../../../pics/torned_preview.gif' title='"+photos[n]+"'></a></span>"
			+ "<img  class='preview' src='../../../photos/"+photos[n-1]+"_p.jpg'>");
		}
		wrt("</table>");
	Pnum++
}}
wrt("</table>");
}

function wrt_info(){
	wrt("<table class=spreaded><tr height=20><td>"
	+ "<tr><td valign='bottom' id=navwall><table><tr><td>"
	+ info
	+ "</table>"
	+ "</table>");
}

// ---------------------------------------------- show ------------------------------------------

function wrt_shprev(preview_num) {
	ph_num = CurrPh-3+preview_num;
	Z=(ph_num-1)*2;
	wrt("<tr height='92px'><td>");
	if ( ph_num < 1 || ph_num > Pquant ) wrt("<span style='display:none' class='prevtorn' id=ph_previewS"+preview_num+"><a id=ph_previewA"+preview_num+"><img src='../../../pics/torned_preview.gif'></a></span>"
		+ "<img class='preview' id=ph_preview"+preview_num+" src='../../../pics/unpreview.gif'><tr height='30px'><td>")
	else wrt("<span class='prevtorn' id=ph_previewS"+preview_num+"><a id=ph_previewA"+preview_num+" title='"+photos[Z+1]+"' href='show.shtml?photo="+photos[Z]+"'><img src='../../../pics/torned_preview.gif'></a></span>"
		+ "<img class='preview' id=ph_preview"+preview_num+" src='../../../photos/"+photos[Z]+"_p.jpg'><tr height='30px'><td>");
}

function turn_prvws(num) {
	if ( Pquant > 2) {
		ph1 = CurrPh-2+num;
		if ( (ph1+3) > Pquant ) ph1=Pquant-3;
		if ( ph1 < 0 ) ph1=0;
		if ( Pquant < 3) ph1=-1;
		N=1;
		for(var ph_num=ph1; ph_num <= ph1+4; ph_num++) {
			if ( ph_num < 1 || ph_num > Pquant ) ImgSrc(N, -1)
			else ImgSrc(N, ((ph_num-1)*2) );
			N++;
		}
		CurrPh=ph1+2;
	}
}

function ImgSrc(imgnum, phID) {
	if (phID == -1) {
		document.getElementById('ph_preview'+imgnum).src='../../../pics/unpreview.gif';
		document.getElementById('ph_previewS'+imgnum).style.display='none';
	}
	else {
		document.getElementById('ph_preview'+imgnum).src='../../../photos/'+photos[phID]+'_p.jpg';
		document.getElementById('ph_previewA'+imgnum).href='show.shtml?photo='+photos[phID];
		document.getElementById('ph_previewA'+imgnum).title=photos[phID+1];
		document.getElementById('ph_previewS'+imgnum).style.display='';
	}
}

function wrt_header() {
	if (previewing) menu_pg_selector();
//- main table code
	wrt("<div class=spreaded><table class=spreaded>"
	+ "<tr height='41'><td>");
//- header
	wrt("<table class=header><tr><td width=12>"
	+ "<td width=105><a href='../"+path_up+"'><img src='"+path_up+"pics/dao.pp.ru-small.gif' height='41' width='92' alt=''></a>"
	+ "<td align='left' width=470><font id=pagetitle>" + pagetitle + "</font><br>");
	menu_navig();
	wrt("<td>&nbsp;"
	+ "<td width=40 align='center'>");
	if (lang == 'en') wrt("<A href='http://www.narod.ru/guestbook/?owner=35356426&mainhtml=in-form-en.html&messageshtml=message-en.html' target='_blank'><img src='"+path_up+"pics/comm.gif' alt='' title='guestbook'></A>")
	else wrt("<A href='http://www.narod.ru/guestbook/?owner=35356426&mainhtml=in-form.html&messageshtml=message.html' target='_blank'><img src='"+path_up+"pics/comm.gif' alt='' title='посетить гостевую'></A>");
	wrt("<td width=40 align='center'>");
	wrt_mail("photo","dao.pp.ru","<img src='"+path_up+"pics/mail.gif' alt=''>");
	wrt("<td width=40 align='center'><A href='"+path_up+"techinfo.shtml' target='_blank'><img src='"+path_up+"pics/technics.gif' alt='' ");
	if (lang == 'en') wrt("title='some information'></A>")
	else wrt("title='околотехническая информация'></A>");
	if (show_coin) wrt("<td width=40 align='center'><A href='"+path_up+"price.shtml' target='_blank'><img src='"+path_up+"pics/coin.gif' alt='' title='позаботиться о нашем бюджете'></A>");
	wrt("<td>&nbsp;<td align='right' width=100>");
	wrt_langswitcher();
	wrt("<td width=13></table>");
//- main table code
	wrt("<tr><td>");
}

function wrt_footer() {
//- main table code
	wrt("<tr height='20'><td>");
//- footer
	wrt("<table class=footer><TR>"
	+ "<TD width=10>"
	+ "<TD align=left>&copy; "+design+" <a href='http://kitaets.livejournal.com/'>Kitaets</a>"
	+ "<TD align=right>"+miniinfo
	+ "<TD width=10></table>");
//- main table code
	wrt("</table></div>");
}

function menu_navig() {
	wrt("<font id=head_menu><a href='../"+path_up+"photo.shtml'>"+title_main+"</a> » ");
	menu_themes();
	menu_groups();
	menu_items();
	if (steps2photos == 0) wrt("<a href='../"+cur_item+"/'>"+cur_item_legend+"</a></font>")
	else wrt("...");
	close_in_time();
}

// ----------------- to do ---------------
// window.onfocus = new Function("document.bgColor='antiquewhite'")