/*----------------------------------------------------------------------------
 * FileName      : nophoto.js
 * LastUpdate    : 2010/12/21
 * Copyright     : マクリー株式会社
 * Email         : info@macly.com
 *
 * NoPhoto画像出力用Javascript
 *
 *
 *
 *
----------------------------------------------------------------------------*/
var obj = '';
var url = '';
var width = 0;
var height = 0;

$(".load_photo").ready(function () {
    $(".load_photo").each(function () {
        obj = $(this)[0];
        url = $(this).attr('src');
        width = $(this).attr('width');
        height = $(this).attr('height');
        
        check_image(obj, width, height, url);
    });
});

$(".normal_photo").ready(function () {
    $(".normal_photo").each(function () {
        obj = $(this)[0];
        url = $(this).attr('src');
        width = $(this).attr('width');
        height = $(this).attr('height');
        
        check_image(obj, width, height, url);
    });
});

function check_image(photo, base_width, base_height, url)
{
    var img = new Image();
        
    img.onload = function() {
        if(img.src != image_nophoto)
        {
            width = img.width;
            height = img.height;
           
            if( width / base_width < height / base_height )
            {
                photo.height = base_height;
                photo.width = width * base_height / height;
            }
            else
            {
                photo.width = base_width;
                photo.height = height * base_width / width;
            }
            
        }
    };
    img.onerror = function() {
        photo.src = image_nophoto;
        photo.height = base_height;
        photo.width = base_width;
    };
    img.src = url;
}
