// ============================================================
// フォーム関連
// 
// %update / 09.11.04
// 
// %use / jquery1.2.6
// ============================================================

// ------------------------------------------------------------
// ▼変数定義
// ------------------------------------------------------------
var lotateTime = 3;
var switchPicVars = {
  "resort"  : {"id" : null, "index" : 0, "areaid":"CtgMaResort"},
  "local"  : {"id" : null, "index" : 0, "areaid":"CtgMaLocal"},
  "dress"   : {"id" : null, "index" : 0, "areaid":"CtgMaDress"},
  "photo"   : {"id" : null, "index" : 0, "areaid":"CtgMaPhoto"}
}

function createRandomNum(){
	var picNum = new Array(-1, 0, 1, 2);
	var randomNum = Math.floor(Math.random()*picNum.length);
	return picNum[randomNum];
}

function createRandomNumLocal(){
	var picNum = new Array(-1, 0);
	var randomNum = Math.floor(Math.random()*picNum.length);
	return picNum[randomNum];
}

// ------------------------------------------------------------
// ▼
// ------------------------------------------------------------
// prototype.js と jquery の共存
if(! $jQ) { var $jQ = jQuery.noConflict(); }

$jQ(document).ready( function() {
  
	// ------------------
	// 【画像切替　初期化】
	// ------------------
  // リゾートウェディング
  //switchPicVars['resort'].id = setTimeout("switchPic('resort')", lotateTime * 1000);
  
  //初期表示設定
  switchPicVars['resort'].index = createRandomNum();
  switchPicVars['photo'].index = createRandomNum();
  switchPicVars['dress'].index = createRandomNum();
  switchPicVars['local'].index = createRandomNumLocal();
  switchPic('resort');
  switchPic('dress');
  switchPic('photo');
  switchPic('local');
  
  
	$jQ('#' + switchPicVars['resort'].areaid + ' .swUnit a').mouseover( function() {
    switchPicVars['resort'].index = $jQ("li", $jQ(this).parent().parent()).index($jQ(this).parent()) - 1;    
    switchPic('resort');
	} );  // mouseover()

  // 国内挙式・披露宴
  //switchPicVars['local'].id = setTimeout("switchPic('local')", lotateTime * 1000);
	$jQ('#' + switchPicVars['local'].areaid + ' .swUnit a').mouseover( function() {
    switchPicVars['local'].index = $jQ("li", $jQ(this).parent().parent()).index($jQ(this).parent()) - 1;
    switchPic('local');
	} );  // mouseover()
  
  // ドレス＆タキシード・和装
  //switchPicVars['dress'].id = setTimeout("switchPic('dress')", lotateTime * 1000);
	$jQ('#' + switchPicVars['dress'].areaid + ' .swUnit a').mouseover( function() {
    switchPicVars['dress'].index = $jQ("li", $jQ(this).parent().parent()).index($jQ(this).parent()) - 1;
    switchPic('dress');
	} );  // mouseover()

  // ウェディングフォト
  //switchPicVars['photo'].id = setTimeout("switchPic('photo')", lotateTime * 1000);
	$jQ('#' + switchPicVars['photo'].areaid + ' .swUnit a').mouseover( function() {
    switchPicVars['photo'].index = $jQ("li", $jQ(this).parent().parent()).index($jQ(this).parent()) - 1;
    switchPic('photo');
	} );  // mouseover()

} );  // ready()


// ------------------------------------------------------------
// ▼画像切替関数
// ------------------------------------------------------------
function switchPic(vstrType){
  
  //タイムアウトID初期化
  //clearTimeout(switchPicVars[vstrType].id);
  
  //インデックスカウントアップ
  switchPicVars[vstrType].index++;
  if (switchPicVars[vstrType].index > 3){
    switchPicVars[vstrType].index = 0;
  }

	// オブジェクト取得
  var myParam = switchPicVars[vstrType]
  var lindex_jq = myParam.index;                              // タブインデックス
  var mainPic_jq = $jQ("#" + myParam.areaid + " .picUnit");   // メイン画像エリア
  var linkPic_jq = $jQ("#" + myParam.areaid + " .swUnit");    // アンカーエリア
  var this_jq = $jQ("a", linkPic_jq).eq(lindex_jq);           // 自オブジェクト
	var curLi_jq = this_jq.parent();                            // カレント<li>
  
	// カレントの切替え
	$jQ('img', linkPic_jq).attr('src', $jQ('img', linkPic_jq).attr('src').replace(/_on\.(jpg|gif|png)$/, '.$1'));
	$jQ('img', this_jq).attr('src', $jQ('img', linkPic_jq).attr('src').replace(/\.(jpg|gif|png)$/, '_on.$1'));

  // メイン画像表示切替
	$jQ('div', mainPic_jq).addClass('hide');
  $jQ('div', mainPic_jq).eq(lindex_jq).removeClass('hide');

  //再起処理
  //switchPicVars[vstrType].id = setTimeout("switchPic('" + vstrType + "')", lotateTime * 1000);
}

