//A few global vars
var zoom_pic = 0;
var selected_tab = 0;
var selected_menu = 0;

function activate_tab(id)
{
	var element = document.getElementById(id);
	element.src = tab_image_path + id + '_active.jpg';
}

function inactivate_tab(id)
{
	if(id != selected_tab)
	{
		var element = document.getElementById(id);
		if(element)
		{
			element.src = tab_image_path + id + '_inactive.jpg';
		}
	}
}

function switch_image(id_image)
{
	if(id_image)
	{
		selected_img = id_image;
		var obj = document.getElementById('ap_product_image');
		obj.style.backgroundImage = "url('" + site_url + "media.php?id_file=" + id_image + "&size=large')";
	}
}

function switch_iframe(id,id2,id3)
{
	selected_tab = id;
	inactivate_tab(id2);
	inactivate_tab(id3);
	var element = document.getElementById('ap_iframe_' + id);
	var text = element.innerHTML;
	var iframe = document.getElementById('ap_iframe');
	iframe.innerHTML = text;
}

function menu_expand(id,id_parent)
{
	var d = document.getElementById('submenu' + id);
	var dl = document.getElementById('link' + id);
	var dp = document.getElementById('menu' + id);
	//var id_parent = getqueryvar('id_parent');

	if(selected_menu == 0)
	{
		selected_menu = id_parent;
	}

	if(selected_menu != id)
	{
		menu_close(selected_menu);
	}

	if(d.style.display == 'none')
	{
		//alert('Opening #' + id);
		d.style.display = 'block';
		dl.className = 'active_expanded';
		dp.style.height = 'auto';
	}
	else
	{
		menu_close(id);
	}

	selected_menu = id;
}

function menu_close(id)
{
	if(id > 0)
	{
		//alert('Closing #' + id);
		var d = document.getElementById('submenu' + id);
		if(d)
		{
			var dl = document.getElementById('link' + id);
			var dp = document.getElementById('menu' + id);

			if(d.style.display != 'none')
			{
				d.style.display = 'none';
				dl.className = 'inactive_folded';
				dp.style.height = '20px';
			}
		}
		else
		{
			return true;
		}
	}
}

function product_zoom()
{
	window.open('zoom.php?id_image=' + selected_img ,'product_zoom','width=450,height=550,toolbar=no,menubar=no,resizable=no,location=no');
	return true;
}

function getqueryvar(variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");

	for(var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
			return pair[1];
		}
 	 }
}