var menu_tree = new Array(4);
var title_tree = new Array(4);
var Widths=new Array(4);
var Heights=new Array(4);
var first_image = 0;
var thumbnails = new Array();
var images = new Array();
var titles = new Array();
var widths = new Array();
var heights = new Array();
var last_i=0;
var last_j=0;
var clck=0;
var blank, Active_icon, Inactive_icon; //gify
var count;
var ImageG
var ThumbnailG;
var readyState = false;

function ff() {
	if (first_image+8>count)
		return;
	if (first_image+16<count) {
		first_image+=8;
		document.images["up"].src="../images/Design/arrow_up_active.gif";
		document.images["up"].style.cursor="hand";
		show();
	} else
	if (first_image+16>=count) {
		first_image=count-8;
		document.images["down"].src="../images/Design/arrow_down_hover.gif";
		document.images["down"].style.cursor="default";
		document.images["up"].src="../images/Design/arrow_up_active.gif";
		document.images["up"].style.cursor="hand";
		show();
	}
}

function rew() {
	if (first_image-8>=0) {
		first_image-=8;
		document.images["down"].src="../images/Design/arrow_down_active.gif";
		document.images["down"].style.cursor="hand";
	}
	else if (first_image-8<0) {
		first_image=0;
		document.images["up"].src="../images/Design/arrow_up_hover.gif";
		document.images["up"].style.cursor="default";
		if (count>8) {
			document.images["down"].src="../images/Design/arrow_down_active.gif";
			document.images["down"].style.cursor="hand";
		}
	}
		
	show();
}

function load_gifs() {
	if (blank==null) {
		blank=new Image();
		blank.src="../images/blank.gif";
	}
	if (Active_icon==null) {
		Active_icon=new Image();
		Active_icon.src="images/li.gif";
	}
	if (Inactive_icon==null) {
		Inactive_icon=new Image();
		Inactive_icon.src="images/li.gif";
	}
}
function hide_icon(i,j) {
	var tmp = "icon_"+i;
	document.images[tmp].src=Inactive_icon.src;
	tmp+="_"+j;
	document.images[tmp].style.visibility="hidden";
}
function show_icon(i,j) {
	var tmp = "icon_"+i;
	document.images[tmp].src=Active_icon.src;
	tmp+="_"+j;
	document.images[tmp].style.visibility="visible";
}
function load_thumbs(imgs, group) {
	readyState=false;
	for (var i=0;i<imgs.length;i++) 
		group.AddImage(imgs[i]);
	group.imageupdate = thumnailsLoaded;
	LoadGroup(group);
}
function thumnailsLoaded(group) {
	if (group.numToLoad == 0)
		return;		
	if (!group.IsComplete())
		return;
	load_images(images, imageG);
}
function load_images(imgs, group) {
	readyState=false;
	document.getElementById("loading").style.display="block";
	for (var i=0;i<imgs.length;i++)
		group.AddImage(imgs[i]);
	group.imageupdate = updateProgress;
	LoadGroup(group);
}
function updateProgress(group) {
	var loading=document.getElementById("loading");
	var loaded=document.getElementById("loaded");
	if (group.numToLoad == 0) {
		loading.style.display="none";
		loaded.width="1";
		readyState = true;
		return;
	}
	var progress = parseFloat(group.numLoaded) / parseFloat(group.numToLoad);
	progress *= 500;
	loaded.width = progress;
	if (!group.IsComplete())
		return;
	loading.style.display="none";
	readyState = true;
	loaded.width="1";
}	
	
function preload(i, j) {
	load_gifs();
	hide_icon(last_i, last_j);
	hideObject("about");
	hideObject("contact");
	last_i=i;
	last_j=j;
	show_icon(i, j);
	cleanup();
	count=menu_tree[i][j].length;
	for(k=0;k<count;k++) {
		thumbnails[k]=menu_tree[i][j][k]+"_81.jpg";
		images[k]=menu_tree[i][j][k]+'.jpg';
		titles[k]=title_tree[i][j][k];
		heights[k]=Heights[i][j][k];
		widths[k]=Widths[i][j][k];
	}
	thumbnailG=new ImageGroup();
	imageG=new ImageGroup();
	load_thumbs(thumbnails, thumbnailG);
	if ((document.getElementById && !document.all) || window.opera) 
		document.getElementById("label").style.display="table-row";
  	else
		document.getElementById("label").style.display="block";
	hideObject("about");
	
	
	document.images["up"].src="../images/Design/arrow_up_hover.gif";
	document.images["up"].style.cursor="default";
	
	if (images.length>8) {
		document.images["down"].src="../images/Design/arrow_down_active.gif";
		document.images["down"].style.cursor="hand";
	}
	else {
		document.images["down"].src="../images/Design/arrow_down_hover.gif";
		document.images["down"].style.cursor="default";
	}
	show();
}
function show() {
	var name="";
	var source="";
	var m = 8;
	if ( m>count)
		m=count;
	for (i=0;i<8;i++) {
			name = "m_"+i;
			tmp="t_"+i;
		if (i<m) {
			document.getElementById(tmp).style.backgroundColor="#2D2B27";
			source=thumbnails[first_image+i];
			if (source!="") {
				document.images[name].src=source;
				document.images[name].style.display="block";
			}
		} else {
			document.images[name].src=blank.src;
			document.getElementById(tmp).style.backgroundColor="";
		}
	}
}

