function ResizeImage(imageid,limitWidth,limitHeight) 
{     
    var image = new Image(); 
    image.src = imageid.src; 
    if(image.width <= 0 && image.height <= 0) return; 
    if(image.width/image.height >= limitWidth/limitHeight) 
    { 
        if(image.width > limitWidth) 
        { 
            imageid.width = limitWidth; 
            imageid.height = (image.height*limitWidth)/image.width; 
        } 
    } 
    else if(image.height > limitHeight) 
    { 
            imageid.height = limitHeight; 
            imageid.width = (image.width*limitHeight)/image.height;      
    } 
    if (imageid.parentElement.tagName != "A") 
    { 
        imageid.onclick = function(){window.open(this.src);} 
        imageid.style.cursor = "hand"; 
    } 
} 
window.onload = InitImages; 
function InitImages() 
{ 
    var maxWidth = 580; 
    var maxHeight = 3000; 
    var imgs = document.getElementsByTagName("img"); 
    for(var i=0; i < imgs.length; i++) 
    { 
        var img = imgs[i]; 
        if(img.width>maxWidth||img.height>maxHeight) 
            ResizeImage(img, maxWidth, maxHeight); 
    } 
}
