/*
 *index_fスライド
 */

  //*** windowで保持 ***
  var WP_PS="wp";//wpかps
  var num=1;
  //*** ************ ***
  //var zero="";//00か0
  function retZero(){
    if(0<num && num<10){
      var zero="00";
    }else if(num>=10 && num<=50){
      var zero="0";
    }
    return zero;
  }
  var dispImg=WP_PS+retZero()+num;//wp001とか

  /*20091209*/
  function chk_1or50(){
    //20091209追加
    (num==50)?getElm("next").style.display="none":getElm("next").style.display="block";
    //20091209追加
    (num==1)?getElm("prev").style.display="none":getElm("prev").style.display="block";
  }

//jQ
$(function(){//alert($(this).attr("id"));
  //$("#thumbnail").fadeOut("fast");

  //chk_1or50();//初期設定ok

  /*画像入れ替え部関数*/
  function changeImage(){//alert($(this).attr("id"));//ok
    //$("#loading").remove();
    //thumbURL = $(this).attr("src");
    //imgURL = thumbURL.replace("/s_","/b_");//
//        if(num>=2 && num<=50){
//          ($(this).attr("id")=="next")?num++:num--;
//        }

    dispImg=WP_PS+retZero()+num;//alert(dispImg)
    imgURL =(WP_PS=="wp")?"flash_img/ph_kabekake/"+WP_PS+retZero()+num+".jpg":"flash_img/ph_takujou/"+WP_PS+retZero()+num+".jpg";//alert(imgURL);

    var image = new Image();
    image.imgURL;
    //$("#imgbox").append('<div id="loading" style="position:absolute;top:0;left:0;z-index:100;"><img src="./img/download.gif" /></div>');
    $("#bigimg").fadeOut(
        "300",//slow
        function() {
          $("#bigimg").attr("src", imgURL);
          $("#bigimg").load(function () {
            $("#bigimg").fadeIn(300);//2000
            //$("#loading").animate({opacity:0}, 800, "linear");
          });

        }
    );
    //chk_1or50();//xxx
  }



  //next
	//$("#menu img").click(function(){
  $("#menu2 a#next").click(function(){//alert($(this).attr("id"));//ok

		//$("#loading").remove();
		//thumbURL = $(this).attr("src");
		//imgURL = thumbURL.replace("/s_","/b_");//
    if(num>=1 && num<=49){
      ($(this).attr("id")=="next")?num++:num--;
    }


    dispImg=WP_PS+retZero()+num;//alert(dispImg)
    imgURL =(WP_PS=="wp")?"flash_img/ph_kabekake/"+WP_PS+retZero()+num+".jpg":"flash_img/ph_takujou/"+WP_PS+retZero()+num+".jpg";//alert(imgURL);

		var image = new Image();
		image.imgURL;
		//$("#imgbox").append('<div id="loading" style="position:absolute;top:0;left:0;z-index:100;"><img src="./img/download.gif" /></div>');
		$("#bigimg").fadeOut(
				"300",//slow
				function() {
					$("#bigimg").attr("src", imgURL);
					$("#bigimg").load(function () {
						$("#bigimg").fadeIn(300);//2000
						//$("#loading").animate({opacity:0}, 800, "linear");
					});
				}
		);
    chk_1or50();//ok
	});

  //クリックで商品ページへ
  $("#bigimg").click(function(){
    var gaiyouURL =(WP_PS=="wp")?"kabekake/hangercalendar/"+WP_PS+retZero()+num+".html":"takujou/taku02/"+WP_PS+retZero()+num+".html";//alert(gaiyouURL);//ok
    document.location=gaiyouURL;
  });

  //prev
  $("#menu1 a#prev").click(function(){//alert($(this).attr("id"));//ok

		//$("#loading").remove();
		//thumbURL = $(this).attr("src");
		//imgURL = thumbURL.replace("/s_","/b_");//
    if(num>=2 && num<=50){
      ($(this).attr("id")=="next")?num++:num--;
    }
    

    dispImg=WP_PS+retZero()+num;//alert(dispImg)
    imgURL =(WP_PS=="wp")?"flash_img/ph_kabekake/"+WP_PS+retZero()+num+".jpg":"flash_img/ph_takujou/"+WP_PS+retZero()+num+".jpg";//alert(imgURL);

		var image = new Image();
		image.imgURL;
		//$("#imgbox").append('<div id="loading" style="position:absolute;top:0;left:0;z-index:100;"><img src="./img/download.gif" /></div>');
		$("#bigimg").fadeOut(
				"300",//slow
				function() {
					$("#bigimg").attr("src", imgURL);
					$("#bigimg").load(function () {
						$("#bigimg").fadeIn(300);//2000
						//$("#loading").animate({opacity:0}, 800, "linear");
					});
				}
		);
    chk_1or50();//ok
	});

  //WP/PS切り替え
  $("#changeView").click(function(){//alert($("#changeView").val());
    if(WP_PS=="wp"){//WP→PS
      WP_PS="ps";
      //画像入れ替え部分の処理
      changeImage();//alert($("#changeView"));
      //$("#changeView").css("background", "url(./images/cmn/btn_chg_kabe.gif) no-repeat 0 0");
      $("#changeView").html("<div>→&nbsp;壁掛けタイプ</div>");

    }else{//PS→WP
      WP_PS="wp";
      //画像入れ替え部分の処理
      changeImage();
      //$("#changeView").css("background", "url(./images/cmn/btn_chg_taku.gif) no-repeat 0 0");
      $("#changeView").html("<div>→&nbsp;卓上タイプ</div>");
    }
  });

  //サムネイル表示
  $("#dispThmbnail").click(function(){//alert(WP_PS)
    //$("#Container").height("1200px");//Footerがおかしくなるので調整
		$("#bg").fadeOut(
				"500",//slow
				function() {
          if(WP_PS=="wp"){
            //$("#thumbnail").style.display="block";
            $("#thumbnail_wp").fadeIn(500);//2000
          }else{
            //$("#thumbnail").style.display="block";
            $("#thumbnail_ps").fadeIn(500);//2000
          }
				}
		);
  });

  //サムネイルでの動作
  $("img.ph_thumbnail").click(function(){
    //$("#Container").height("650px");//Footerがおかしくなるので調整
    //srcがkabekake/hangercalendar/images/wp001.pngとか
//    alert($(this).attr("src"));
//    alert($(this).attr("src").substring($(this).attr("src").length-7, $(this).attr("src").length-4));
    var tmp_num=$(this).attr("src").substring($(this).attr("src").length-7, $(this).attr("src").length-4);//alert("tmp_num : "+tmp_num);
//    tmp_num=tmp_num.replace("0", "");
//    tmp_num=tmp_num.replace("0", "");
      //tmp_num：001とか
      if(tmp_num.charAt(0)=="0"){//alert("0が先頭にあれば削除");//0が先頭にあれば削除
        tmp_num= tmp_num.substring(1, tmp_num.length);//2番目からを取り出す
      }
      if(tmp_num.charAt(0)=="0"){//0が先頭にあれば削除
        tmp_num= tmp_num.substring(1, tmp_num.length);//2番目からを取り出す
      }
//    alert(tmp_num);//ok
    num=tmp_num;//グローバルに保持
//alert("保持されたnum : "+num);
    dispImg=WP_PS+retZero()+num;//alert(dispImg)
    imgURL =(WP_PS=="wp")?"flash_img/ph_kabekake/"+WP_PS+retZero()+num+".jpg":"flash_img/ph_takujou/"+WP_PS+retZero()+num+".jpg";//alert("画像切り替え時の imgURL : "+imgURL);
    $("#bigimg").attr("src", imgURL);
    if(WP_PS=="wp"){
      $("#thumbnail_wp").fadeOut(
        "500",//slow
        function() {
          //$("#thumbnail").style.display="block";
          $("#bg").fadeIn(500);//2000
        }
      );
    }else if(WP_PS=="ps"){
      $("#thumbnail_ps").fadeOut(
        "500",//slow
        function() {
          //$("#thumbnail").style.display="block";
          $("#bg").fadeIn(500);//2000
        }
      );
    }

    chk_1or50();

  });

});