// rollover
$(function () {
  $('img:not(a.rollover img,.mainBlock h4 img),input[type=image]').each(function () {
    var ofSrc = $(this).attr('src');
    var ovSrc = ofSrc.replace('_off.', '_on.');
    $(this).hover(function () {
      $(this).attr('src', ovSrc);
    }, function () {
      $(this).attr('src', ofSrc);
    });
    $(window).unload(function () {
      $(this).attr('src', ofSrc);
    });
  });
});

//rollover for index
$(function () {
  $('a.rollover').each(function () {
    var ofSrc = $(this).children('img').attr('src');
    var ovSrc = ofSrc.replace('_off.', '_on.');
    $(this).hover(function () {
      $(this).children('img').attr('src', ovSrc);
    }, function () {
      $(this).children('img').attr('src', ofSrc);
    });
    $(window).unload(function () {
      $(this).children('img').attr('src', ofSrc);
    });
  });
});


// focus for index
$(function () {
    $("#campaignWord").focus(function () {
        $("#ImageErr").fadeOut(500);
        if (this.value == "キャンペーンコード、またはアクセスワードをご入力ください。") {
            $(this).val("").css("color", "#221815");
        }
    });
    $("#campaignWord").blur(function () {
        $("#ImageErr").fadeOut(500);
        if (this.value == "") {
            $(this).val("キャンペーンコード、またはアクセスワードをご入力ください。").css("color", "#bfc0c0");
        }
    });
    // keydown for index
    $("#campaignWord").keydown(function(){
        $("#ImageErr").fadeOut(500);
    });
});

// focus for index and knowledgebank
$(function(){
  $("#knowledgeWord").focus(function(){
    if(this.value == "調べたい経済用語を入力してください。"){
      $(this).val("").css("color","#221815");
    }
  });
  $("#knowledgeWord").blur(function(){
    if(this.value == ""){
      $(this).val("調べたい経済用語を入力してください。").css("color","#bfc0c0");
    }
  });
});


// focus for koudoku
$(function(){
  $("#code").focus(function(){
    if(this.value == "入力後、下のお申し込みボタンをクリック"){
      $(this).val("").css("color","#9fa0a0");
    }
  });
  $("#code").blur(function(){
    if(this.value == ""){
      $(this).val("入力後、下のお申し込みボタンをクリック").css("color","#9fa0a0");
    }
  });
});



// popup for index
$(function() {
  $(".popup").click(function(){
    window.open(this.href, "WindowName","width=630,height=630,resizable=yes,scrollbars=yes");
    return false;
  });
});

//map for overseas
function setArea(area) {
  document.getElementById('mapImg').src = '../../overseas/images/' + area;
}
function restoreMap() {
  document.getElementById('mapImg').src = '../../overseas/images/idx_bg01.gif';
}


// syoukai toggle（5つの日経の開閉動作）

$(document).ready(function() {
  $('div.mainBlock:eq(0)> div.detailBlock').hide();
  $('div.mainBlock:eq(0)> h4').click(function() {
    $(this).next().slideToggle('slow');
    var thisImg = $('img',this);
    if (thisImg.hasClass('accCurrent')) {
      thisImg.attr('src',thisImg.attr('src').replace('_active','_on'));
      thisImg.removeClass('accCurrent');
    } else {
      thisImg.attr('src',thisImg.attr('src').replace('_on','_active'));
      thisImg.addClass('accCurrent');
    }
  });
  //閉じている状態でのロールオーバー
  $('div.mainBlock:eq(0)> h4>img').hover(function() {
    var ofSrc = $(this).attr('src');
    var ovSrc = ofSrc.replace('_off.', '_on.');
    if (! $(this).hasClass('accCurrent')) {
      $(this).attr('src', ovSrc);
    }},
                                         function() {
    var ofSrc = $(this).attr('src');
    var ovSrc = ofSrc.replace('_on.', '_off.');
    if (! $(this).hasClass('accCurrent')) {
      $(this).attr('src', ovSrc);
    }
  });
  //閉じるボタンの挙動
  $('div.mainBlock:eq(0) .closebtn').click(function(){
    $(this).parent().slideToggle('slow');
    var parent = $(this).parent();
    var title = parent.prev('h4');
    var thisImg = $('img',title);
				var targetOffset = $(title).offset().top;
				$('html,body').animate({scrollTop: targetOffset}, "slow");
    if (thisImg.hasClass('accCurrent')) {
      thisImg.attr('src',thisImg.attr('src').replace('_active','_off'));
      thisImg.removeClass('accCurrent');
    } else {
      thisImg.attr('src',thisImg.attr('src').replace('_on','_active'));
      thisImg.addClass('accCurrent');
    }
  });
});


// popup for syoukai
$(function() {
  $(".popSyoukai").click(function(){
    window.open(this.href, "WindowName","width=666,height=670,resizable=yes,scrollbars=yes");
    return false;
  });
});
