
$(document).ready(function() {

$(".product-th").click(
                                                         
    function(){
        //以下、クリック時のアクション定義
        var srcstr = $(this).attr("src"); //scrを取得
        //var srcstr = srcstr.replace("68","600") // 幅指定サイズの68を600に置換
        var srcstr = '<img src="'+srcstr+'" alt="" />'

        $("#productpicinner img").replaceWith(srcstr);//画像部分のhtmlを置換
        //window.alert(srcstr);
        $("#productpicinner img").hide();//一旦隠して
        $("#productpicinner img").fadeIn("slow");//フェードイン
        
        //元々選択されていたサムネールの枠色を外す
        //$(".thumblist li img").removeClass("sel");
        //押されたものに枠色を設定する
        //$(this).addClass("sel");
	}
);


//画像センタリング
//$("#productpic img").center();

//プロフィール設定
var pimg = $("#option .pimg").html();
pimg = '<img src="'+pimg+'"/ >';
var ptxt = $("#option .ptxt").html();

//console.log(pimg);

$("#option .pimg").empty();
$("#option .ptxt").empty();

$("#profileinner").prepend(pimg);
$("#profiletext").append(ptxt);


//カテゴリー画像
var cbid= $.query.get('cbid');
//console.log(cbid);
var catimg = "http://img15.shop-pro.jp/PA01087/910/category/"+cbid+"_0.jpg"
var catimgtag = '<img src="'+catimg+'" />';
//console.log(catimgtag);

$("#categoryinner h1").prepend(catimgtag);

//セール商品

var salefalg = $("#itemdetail tr:eq(0) th").eq(0).text();
if(salefalg == "定価"){

	var proper = $("#itemdetail tr:eq(0) td").eq(0).text();
	var price = $("#itemdetail tr:eq(1) td").eq(0).text();
	
	var pricestr = price
	
	var offper =  getoff(proper, price)
	
	$("#itemdetail tr:eq(0) td").eq(0).addClass("textred-line");
	$("#itemdetail tr:eq(0) td").eq(0).addClass("textred-line");
	$("#itemdetail tr:eq(1)").eq(0).addClass("textred");
	$("#itemdetail tr:eq(1) td").text(pricestr+" "+offper);
}
//console.log(offper);


//セール商品一覧処理
var gid= $.query.get('gid');
if(gid=="73697"){

	$("p.itemprice").addClass("textred");
	
	//カテゴリー画像
	//console.log(cbid);
	var catimg = "http://img15.shop-pro.jp/PA01087/910/category/g_"+gid+".gif"
	var catimgtag = '<img src="'+catimg+'" />';
	
	$("#categoryinner h1").prepend(catimgtag);
}


});


function getoff(a,b){
	a =  jQuery.trim(a);
	a =  a.replace(",","");
	a =  a.replace("円(税込)","");

	b =  jQuery.trim(b);
	b =  b.replace(",","");
	b =  b.replace("円(税込)","");
	
	
	return "["+Math.floor((a-b)/a*100)+"%OFF"+"]";
}
