$(document).ready(function(){
  arsoatopSetupScrollPage();
  arsoatopSetupWhatsnew();
  arsoatopSetupSlideImage();
  arsoatopSetupContents();
  arsoatopSetupStudio();
});

var scrollTimer =false;
/* ########## arsoatopSetupScrollPage ##########
  U: arsoatopSetupScrollPage()
  D: トップページのメイン画面とサブ画面スクロールのイベント設定。
  I: jquery-1.5.1.min.js
  I: jquery.scrollTo-min.js
  I: jquery.easing.1.3.js
  I: jquery.timer.js
  I: jquery.belatedPNG.min.js
  I: arsoatopRecalculationScrollPage()
*/
function arsoatopSetupScrollPage(){
  $('div#scrollbtnl').fadeOut(0);
  arsoatopRecalculationScrollPage();
  $('div#scrollbtnr img').fixPng();
  $('div#scrollbtnr a').css({cursor:'pointer'});
  $('div#scrollbtnl a').click(function(){
    $('div#index').scrollTo('0px', 1600, {'axis': 'x', 'easing':'easeOutExpo'});
    if ($.browser.msie) {
      $('div#scrollbtnl a').html('<img src="image/index_ph01_2.gif" alt="≪" width="100" height="100"/>');
    }
    $('div#scrollbtnl').fadeOut(300);
    $('div#scrollbtnr').fadeIn(300, 'linear', function(){
      if ($.browser.msie) {
        $('div#scrollbtnr a').html('<img src="image/index_ph01_1.png" alt="≫" width="100" height="100"/>');
        $('div#scrollbtnr img').fixPng();
      }
    });
  });
  $('div#scrollbtnr a').click(function(){
    $('div#index').scrollTo('100%', 1600, {'axis': 'x', 'easing':'easeOutExpo'});
    if ($.browser.msie) {
      $('div#scrollbtnr a').html('<img src="image/index_ph01_1.gif" alt="≫" width="100" height="100"/>');
    }
    $('div#scrollbtnr').fadeOut(300);
    $('div#scrollbtnl').fadeIn(300, 'linear', function(){
      if ($.browser.msie) {
        $('div#scrollbtnl a').html('<img src="image/index_ph01_2.png" alt="≪" width="100" height="100"/>');
        $('div#scrollbtnl img').fixPng();
      }
    });
  });
  $(window).resize(function(){
    if(scrollTimer===false){
      scrollTimer = $.timer(100,function(){
        arsoatopRecalculationScrollPage();
        scrollTimer.stop();
        scrollTimer =false;
      });
    }else{
      scrollTimer.reset(100);
    }
  });
}

/* ########## arsoatopRecalculationScrollPage ##########
  U: arsoatopRecalculationScrollPage()
  D: トップページのメイン画面とサブ画面スクロールの幅、位置の再計算。
  I: jquery-1.5.1.min.js
*/
function arsoatopRecalculationScrollPage(){
  var widthWindow = $(window).width();
  var widthContents = widthWindow -20;
  if(widthContents < 900) widthContents = 900;
  var widthContentsMargin = (widthContents -900) /2;
  if($.browser.msie && $.browser.version <7) {
    $('div#centeringcontainer').css({
      'left': (widthContentsMargin) +'px'
    });
  } else if($.browser.msie && $.browser.version <8) {
    if(widthContents > 900){
      $('body').css({
        'position': 'relative',
        'overflow': 'hidden'
      });
    } else {
      $('body').css({
        'overflow': 'visible'
      });
    }
  }
  $('div#index').css({
    'width': (widthContents) +'px',
    'left': (0-widthContentsMargin) +'px'
  });
  $('div#index div.maincontainer').css({
    'width': (1860 +(widthContentsMargin *2)) +'px'
  });
  $('div#index div.maincontainer div.mainpage').css({
    'left': (widthContentsMargin) +'px'
  });
  $('div#index div.maincontainer div.contentindex').css({
    'left': (930 +widthContentsMargin) +'px'
  });
  $('div#scrollbtnl').css({
    'left': (0-widthContentsMargin) +'px'
  });
  $('div#scrollbtnl a').css({cursor:'pointer'});
  $('div#scrollbtnr').css({
    'left': (widthContents -widthContentsMargin -100) +'px'
  });
}

