// Change when dest_div is triggered by target_div, open target
// at target_divs coordinates with the specified offsets
function SetPosXY(target_div, dest_div, dest_shim, x_offset, y_offset) 
{															
	var target = getAnchorPosition(target_div);
	document.getElementById(dest_div).style.left = target.x + x_offset;
	document.getElementById(dest_div).style.top = target.y + y_offset;	
	document.getElementById(dest_shim).style.left = target.x + x_offset;
	document.getElementById(dest_shim).style.top = target.y + y_offset;	
}

function DivSetVisible(div_name, shim_name, popup_class, state)
{
	var DivRef = document.getElementById(div_name);
	var IfrRef = document.getElementById(shim_name);
	
	if(state)
	{
		DivRef.style.display = "block";
		DivRef.className = popup_class;
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = "block";
	}
	else
	{
		DivRef.style.display = "none";
		IfrRef.style.display = "none";
	}
}

function set_div_focus(popup_name, new_focus, x, y, action) 
{ 
	var old_focus = document.getElementById('DIV_FOCUS').value;
	var active_div = document.getElementById('ACTIVE_DIV').value + '_popup_content';
	var popup_anchor = popup_name + '_popup_anchor';
	var popup_content = popup_name + '_popup_content';
	var popup_shim = popup_name + '_popup_shim';
	var popup_open = popup_name + '_popup_open';		
		
	if (new_focus != old_focus)	{	
		if (action == 'over') {	
			if ((new_focus == popup_anchor) || (new_focus == popup_content)) {
				DivSetVisible(popup_content, popup_shim, popup_open, true); 
				SetPosXY(popup_anchor, popup_content, popup_shim, x, y); 
				document.getElementById('ACTIVE_DIV').value = popup_name;
				
				if (popup_name == 'login') {
					if (document.getElementById('viewcart_popup_content') != null) {
						document.getElementById('viewcart_popup_content').style.display = "none";
						document.getElementById('viewcart_popup_shim').style.display = "none";	
					}
				}
				
				if (popup_name == 'viewcart') {
					if (document.getElementById('login_popup_content') != null) {
						document.getElementById('login_popup_content').style.display = "none";
						document.getElementById('login_popup_shim').style.display = "none";	
					}
				}
			}
			document.getElementById('DIV_FOCUS').value = new_focus;		
		}		
		
		if ((action == 'out') && active_div) {
			
			if (new_focus == 'main') {
				if ((old_focus == popup_anchor) || (old_focus == popup_content)) {
					DivSetVisible(active_div, popup_shim, popup_open, false);
				}
			}	
			
			if (new_focus == 'top') {
				if (active_div == 'login_popup_content') {
					if ((old_focus == popup_anchor) || (old_focus == popup_content)) {
						DivSetVisible(active_div, popup_shim, popup_open, false);
					}
				}
			}	
			
			document.getElementById('DIV_FOCUS').value = '';
			document.getElementById('ACTIVE_DIV').value = '';
		}			
	}			 
} 

function popup_flash_window(product_id) {
	var flash_path = "images/products/flash/" + product_id + "/" + product_id + "_flash_popup.php";
	new_window = window.open(flash_path, "FlashPics", "width=600,height=550");
	return false;
}