function pdg_format_num(num) 
{
	if(num < 10)
	{
		return "0" + num;
	}
	return num;
}


function pdg_get_pic_name(img_num)
{
	return pdg_format_num(img_num) + '_' + gallery + '.jpg';
}

function pdg_get_img_path(img_num)
{
	var img_path = gallery + '_images/' + pdg_get_pic_name(img_num);
	//alert("img_path = " + img_path);
	return img_path;
}

function pdg_hide(id)
{
	var obj = document.getElementById(id);
	obj.style.visibility = "hidden";
}

function pdg_show(id)
{
	var obj = document.getElementById(id);
	obj.style.visibility = "visible";
}

function pdg_find(t)
{
	return document.getElementById(t);
}

function pdg_preload_img(num)
{
	var img = new Image();
	img.src = pdg_get_img_path(num);
}

function pdg_toggle_arrows() 
{
	if(cur_img > 1)
	{
		pdg_show("arrow_left");
		// preload next image
		pdg_preload_img(cur_img+1);
	}
	else {
		pdg_hide("arrow_left");
	}
	if(cur_img < max_img)
	{
		pdg_show("arrow_right");
		// preload previous image
		pdg_preload_img(cur_img-1);
	}
	else {
		pdg_hide("arrow_right");
	}
}

function pdg_img(img_num) 
{
	// alert("img_num = " + img_num);
	pdg_find("main_image").src = pdg_get_img_path(img_num);
	cur_img = img_num;
	pdg_toggle_arrows();
}

function pdg_prev()
{
	if(cur_img > 1)
	{
		cur_img -= 1;
		pdg_img(cur_img);
	}
}

function pdg_next()
{	
	if(cur_img < max_img)
	{	
		cur_img += 1;
		pdg_img(cur_img);
	}
}

function pdg_link(gallery)
{
	document.location = "?gallery=" + gallery;
}

function pdg_link2(segment)
{
	document.location = "?gallery=" + gallery + "&segment=" + segment;
}


function pdg_init() 
{
	// set the active link to the "on" img
	var gallery_img = "img_" + gallery;
		
	var img = document.getElementById("img_"+gallery);
	
	if(img != null) 
	{
		img.src = "rollover_images/" + gallery + "_on.gif"; 
	} 

	var img_seg = document.getElementById("img_segment" + segment);
	if(img_seg != null)
    {	
		img_seg.src = "rollover_images/segment" + segment + "_on.gif";
	}

	// set the main image to the first image
	//pdg_find("main_image").src = pdg_get_img_path(1);
	
}
