var ampliaFoto_x = 0;
if(typeof(AmpliaFoto)=='undefined'){
    function AmpliaFoto(img){
        if(!img.length) return;
        var foto;
        var amplia = {
            ler : function(img){
              if((parseInt(foto.width,10)!=0)&&(parseInt(foto.height,10)!=0)){
              //if(foto.complete){
                amplia.mostrar_foto(img);
              }
              else{
                var intervalo=setTimeout(function(){amplia.ler(img);},50);
              }
            },

            mostrar_foto : function(img){
                var larg_max = screen.availWidth - 100;
                var alt_max  = screen.availHeight - 50;
                var larg     = foto.width+20;
                var alt      = foto.height+20;

                if(larg > larg_max)
                    larg = larg_max;
                if(alt > alt_max)
                    alt = alt_max;

                var string="resizable=yes, width="+larg+", height="+alt;
                if((larg == larg_max) || (alt == alt_max))
                    string = string + ", scrollbars=yes";

                var title = "Waz Hardware Store";
                var html  = "\
<html>\
<head>\
<title>"+title+"</title>\
</head>\
<body>\
<img src='"+img+"'>\
</body>\
<script type='text/javascript' src='../js/disableElement.js'></script>\
</html>\
";

                var janela = window.open("","",string);
                if(!janela){
                    alert('Para mostrar a imagem é necessário desbloquear popups deste site.')
                    return;
                }
                janela.document.write(html);
                janela.document.close();
            }

        };


        foto = new Image();
        foto.src=(img);
        if((parseInt(foto.width,10)!=0)&&(parseInt(foto.height,10)!=0)){
            amplia.ler(img);
        }
        else if(ampliaFoto_x < 10){
            ampliaFoto_x = ampliaFoto_x + 1;
            funcao="AmpliaFoto('"+img+"')";
            intervalo=setTimeout(funcao,500);
        }
    }
}
