﻿
function autofitImages()
{
    $$('img').each(function(item){
        if(item.get('maxw')&&item.get('maxw')>0)
        {
            var maxViewImageW=item.get('maxw');
            var maxViewImageH=item.get('maxh');            
            var img = new Image();
            img.src = item.get('src');                
            var imgw=img.width;
            var imgh=img.height;              
            imgw=parseInt(imgw);
            imgh=parseInt(imgh);
            if(imgw>maxViewImageW){           
                imgh=maxViewImageW*imgh/imgw;
                imgw=maxViewImageW;
            }                
            if(imgh>maxViewImageH){               
                imgw=maxViewImageH*imgw/imgh;
                imgh=maxViewImageH;
            }                
            imgw=parseInt(imgw);
            imgh=parseInt(imgh);
            if(imgh*imgw>0){
                item.setStyle('height',imgh);
                item.setStyle('width',imgw);
            }
        }
    });
}


window.addEvent("domready",function()
{
//    previewImages();
//    var arr = new Array();
//    $$('img[maxw!=null]').each(function(item)
//    {
//        arr.include(item.get("src"));
//    });

//    var myImages = new Asset.images(arr, {
//        onComplete: function(){
//            autofitImages();
//        }
//    });
});
    
window.addEvent('load', function() {
    autofitImages();
});
    
