nav_img = new Array();
nav_images = new Array("prev_img","next_img");
var curent_image = 0;
var curent_array = 1;
for(i=0;i<2;i++)
{	nav_img[i] = new Array()
	nav_img[i][0] = new Image();
	nav_img[i][0].src = "resources/img/" + nav_images[i] + ".gif";
	nav_img[i][1] = new Image();
	nav_img[i][1].src = "resources/img/" + nav_images[i] + "_dis.gif";
}
nav_img[2] = new Image();
nav_img[2].src = "resources/img/wait.gif";

function hLightThumb(mode,id,locate,line)
{
	colors = Array();
	colors[0] = Array("","#589265");
	colors[1] = Array("","#004F00");
	objects = Array("m_img","p_img");

	if(line)
		s_line = 0;
	else
		s_line = 1;
	
	if(document.getElementById(objects[locate] + line + id))
		td_object = Array(document.getElementById(objects[locate] + line + id),document.getElementById(objects[locate] + s_line + id));
	else if(document.all[objects[locate] + line + id])
		td_object = Array(document.all[objects[locate] + line + id],document.all[objects[locate] + s_line + id]);
	else
		td_object = Array(false,false)
	
	if(td_object[0])
	{
		td_object[0].style.backgroundColor = colors[line][mode];
		td_object[1].style.backgroundColor = colors[s_line][mode];
	}
}

function keyHandler(key)
{
	if(key == 13 || key == 32 || key == 110)
		next_img(1,curent_array);
	if(key == 92 || key == 98 || key == 112)
		next_img(0,curent_array);
	if(key == 113)
		image_window.close();
}

function openImageWindow(t_id,array_id)
{
	this_img = ("" + thumbnails[array_id][0][t_id]).split("_");
	image_window = window.open("", "ImageWindow", "scrollbars=0, fullscreen=1");
	image_window.document.write("<html><head></head><body scroll='no' onkeypress='if(window.event){opener.keyHandler(window.event.keyCode)}else {opener.keyHandler(event.which)}' ondblclick='window.close()' bgcolor='#C0C0C0' marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' syle='overflow:auto'><table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td width='11' valign='top' bgcolor='#588760'><table border='0' cellpadding='0' cellspacing='2'><tr><td><a href='javascript:window.close()'><img alt='Close window' src='resources/img/close.gif' border='0' height='11' width='11'></a></td></tr><tr><td><img src='resources/img/0.gif' height='7' width='11'></td></tr><tr><td><a href='javascript:opener.next_img(1," + array_id + ")'><img name='bimg1' alt='Next photo' src='resources/img/next_img.gif' border='0' height='11' width='11'></a></td></tr><tr><td><a href='javascript:opener.next_img(0," + array_id + ")'><img name='bimg0' alt='Previous photo' src='resources/img/prev_img.gif' border='0' height='11' width='11'></a></td></tr></table></td><td width='100%' valign='middle' rowspan='2' align='center'><img name='main_img' src='show_image.php?pid=" + this_img[0] + "' border='0' width='" + this_img[1] + "' height='" + this_img[2] + "' alt='" + thumbnails[array_id][1][t_id] + "'></td></tr><tr><td valign='bottom' bgcolor='#588760'><table border='0' cellpadding='0' cellspacing='2'><tr><td bgcolor='#ffffff'><img name='#ffffff' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#e0e0e0'><img name='#e0e0e0' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#c0c0c0'><img name='#c0c0c0' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#a0a0a0'><img name='#a0a0a0' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#808080'><img name='#808080' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#606060'><img name='#606060' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#404040'><img name='#404040' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#202020'><img name='#202020' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr><tr><td bgcolor='#000000'><img name='#000000' onmouseover='document.bgColor = this.name' alt='Set background color' src='resources/img/0.gif' height='11' width='11'></td></tr></table></td></tr></table></body></html>");
	image_window.document.close();
	image_window.focus();
	curent_image = t_id;
	curent_array = array_id;
}

function next_img(step,array_id)
{
 	steps = new Array(-1,1);
	array_length = thumbnails[array_id][0].length;
	step_dir = steps[step];
	win_images = image_window.document.images;
	
	if((curent_image + step_dir) >= 0 && (curent_image + step_dir) < array_length)
	{
		curent_image = curent_image + step_dir
		this_img = ("" + thumbnails[array_id][0][curent_image]).split("_");
		win_images["main_img"].src = nav_img[2].src;
		image_to_show = new Image();
		image_to_show.src = "show_image.php?pid=" + this_img[0];
		win_images["main_img"].src = image_to_show.src;
		win_images["main_img"].width = this_img[1];
		win_images["main_img"].height = this_img[2];
		win_images["main_img"].alt = thumbnails[array_id][1][curent_image];
		win_images["bimg" + step].src = nav_img[step][0].src;
		win_images["bimg" + ((step+1)%2)].src = nav_img[((step+1)%2)][0].src;
	}
	else
		win_images["bimg" + step].src = nav_img[step][1].src;
}