/*=================================================
 * 共通のJS
 *-------------------------------------------------
 * Version : 1.0.0
 * Make    : 2010/09/01
 * Update  : 2010/09/14
 * Admin   : Dai Kimura
 *-------------------------------------------------
 * Copyright 2010 VIVID WORKS All Rights Reserved.
 * Copyright 2010 THE-URI Studio All Rights Reserved.
 *===============================================*/

var timerId;
var scene = 0;
var topMovieStart = function() {
	switch(scene) {
		case 0:
			scene = 1;
			$('#index1').animate({opacity: 1}, 2000);
			timerId = setTimeout('topMovieStart()', 7000);
			break;
		
		case 1:
			clearTimeout(timerId);
			scene = 2;
			$('#index3').css({left: '1900px', opacity: 0});
			$('#index1').animate({left: '-950px', opacity: 0}, 2000);
			$('#index2').animate({left: '0px', opacity: 1}, 2000);
			$('#index3').animate({left: '950px'}, 2000);
			timerId = setTimeout('topMovieStart()', 7000);
			break;
		
		case 2:
			clearTimeout(timerId);
			scene = 3;
			$('#index1').css({left: '1900px', opacity: 0});
			$('#index1').animate({left: '950px'}, 2000);
			$('#index2').animate({left: '-950px', opacity: 0}, 2000);
			$('#index3').animate({left: '0px', opacity: 1}, 2000);
			timerId = setTimeout('topMovieStart()', 7000);
			break;
		
		case 3:
			clearTimeout(timerId);
			scene = 1;
			$('#index2').css({left: '1900px', opacity: 0});
			$('#index1').animate({left: '0px', opacity: 1}, 2000);
			$('#index2').animate({left: '950px'}, 2000);
			$('#index3').animate({left: '-950px', opacity: 0}, 2000);
			timerId = setTimeout('topMovieStart()', 7000);
			break;
	}
};

$(function() {
	// for IE7/8 png images
	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");'});
            }
        });
    }
	
	// rollover
	var imgCache = new Object();
	
	$(".swap").each(function(i) {
		var img = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgOn = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		
		imgCache[this.src] = new Image();
		imgCache[this.src].src = imgOn;
		
		$(this).hover(
			function() { this.src = imgOn; },
			function() { this.src = img; }
		);
	});
	
	// scroll
	$('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;
			}
		}
	});
	
	// anchor link
	if(location.href.indexOf("#") != -1) {
		$('html, body').animate({scrollTop: $('#' + location.href.split("#")[1]).offset().top}, 500);
	}
	
	try {
		topMovieStart();
	} catch(e) {
	}
});

