var isIE = document.all ? true : false;
document.onmousemove = getMousePosition;
var _posX;
var _posY;
function getMousePosition(e) {
	var _x;
	var _y;
	if (!isIE) {
		_x = e.pageX;
		_y = e.pageY;
	}
	if (isIE) {
//		_x = event.clientX + document.body.scrollLeft;
//		_y = event.clientY + document.body.scrollTop;
		_x = event.clientX + document.documentElement.scrollLeft;
		_y = event.clientY + document.documentElement.scrollTop;
	}
	_posX = _x;
	_posY = _y;
	return true;
}

function set_popup_text(text) {
	if (text != null) {
	    var popUpText = document.getElementById('productPopUpText');
	    popUpText.innerHTML = text;
	}
}

function set_popup_image(image) {
	if (image != null) {
	    var popUpImage = document.getElementById('productPopUpImage');
	    popUpImage.src = image;
	}
}

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {
		el.style.display = 'block';
	}
	else {
		el.style.display = 'none';
	}
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('productPopUpBlanket');
	blanket.style.height = blanket_height + 'px';
}

function window_pos(popUpDivVar, width, height) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv.style.left = (window_width/2-300) + 'px';
	//popUpDiv.style.left = (_posX-0)  + 'px';

	popUpDiv.style.top = (_posY-height/2) + 'px';

	var newWidth = parseInt(width);
	if (newWidth < 500) {
		newWidth = 500;
	}
	popUpDiv.style.width = newWidth + 'px';
	popUpDiv.style.height = height + 'px';
}

function css_popup(baseURL, image, title, description, width, height) {
	set_popup_text(description);
	set_popup_image(baseURL + image);
	blanket_size('productPopUpDiv');
	window_pos('productPopUpDiv', width, height);
	toggle('productPopUpBlanket');
	toggle('productPopUpDiv');		
}

function window_popup(baseURL, image, title, description, width, height) {
	var w1 = window.open('', 'name', "directories=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,height=" + height + ",width=" + width);
	var t = w1.document;
	t.write('<html>');
	t.write('<head>');
	t.write('<style type=\"text/css\">');
	t.write('</style>');
	t.write('<title>' + title + '</title>');
	//t.write('<link rel="stylesheet" href="' + baseURL + '/wp-content/themes/theme850/style-popup.css">');
	t.write('</head>');
	t.write('<body>');
	t.write('<script type="text/javascript">self.focus()</script>');
	t.write('<p>' + description + '</p>');
	t.write('<img src=\"' + baseURL + image + '\"/>');
	t.write('</body></html>');
	t.close();
}

function do_popup(baseURL, image, title, description, w, h) {
	var width = 600;
	var height = 600;
	if (w != "" && h != "") {
		width = w;
		height = h;
	}
	window_popup(baseURL, image, title, description, width, height);
	//css_popup(baseURL, image, title, description, width, height);
}


