// $Id: popup_image.js,v 1.4.2.1 2006/09/13 14:03:29 max Exp $
function popup_image(type, id, max_x, max_y, title, page, back,extra, excl) {

	max_x = parseInt(max_x);
	max_y = parseInt(max_y);

/*	if (!max_x)
		max_x = 150;
	else
		max_x += 25;*/

	max_x += 100;
	
	if (!max_y)
		max_y = 120;
	else
		max_y += 55;

	return window.open(xcart_web_dir+'/popup_image.php?type='+type+'&id='+id+'&title='+title+'&area='+current_area+'&back='+back+'&extra='+extra+'&excl='+excl+'&page='+page,'images','width='+max_x+',height='+max_y+',toolbar=no,scrollbars=yes,status=no,resizable=yes,menubar=no,location=no,direction=no');
}

function showDetailedImg(elm, id, back){

    if (back)
        var urlD = url_D_back[id];
    else
        var urlD = url_D[id];

	if (urlD == '') {
        return;
    }

    elm.style.cursor= "hand";
    elm.onmouseout = function () {
        hideDetailedImg(this);
    }
    var doc_width =  document.body.clientWidth - 30;
    var doc_height = document.body.clientHeight - 30;
	
	if (window.document.body.scrollTop!=0)
		var scrolltop=window.document.body.scrollTop;
	else
		var scrolltop=window.document.documentElement.scrollTop;

    var hint = window.document.createElement('span');
    hint.name = "hint_box";
    hint.id = "hint_id";
    hint.className = 'hint_box';
    hint.innerHTML = '<img src="'+urlD+'" width="'+detailed_img_width+'"><br /><center><h2></h2></center>';
    hint.style.visibility = "hidden";
	window.document.body.appendChild(hint);

    var hint_width = hint.offsetWidth;
    var hint_height = hint.offsetHeight;

    if (hint_width >= doc_width - 50) {
        hint_width = doc_width - 50;
        hint.style.width = hint_width;
        hint_width = hint.offsetWidth;
    }
    if (hint_height >= doc_height - 50) {
        hint_height = doc_height - 50;
        hint.style.height = hint_height;
        hint_height = hint.offsetHeight;
    }

    elm.xb_hint = hint;

    var left_offset = elm.offsetLeft;
    var top_offset = elm.offsetTop;
    var obj = elm;
    while ((obj = obj.offsetParent) != null)
 {
        left_offset += obj.offsetLeft;
        top_offset += obj.offsetTop;
    }

    left_offset -= window.document.body.scrollLeft;
    top_offset -= window.document.body.scrollTop;

if (left_offset + hint_width < doc_width) {
        hint.style.left = left_offset +window.document.body.scrollLeft + elm.offsetWidth + 'px';
    } else {
		hint.style.left=left_offset - hint_width - 10 + 'px';
    }
	hint.style.top = scrolltop +  'px';

	hint.style.width = hint_width;

    hint.style.visibility = "visible";
}

function hideDetailedImg(elm)  {
    if (elm.name == 'hint_box') {
        var hint = elm;
    } else {
        var hint = elm.xb_hint;
    }
	hint.style.display = "none";
    if (!hint || !hint.parentNode) {
        return;
    }
}
