/**
 * NetSuper用画像処理
 * @since 2010/06/01
 */
var max_width  = 150;
var max_height = 150;
var nsimg_max_width  = 100;
var nsimg_max_height = 100;

function resizeImgSmall(){
	max_width  = 64;
	max_height = 64;
	resizeImg();
}

function resizeImg() {

    // YMSAPI_MOD ネットスーパー３期対応 一括カート投入 START by KDL naito 2011/01/14
	try{
		for (i = 0; i < document.images.length; i++) {

			if ( ( document.images[i].className != "nsimg" )
					&& ( document.images[i].className != "nsimg_shop" )
					&& ( document.images[i].className != "ns_rcm_img" )
					&& ( document.images[i].className != "ns_cart_img" ) ) {
				continue;
			}

			if( !document.images[i].complete ){
				(function(arg){
					setTimeout(function(){resizeImgSingle(arg);}, 1000);
				})(document.images[i]);
				continue;
			}
			
			resizeImgSingle(document.images[i]);

		}

	} catch( e ){}
    // YMSAPI_MOD ネットスーパー３期対応 一括カート投入 END by KDL naito 2011/01/14

	return;
}

function resizeImgSingle( img ){

    // YMSAPI_MOD ネットスーパー３期対応 一括カート投入 START by KDL naito 2011/01/14
	try{
        var img_msx_width = max_width;
        var img_msx_height = max_height;

        if (img.className == "nsimg_shop") {
            img_msx_width = nsimg_max_width;
            img_msx_height = nsimg_max_height;
        }

        setNsImgVisible( img, true );

		if( !img.complete ){
			setNsNoImageSrc(img);
			img.width = img_msx_width ;
			img.height = img_msx_height ;
			return;
		}

		// 画像サイズ変更
		if (img.width > img.height) {
			var old_width = img.width;
			img.width = img_msx_width ;

			if (img.height < img_msx_height) {
				var margin = parseInt((img_msx_height - img.height)/2);
				img.style.marginTop    = margin + 'px';
				img.style.marginBottom = margin + 'px';
			}

		} else {
			var old_height = img.height;
			img.height = img_msx_height ;

			if (img.width < img_msx_width) {

				var margin = parseInt((img_msx_width - img.width)/2);
				img.style.marginLeft  = margin + 'px';
				img.style.marginRight = margin + 'px';
			}
		}

		setNsImgVisible( img, false );

		if ( ( img.className != "nsimg" )
					&& ( img.className != "nsimg_shop" )
					&& ( img.className != "ns_rcm_img" )
					&& ( img.className != "ns_cart_img" ) ) {
		}else{
			if ( img.className == "ns_cart_img" ){
				img.style.display = 'inline';
			} else {
				img.style.visibility = 'visible';
			}
		}
	}
	catch( e ){
		throw e;
	}
    // YMSAPI_MOD ネットスーパー３期対応 一括カート投入 END by KDL naito 2011/01/14

	return;
}

function setNsImgVisible( img, f ){
	if( img.className == "ns_cart_img" ){
		img.style.display =  f ? 'inline' :  'none';
	}
}

function setNsNoImageSrc( img ){
	img.src = "/img/l_non.jpg";
}

function setNsImageHidden(){
	jQuery(".nsimg").css("visibility", "hidden");
	jQuery(".nsimg_shop").css("visibility", "hidden");
	jQuery(".ns_rcm_img").css("visibility", "hidden");
	jQuery(".ns_cart_img").css("display", "none");
}