var whatsnewCloseTimer =false;
/* ########## arsoatopSetupWhatsnew ##########
  U: arsoatopSetupWhatsnew()
  D: トップページWhat'sNewのイベント設定。
  I: jquery-1.5.1.min.js
  I: jquery.timer.js
  I: jquery.belatedPNG.min.js
  I: arsoatopSwitchWhatsnew()
*/
function arsoatopSetupWhatsnew(){
  if($.browser.msie && $.browser.version <7) $('div#whatsnew').fixPng();
  whatsnewCloseTimer = $.timer(3000, function(){
    arsoatopSwitchWhatsnew(true);
    whatsnewCloseTimer.stop();
  });
  $('div#whatsnew').click(function(){
    arsoatopSwitchWhatsnew(false);
  });
  $('div#whatsnew').css({cursor:'pointer'});
}

/* ########## arsoatopSwitchWhatsnew ##########
  U: arsoatopSwitchWhatsnew()
  D: トップページWhat'sNewの開閉。
  I: jquery-1.5.1.min.js
  I: jquery.easing.1.3.js
*/
function arsoatopSwitchWhatsnew(argForceClose){
  whatsnewCloseTimer.stop();
  if(argForceClose || $('div#whatsnew').css('left')=='0px'){
    $('div#whatsnew').animate({
      left: '-371px'
    }, 500, 'easeOutExpo');
  } else {
    $('div#whatsnew').animate({
      left: '0px'
    }, 500, 'easeOutExpo');
  }
}

var arraySlideImages = new Array(
  ['image/top_8.jpg', 'image/banner_8.jpg', 'http://nozomiboshi.arsoa.net/'],
  ['image/top_5.jpg', 'image/banner_5.jpg', 'product/skin/'],
  ['image/top_4.jpg', 'image/banner_4.jpg', 'https://www.arsoa.co.jp/question/sample'],
  ['image/top_3.jpg', 'image/banner_3.jpg', 'product/skin/queensilver/'],
  ['image/top_11.jpg', 'image/banner_11.jpg', 'whatsnew/news111205.html'],
  ['image/top_9.jpg', 'image/banner_9.jpg', 'http://www.arsoa.co.jp/map/']
);
var arraySlideBox = [[],[],[],[],[],[]];
var maxSlideImage = arraySlideImages.length;
var slideTimer =false;
var counterSlide =0;
/* ########## arsoatopSetupSlideImage ##########
  U: arsoatopSetupSlideImage()
  D: スライドイメージのCSS・イベント設定。
  I: jquery-1.5.1.min.js
  I: jquery.belatedPNG.min.js
  I: arsoatopMoveSlideImage()
*/
function arsoatopSetupSlideImage(){
  for(counter=0; counter<6; counter++){
    arraySlideBox[counter][0] =counter %maxSlideImage;
    arraySlideBox[counter][1] =counter*131 -121;
    $('div#slideshow div.selecter div.selecter0'+ (counter+1) +' a img').attr('src', arraySlideImages[arraySlideBox[counter][0]][1]);
    $('div#slideshow div.selecter div.selecter0'+ (counter+1)).css('left', arraySlideBox[counter][1]);
    counterSlide++;
  }
  var extFile =false;
  extFile =arraySlideImages[arraySlideBox[3][0]][0].match(/\.(html|jpg)/);
  if(extFile ===false) extFiles[1] ='null';
  switch(extFile[1]){
    case 'html':
      $.get(arraySlideImages[arraySlideBox[3][0]][0], function(argGetHtml){
        $('div#slideshow div.image').html(argGetHtml);
      });
      break;
    default:
      if(arraySlideImages[arraySlideBox[3][0]][2] =='#'){
        $('div#slideshow div.image').html('<img src="'+ arraySlideImages[arraySlideBox[3][0]][0] +'" alt="" width="663" height="468"/><br/>');
      } else {
        $('div#slideshow div.image').html('<a href="'+ arraySlideImages[arraySlideBox[3][0]][2] +'"><img src="'+ arraySlideImages[arraySlideBox[3][0]][0] +'" alt="" width="663" height="468"/></a><br/>');
      }
  }
  $('div#slideshow div.selecter div a').css({cursor:'pointer'});
  $('div#slideshow div.selecter div.selecter01 a').click(function(){
    arsoatopMoveSlideImage(0);
  });
  $('div#slideshow div.selecter div.selecter02 a').click(function(){
    arsoatopMoveSlideImage(-2);
  });
  $('div#slideshow div.selecter div.selecter03 a').click(function(){
    arsoatopMoveSlideImage(-1);
  });
  $('div#slideshow div.selecter div.selecter04 a').click(function(){
    arsoatopMoveSlideImage(0);
  });
  $('div#slideshow div.selecter div.selecter05 a').click(function(){
    arsoatopMoveSlideImage(1);
  });
  $('div#slideshow div.selecter div.selecter06 a').click(function(){
    arsoatopMoveSlideImage(2);
  });
  slideTimer = $.timer(7000,function(){
    arsoatopMoveSlideImage(1);
  });
  if($.browser.msie && $.browser.version <7){
    $('div#slideshow div.selecter').fixPng();
    $('div#slideshow div.eqancher a img').fixPng();
  }
}