function mv(n) {
//	if (!readyState)
	//	return;
	if (n+1>count)
			return;
	hideObject("about");
	hideObject("contact");
	if (clck>0) {
		var tmp=clck;
		clck=0;
		muv(tmp-1);
	}
	var cur=document.images["m_"+n];
	var title="";
	opacity(cur, 1);
	title=titles[first_image+n];
	set_text("title", title);
	current=first_image+n+1;
	set_text("number", ""+current+"/"+images.length);
	show_big(n);
}
function show_big(n) {
		var w=widths[n+first_image];
		var h=heights[n+first_image];
		var tbl = document.getElementById("table");
		hideObject("about");
		hideObject("contact");
		b=document.images["big"];
		b.style.display="block";
		tbl.style.display="block";
		if (h>450)
			document.getElementById("label").style.display="none";
		if (w <= h) { //pionowo
			tbl.align="center";
			tbl.width=new String(w+8);
			tbl.style.marginTop="0px";
			tbl.rows[0].cells[0].vAlign="bottom";
			tbl.rows[0].cells[0].align="left";
			tbl.rows[0].cells[0].height=new String(h+25);
		}
		else { //poziomo
			tbl.align="left";
			tbl.rows[0].cells[0].align="right";
			tbl.rows[0].cells[0].width="600";
			tbl.width="600";
			tbl.style.marginTop="20px";
			tbl.rows[0].cells[0].vAlign="middle";
			document.getElementById("title").style.paddingLeft=new String(594-w) +'px';

			tbl.rows[0].cells[0].height=new String(h+6);
		}
		tbl.rows[0].bgColor="#2D2B27";
		b.src=images[n+first_image];
		tbl.style.display="block";
}
function muv(n) {
	var cur=document.images["m_"+n];
	if (clck==0) {
		opacity(cur, 0.5);
		hideObject("table");
		hideObject("contact");
		document.getElementById("label").height="70";
		if ((document.getElementById && !document.all) || window.opera) 
			document.getElementById("label").style.display="table-row";
   	else
			document.getElementById("label").style.display="block";
		set_text("title", "");
		set_text("number", "");
	} 
}
function showObject(id) {
	var tmp = document.getElementById(id);
	if (tmp.style.display=="none") {
		tmp.style.display="block";
	}
}
function hideObject(id) {
	var tmp = document.getElementById(id);
	if ((tmp.style.display=="") || (tmp.style.display=="block")) {
		tmp.style.display="none";
	}	
}
	
function cleanup() {
	first_image=0;
	document.images["big"].src=blank.src;
	set_text("title", "");
	set_text("number", "");
	var m = 8;
	if ((thumbnails!=null) && (m>count)) m=count;
	thumbnails=new Array();
	titles=new Array();
	images=new Array();
	var name, tmp;
	for (i=0;i<m;i++) {
		name = "m_"+i;
		tmp="t_"+i;
		document.getElementById(tmp).style.backgroundColor="";
		document.images[name].src="";
		document.images[name].style.display="none";
	}
}
function pre() {
		window.moveTo(0,0)
		if(document.all)
			window.resizeTo(screen.availWidth, screen.availHeight);
		else if(document.layers) {
			window.outerWidth = screen.availWidth;
			window.outerHeight = screen.availHeight
  		}
		var z=screen.Height/840;
		if (screen.Height>1024)
			z=1;
		return z;
		
}
function set_text(id, content) {
	document.getElementById(id).innerHTML=content;
}
function opacity(obj, value) {
	if (obj.filters) {
		obj.filters.alpha.opacity= value*100;
	}
	else {
		obj.style.MozOpacity=value;
	}
}

function clicked(n) {
	clck=n;
}

function about() {
//	if (!readyState)
		//return;
	hideObject("contact");
	var frame= document.getElementById("about");
	var tbl = document.getElementById("table");
	set_text("title", "");
	set_text("number", "");
	tbl.align="left";
	tbl.style.marginTop="75px";
	tbl.height="350";
	tbl.rows[0].cells[0].height="350";
	tbl.rows[0].cells[0].align="center";
	tbl.rows[0].bgColor="#2D2B27";
	tbl.style.display="block";
	document.images["big"].style.display="none";
	frame.style.display="block";
}
function contact() {
//	if (!readyState)
//		return;
	showObject("contact");
	hideObject("table");
}