﻿/* visual loation script ************************/

//初期設定
var speed = 2000;
var now=0;
var next=1;

$(function(){
	
	//メインビジュアル設定
	var array = [
		$("ul#title li").eq(0),
		$("ul#title li").eq(1),
		$("ul#title li").eq(2)	
	];
	
	for (var i = 0; i < array.length; i++) {
       $(array[i]).css("z-index", String(array.length-i));
    }
    
	array[now].css('display', 'block');
	
	
	//画像ローテーション
	$.timer(speed*2.5, function(timer){
		array[now].fadeOut(speed);
		array[next].fadeIn(speed);
		
		ClearNavi();
		vnavi[next].addClass("active");
		vnavi[next].children("img").attr("src", "img/tp01_btn_visual_active.gif");
		
		now += 1;
		next += 1;
		if(now==3){
			now = 0;
		}
		if(next==3){
			next = 0;
		}
		
	});
	
	
	//ALL CLEAR (MAIN VISUAL)
	function Clear(){
		for(var i = 0; i < array.length; i++){
			$(array[i]).css('display','none');
		}
	}
	
	//ALL CLEAR (NAVIGATION)
	function ClearNavi(target){
		for(var j = 0; j < vnavi.length; j++){
			$(vnavi[j]).removeClass();
			$(vnavi[j]).children("img").attr("src", "img/tp01_btn_visual_off.gif");
		}
		$(target).addClass("active");
		$(target).children("img").attr("src", "img/tp01_btn_visual_active.gif");
	}
	
	
	//切り替えナビゲーションの設定
	var vnavi = [
		$("ul#visunavi li").eq(0),
		$("ul#visunavi li").eq(1),
		$("ul#visunavi li").eq(2)
	];
	
	$(vnavi[0]).click(function(){
		Clear();
		array[0].css('display', 'block');
		now=0;
		next=1;
		ClearNavi($(this));
	});
		
	$(vnavi[1]).click(function(){
		Clear();
		array[1].css('display', 'block');
		now=1;
		next=2;
		ClearNavi($(this));
	});
		
	$(vnavi[2]).click(function(){
		Clear();
		array[2].css('display', 'block');
		now=2;
		next=0;
		ClearNavi($(this));
	});
	
});

$(function(){
	$target = $("ul#visunavi").children("li").children("img");
	$target.mouseover(function(){
		if(!$(this).parent().attr("class") && $(this).attr("src").indexOf("tp01_btn_visual_off.gif")>-1){
			$(this).attr("src", "img/tp01_btn_visual_active.gif");
		}
	});
});

$(function(){
	$target = $("ul#visunavi").children("li").children("img");
	$target.mouseout(function(){
		if(!$(this).parent().attr("class") && $(this).attr("src").indexOf("tp01_btn_visual_active.gif")>-1){
			$(this).attr("src", "img/tp01_btn_visual_off.gif");
		}
	});
});	

/***********************************************/

/* jquery.timer.js
 *
 *	jQuery Timer plugin v0.1
 *		Matt Schmidt [http://www.mattptr.net]
 *
 *	Licensed under the BSD License:
 *		http://mattptr.net/license/license.txt
 *
 */
 
 jQuery.timer = function (interval, callback)
 {
 /**
  *
  * timer() provides a cleaner way to handle intervals  
  *
  *	@usage
  * $.timer(interval, callback);
  *
  *
  * @example
  * $.timer(1000, function (timer) {
  * 	alert("hello");
  * 	timer.stop();
  * });
  * @desc Show an alert box after 1 second and stop
  * 
  * @example
  * var second = false;
  *	$.timer(1000, function (timer) {
  *		if (!second) {
  *			alert('First time!');
  *			second = true;
  *			timer.reset(3000);
  *		}
  *		else {
  *			alert('Second time');
  *			timer.stop();
  *		}
  *	});
  * @desc Show an alert box after 1 second and show another after 3 seconds
  *
  * 
  */

	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };