/**
 *
 * IE specific initial evaluation.
 *
 */

/** Initialization */
$j("document").ready(function() {
    var version = $j.browser.version
    if($j.browser.msie) {
        if(version < 6.0) {
            for_ie_under_6();
        } 
        if(6.0 <= version && version < 7.0) {
            for_ie6();
        } else if(7.0 <= version && version < 8.0) {
            for_ie7();
        } else {
            for_ie_over_7();    
        }
    }
});


var show_images = function() {
    for (i in images_to_resize) {
        $j(images_to_resize[i].selector).show();
    }
}

var images_to_resize = [
    // thumb nails used in lists and  featured/latest boxes.
    { selector: ".thumb_001", width: 100, height: 85 },
    { selector: ".thumb_002", width: 80, height: 60 },
    { selector: ".thumb_003", width: 80, height: 105 },

    // Images showed for each item's detail page.
    { selector: ".item_detail", width: 300, height: 180 },

    // company's logos.
    { selector: "#content_right .company_header img", width: 640, height: 9999 },
    { selector: ".company_logo", width: 300, height: 9999 },
    { selector: ".free_company_logo", width: 300, height: 9999 },

    // featured items under premium company's mypage.
    { selector: ".border_leftred img", width: 200, height: 110 }, 

    // map image used for event detail.
    { selector: ".place_image_url", width: 500, height: 500},

    // detail present.
    { selector: ".present_detail", width: 200, height: 110}
]


var for_ie_under_6 = function() {}
var for_ie6 = function() { resize_images(); }
var for_ie7 = function() {}
var for_ie_over_7 = function() {}


var resize_images = function()
{
    for (idx in images_to_resize) {
        param = images_to_resize[idx];
        resize_an_image(param.selector, param.width, param.height);
    }
}

var resize_an_image = function(selector, max_width, max_height)
{
    $j(selector).each(function(i, img_elem) {
        img_obj = new Image();
        img_obj.src = img_elem.src;
        if(max_width < img_obj.width || max_height < img_obj.height) {
            width_ratio = max_width / img_obj.width;
            height_ratio = max_height / img_obj.height;
            if(width_ratio < height_ratio) {
                multiplier = width_ratio;
            } else {
                multiplier = height_ratio;
            }
            if(img_elem.width < img_elem.height) {
                img_elem.height = img_elem.height * multiplier;
            } else {
                img_elem.width = img_elem.width * multiplier;
            }
        }
    });
}
