document.write('<div id="capaFondoImagenAmpliada" style="position:absolute;top:0px;left:0px;width:400px;height:400px;visibility:hidden;background-color:black;opacity:0.7;filter:alpha(opacity=70);z-index:98" align="center" onClick="cerrarImagen();"></div>');
document.write('<div id="capaImagenAmpliada" style="position:absolute;top:0px;left:0px;width:400px;height:400px;visibility:hidden;z-index:99"><table width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><td height="100%" align="center" onClick="cerrarImagen();"><a href="javascript:cerrarImagen()"><img id="imagenAmpliadaProducto" border="0"></a></td></tr></table></div>');

function scroll_top(){
	if(window.pageYOffset){
		return window.pageYOffset;
	 }
	 else {
		return Math.max(top.document.body.scrollTop,top.document.documentElement.scrollTop);
	 }
}

function getViewportWidth() {
    var helper;
    if (null == (helper = document.getElementById('styleSwapHelper'))) {
        var helper = document.createElement('div');
        helper.style.position = 'absolute';
        helper.style.margin = '0';
        helper.style.padding = '0';
        helper.style.right = '0';
        helper.style.width = '10px';
        document.getElementsByTagName('body')[0].appendChild(helper);
    }
    return helper.offsetLeft + 10;
}

function ampliarImagen(imagen) {
	
	document.getElementById('imagenAmpliadaProducto').style.visibility='hidden';
	
	document.getElementById('capaImagenAmpliada').style.visibility='visible';
	document.getElementById('capaFondoImagenAmpliada').style.visibility='visible';
	
	var scrolleando = scroll_top();
	
	document.getElementById('capaImagenAmpliada').style.top = scrolleando;
	document.getElementById('capaFondoImagenAmpliada').style.top = 0;

	var anchoVentana = getViewportWidth();

	document.getElementById('imagenAmpliadaProducto').src=imagen;
	document.getElementById('imagenAmpliadaProducto').style.visibility='visible';

	var pageWidth=0;
	var pageHeight=0;
	
	if( window.innerHeight && window.scrollMaxY ) { // Firefox
		pageWidth = window.innerWidth + window.scrollMaxX;
		pageHeight = window.innerHeight + window.scrollMaxY;
	}
	else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
	{
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	}
	else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	{ 
		pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
		pageHeight = document.body.offsetHeight + document.body.offsetTop; 
	}

	var anchoImagen = document.getElementById('imagenAmpliadaProducto').width;
	if (anchoImagen > pageWidth) {
		document.getElementById('capaImagenAmpliada').style.width = anchoImagen;
		document.getElementById('capaFondoImagenAmpliada').style.width = anchoImagen;
	} else {
		document.getElementById('capaImagenAmpliada').style.width = pageWidth;
		document.getElementById('capaFondoImagenAmpliada').style.width = pageWidth;
	}
	document.getElementById('capaImagenAmpliada').style.height = window.document.body.clientHeight;
	document.getElementById('capaFondoImagenAmpliada').style.height = pageHeight;

}

function cerrarImagen() {
	document.getElementById('capaImagenAmpliada').style.visibility='hidden';
	document.getElementById('capaFondoImagenAmpliada').style.visibility='hidden';
	document.getElementById('imagenAmpliadaProducto').style.visibility='hidden';
	document.getElementById('capaImagenAmpliada').style.width = 0;
	document.getElementById('capaFondoImagenAmpliada').style.width = 0;
	document.getElementById('imagenAmpliadaProducto').src='/img/cargando.gif';
}