/* ########## arsoatopMoveSlideImage ##########
  U: arsoatopMoveSlideImage()
  D: スライドイメージの画像変更。
  I: jquery-1.5.1.min.js
  I: jquery.easing.1.3.js
*/
function arsoatopMoveSlideImage(argMoveTo){
  $('div#slideshow div.selecter div.selecter01 a').unbind('click');
  $('div#slideshow div.selecter div.selecter02 a').unbind('click');
  $('div#slideshow div.selecter div.selecter03 a').unbind('click');
  $('div#slideshow div.selecter div.selecter04 a').unbind('click');
  $('div#slideshow div.selecter div.selecter05 a').unbind('click');
  $('div#slideshow div.selecter div.selecter06 a').unbind('click');
  if(argMoveTo>0){
    for(countMoveTo=0; countMoveTo<argMoveTo; countMoveTo++){
      var tmpModBox =counterSlide %6;
      arraySlideBox[tmpModBox][0] =counterSlide %maxSlideImage;
      $('div#slideshow div.selecter div.selecter0'+ (tmpModBox +1) +' a img').attr('src', arraySlideImages[arraySlideBox[tmpModBox][0]][1]);
      arraySlideBox[tmpModBox][1] =665;
      $('div#slideshow div.selecter div.selecter0'+ (tmpModBox +1)).animate({'left': 663}, 0, 'swing', function(){
        for(count =0; count <6; count++){
          arraySlideBox[count][1] -=131;
          $('div#slideshow div.selecter div.selecter0'+ (count +1)).animate({'left': arraySlideBox[count][1]}, 500, 'easeOutExpo');
        }
      });
      counterSlide +=1;
    }
    $('div#slideshow div.selecter div.selecter01 a').unbind('click');
    $('div#slideshow div.selecter div.selecter02 a').unbind('click');
    $('div#slideshow div.selecter div.selecter03 a').unbind('click');
    $('div#slideshow div.selecter div.selecter04 a').unbind('click');
    $('div#slideshow div.selecter div.selecter05 a').unbind('click');
    $('div#slideshow div.selecter div.selecter06 a').unbind('click');
    $('div#slideshow div.selecter div.selecter0'+ (tmpModBox %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(2);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+1) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(0);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+2) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(-2);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+3) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(-1);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+4) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(0);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+5) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(1);
    });
  }
  if(argMoveTo<0) {
    for(countMoveTo=0; countMoveTo>argMoveTo; countMoveTo--){
      var tmpCounterMod =counterSlide;
      while(tmpCounterMod <0){
        tmpCounterMod +=maxSlideImage;
      }
      var tmpModBox =tmpCounterMod %6;
      arraySlideBox[tmpModBox][0] =(tmpCounterMod -1) %maxSlideImage;
      $('div#slideshow div.selecter div.selecter0'+ (tmpModBox +1) +' a img').attr('src', arraySlideImages[arraySlideBox[tmpModBox][0]][1]);
      arraySlideBox[tmpModBox][1] =-121;
      $('div#slideshow div.selecter div.selecter0'+ (tmpModBox +1)).animate({'left': -121}, 0, 'swing', function(){
        for(count =0; count <6; count++){
          arraySlideBox[count][1] +=131;
          $('div#slideshow div.selecter div.selecter0'+ (count +1)).animate({'left': arraySlideBox[count][1]}, 500, 'easeOutExpo');
        }
      });
      counterSlide -=1;
    }
    $('div#slideshow div.selecter div.selecter01 a').unbind('click');
    $('div#slideshow div.selecter div.selecter02 a').unbind('click');
    $('div#slideshow div.selecter div.selecter03 a').unbind('click');
    $('div#slideshow div.selecter div.selecter04 a').unbind('click');
    $('div#slideshow div.selecter div.selecter05 a').unbind('click');
    $('div#slideshow div.selecter div.selecter06 a').unbind('click');
    $('div#slideshow div.selecter div.selecter0'+ (tmpModBox %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(-2);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+1) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(-1);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+2) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(0);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+3) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(1);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+4) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(2);
    });
    $('div#slideshow div.selecter div.selecter0'+ ((tmpModBox+5) %6 +1) +' a').click(function(){
      arsoatopMoveSlideImage(0);
    });
  }
  slideTimer.reset(7000);
  $('div#slideshow div.image').fadeOut(300, function(){
    var tmpModBox =counterSlide %6;
    var tmpCenterBox =(tmpModBox +3) %6;
    var extFile =false;
    extFile =arraySlideImages[arraySlideBox[tmpCenterBox][0]][0].match(/\.(html|jpg)/);
    if(extFile ===false) extFiles[1] ='null';
    switch(extFile[1]){
      case 'html':
        $.get(arraySlideImages[arraySlideBox[tmpCenterBox][0]][0], function(argGetHtml){
          $('div#slideshow div.image').html(argGetHtml);
        });
        break;
      default:
        if(arraySlideImages[arraySlideBox[tmpCenterBox][0]][2] =='#'){
          $('div#slideshow div.image').html('<img src="'+ arraySlideImages[arraySlideBox[tmpCenterBox][0]][0] +'" alt="" width="663" height="468"/><br/>');
        } else {
          $('div#slideshow div.image').html('<a href="'+ arraySlideImages[arraySlideBox[tmpCenterBox][0]][2] +'"><img src="'+ arraySlideImages[arraySlideBox[tmpCenterBox][0]][0] +'" alt="" width="663" height="468"/></a><br/>');
        }
    }
    $('div#slideshow div.image').fadeIn(500, function(){$('div#slideshow div.image').css('opacity', 1)});
  });
}

