/*=================================================
 * 共通のJS
 *-------------------------------------------------
 * Version : 1.0.0
 * Make    : 2011/01/24
 * Update  : 2011/01/24
 * Admin   : Dai Kimura
 *-------------------------------------------------
 * Copyright 2011 VIVID WORKS All Rights Reserved.
 *===============================================*/

var timerId;
var scene = 1;

function topMovieStart() {
	switch(scene) {
		case 1:
			scene = 2;
			$('#topMovieBG1').fadeIn('slow');
			timerId = setTimeout('topMovieStart()', 2000);
			break;
		
		case 2:
			clearTimeout(timerId);
			scene = 3;
			$('#topMovieImage1').fadeIn('slow');
			timerId = setTimeout('topMovieStart()', 2000);
			break;
		
		case 3:
			clearTimeout(timerId);
			scene = 4;
			$('#topMovieImage2').fadeIn('slow');
			timerId = setTimeout('topMovieStart()', 2000);
			break;
		
		case 4:
			clearTimeout(timerId);
			scene = 5;
			$('#topMovieImage3').fadeIn('slow');
			timerId = setTimeout('topMovieStart()', 2000);
			break;
		
		case 5:
			clearTimeout(timerId);
			scene = 6;
			$('#topMovieImage4').fadeIn('slow');
			timerId = setTimeout('topMovieStart()', 4000);
			break;
		
		case 6:
			clearTimeout(timerId);
			scene = 7;
			$('#topMovieImage1').fadeOut();
			$('#topMovieImage2').fadeOut();
			$('#topMovieImage3').fadeOut();
			$('#topMovieImage4').fadeOut();
			timerId = setTimeout('topMovieStart()', 1000);
			break;
		
		case 7:
			clearTimeout(timerId);
			scene = 8;
			$('#topMovieText1').slideDown('slow');
			timerId = setTimeout('topMovieStart()', 2000);
			break;
		
		case 8:
			clearTimeout(timerId);
			scene = 9;
			$('#topMovieText1').animate({
				top: '18px'
			}, 600);
			timerId = setTimeout('topMovieStart()', 100);
			break;
		
		case 9:
			clearTimeout(timerId);
			scene = 10;
			$('#topMovieText3').css('display', 'block');
			timerId = setTimeout('topMovieStart()', 100);
			break;
		
		case 10:
			clearTimeout(timerId);
			scene = 11;
			$('#topMovieText4').css('display', 'block');
			timerId = setTimeout('topMovieStart()', 100);
			break;
		
		case 11:
			clearTimeout(timerId);
			scene = 12;
			$('#topMovieText5').css('display', 'block');
			timerId = setTimeout('topMovieStart()', 100);
			break;
		
		case 12:
			clearTimeout(timerId);
			scene = 13;
			$('#topMovieText6').css('display', 'block');
			timerId = setTimeout('topMovieStart()', 100);
			break;
		
		case 13:
			clearTimeout(timerId);
			scene = 14;
			$('#topMovieImage5').fadeIn('slow');
			timerId = setTimeout('topMovieStart()', 1500);
			break;
		
		case 14:
			clearTimeout(timerId);
			scene = 15;
			$('#topMovieText2').css('display', 'block');
			$('#topMovieText2').animate({
				width: '223px',
				height: '61px',
				left: '355px',
				top: '47px'
			}, 300);
			timerId = setTimeout('topMovieStart()', 1);
			break;
		
		case 15:
			clearTimeout(timerId);
			scene = 16;
			//$('#topMovieRestart').css('display', 'inline-block');
			timerId = setTimeout('topMovieStart()', 1);
			break;
		
		case 16:
			clearTimeout(timerId);
			break;
	}
}

function topMovieRestart() {
	scene = 1;
	$('#topMovieBG1').css('display', 'none');
	$('#topMovieText1').css({'display': 'none', 'top': '95px'});
	$('#topMovieText2').css({'display': 'none', 'width': '2000px', 'height': '547px', 'left': '-535px', 'top': '-65px'});
	$('#topMovieText3').css('display', 'none');
	$('#topMovieText4').css('display', 'none');
	$('#topMovieText5').css('display', 'none');
	$('#topMovieText6').css('display', 'none');
	$('#topMovieImage5').css('display', 'none');
	$('#topMovieRestart').css('display', 'none');
	topMovieStart();
}

function formSubmit() {
	$('form').submit();
}

function formReset() {
	$('input[type=text]').each(function() { $(this).val(''); });
	$('input[type=radio]').each(function() { $(this).attr('checked', false); });
	$('input[type=checkbox]').each(function() { $(this).attr('checked', false); });
	$('select').each(function() { $(this).val(''); });
	$('textarea').each(function() { $(this).val(''); });
}

$(function() {
	// ロールオーバー初期化
	var image_cache = new Object();
	
	$(".swap").each(function(i) {
		var img = this.src;
		var dot = this.src.lastIndexOf('.');
		var img_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		
		image_cache[this.src] = new Image();
		image_cache[this.src].src = img_on;
		
		$(this).hover(
			function() { this.src = img_on; },
			function() { this.src = img; }
		);
	});
	
	// スムーズスクロール（対象：a,areaの#リンク）
	$('a[href^=#], area[href^=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body')
				.animate({scrollTop: targetOffset}, 500);
				return false;
			}
		}
	});
	
	// アンカーリンク判定
	if(location.href.indexOf("#") != -1) {
		var tmp = location.href.split("#");
		$('html,body').animate({scrollTop: $('#' + tmp[1]).offset().top}, 500);
	}
	
	if(navigator.userAgent.indexOf("MSIE") != -1) {
		$('img').each(function() {
			if($(this).attr('src').indexOf('.png') != -1) {
				$(this).css({'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + $(this).attr('src') + '", sizingMethod="scale");'});
			}
		});
	}
	
	try {
	} catch(e) {
	}
	
	topMovieStart();
});