/* ########## arsoatopSetupContents ##########
  U: arsoatopSetupContents()
  D: おすすめコンテンツへイベントを設定する。
  I: jquery-1.5.1.min.js
  I: jquery.belatedPNG.min.js
  I: jquery.arsoacommon.js; arsoaImageSwap()
*/
function arsoatopSetupContents(){
  $('div#index div.pickup div.pickup01 a').hover(function(){
    arsoaImageSwap(this, 'image/index_ph08_1_on.png', 'アルソアクイーンシルバー', 203, 116);
  }, function(){
    arsoaImageSwap(this, 'image/index_ph08_1.png', 'アルソアクイーンシルバー', 203, 116);
  });
  $('div#index div.pickup div.pickup02 a').hover(function(){
    arsoaImageSwap(this, 'image/index_ph08_2_on.png', 'ご購入方法', 203, 116);
  }, function(){
    arsoaImageSwap(this, 'image/index_ph08_2.png', 'ご購入方法', 203, 116);
  });
  $('div#index div.pickup div.pickup03 a').hover(function(){
    arsoaImageSwap(this, 'image/index_ph08_3_on.png', 'アルソアのご紹介', 203, 116);
  }, function(){
    arsoaImageSwap(this, 'image/index_ph08_3.png', 'アルソアのご紹介', 203, 116);
  });
  $('div#index div.pickup div.pickup04 a').hover(function(){
    arsoaImageSwap(this, 'image/index_ph08_4_on.png', '製品情報', 203, 116);
  }, function(){
    arsoaImageSwap(this, 'image/index_ph08_4.png', '製品情報', 203, 116);
  });
  $('div#index div.pickup div.pickup05 a').hover(function(){
    arsoaImageSwap(this, 'image/index_ph08_5_on.png', 'よくあるご質問', 203, 116);
  }, function(){
    arsoaImageSwap(this, 'image/index_ph08_5.png', 'よくあるご質問', 203, 116);
  });
  $('div#index div.pickup div.pickup06 a').hover(function(){
    arsoaImageSwap(this, 'image/index_ph08_6_on.png', 'TVCM', 203, 116);
  }, function(){
    arsoaImageSwap(this, 'image/index_ph08_6.png', 'TVCM', 203, 116);
  });
  if($.browser.msie && $.browser.version <7) $('div#index div.pickup div[class^=pickup] a img').fixPng();
}

/* ########## arsoatopSetupStudio ##########
  U: arsoatopSetupStudio()
  D: AlsoaStudioのボタンを設定する。
  I: jquery-1.5.1.min.js
  I: jquery.easing.1.3.js
*/
var arsoatopStudioID =0;
function arsoatopSetupStudio(){
  $('div#studioselecter div.image01').fadeOut(0);
  $('div#studioselecter div.image02').fadeOut(0);
  $('div#studioselecter div.image03').fadeOut(0);
  $('div#studioselecter div.image04').fadeOut(0);
  $('div#studioselecter div.image05').fadeOut(0);
  $('div#studioselecter div.blocker').fadeOut(0);
  $('div#studioselecter div.hitarea01 a').hover(function(){
    arsoatopSwapStudio(1);
  }, function(){
    arsoatopSwapStudio(0);
  });
  $('div#studioselecter div.hitarea02 a').hover(function(){
    arsoatopSwapStudio(2);
  }, function(){
    arsoatopSwapStudio(0);
  });
  $('div#studioselecter div.hitarea03 a').hover(function(){
    arsoatopSwapStudio(3);
  }, function(){
    arsoatopSwapStudio(0);
  });
  $('div#studioselecter div.hitarea04 a').hover(function(){
    arsoatopSwapStudio(4);
  }, function(){
    arsoatopSwapStudio(0);
  });
  $('div#studioselecter div.hitarea05 a').hover(function(){
    arsoatopSwapStudio(5);
  }, function(){
    arsoatopSwapStudio(0);
  });
}
function arsoatopSwapStudio(argID){
  if(argID ==0){
    arsoatopStudioID =0;
    $('div#studioselecter div[class^=image]').queue([]);
    $('div#studioselecter div[class^=image]').stop();
    $('div#studioselecter div[class^=image]').fadeTo(300, 0);
  }else{
    arsoatopStudioID =argID;
    $('div#studioselecter div[class^=image]').queue([]);
    $('div#studioselecter div[class^=image]').stop();
    $('div#studioselecter div[class^=image][class!=image0'+ argID +']').fadeTo(300, 0);
    $('div#studioselecter div.image0'+ argID).fadeTo(750, 1);
  }
}

