var sprash;

$(document).ready(function() {
	sprash = new Sprash;
	sprash.start();
});

//--------------------- Sprash ---------------------//
var Sprash = function() {
	this.bodyElement = $('body');
	this.sprashElement = $('#sprash');
	
	this.img01 = $('#img1');
	this.img02 = $('#img2');
	this.img03 = $('#img3');
	this.img04 = $('#img4');
	this.img05 = $('#img5');
	this.img06 = $('#img6');
	
	this.sprashContentElement = $('#sprash_contents');
	
	this.init();
}
Sprash.prototype.init = function() {
	$('<img src="images/sprash/01bg_d.jpg" />');
	$('<img src="images/sprash/01bg_c.jpg" />');
	$('<img src="images/sprash/01bg_b.jpg" />');
	$('<img src="images/sprash/01bg_a.png" />');
	$('<img src="images/sprash/01img_a.png" />');
	$('<img src="images/sprash/01img_b.png" />');
	$('<img src="images/sprash/01img_c.png" />');
	
	setSize('.bg', 1280, 630);
}
Sprash.prototype.start = function() {
if (document.referrer.split('/')[2] == location.href.split('/')[2] || (ie && ie < 7)) {
		this.bodyElement.css({'overflow':'auto', 'overflow-x':'hidden'});
		this.sprashElement.css('display', 'none');
	}
	else {
		this.animation01();
	}
}
Sprash.prototype.animation01 = function() {
	this.img05.fadeIn(1000);
	this.img04.fadeIn(1000, function() {
		sprash.animation02();
	});
	this.img06.fadeIn(1000);
}
Sprash.prototype.animation02 = function() {
	this.img01.delay(3000).fadeOut(1000);
	this.img02.delay(3000).fadeIn(1000, function() {
		sprash.animation03();
	});
}
Sprash.prototype.animation03 = function() {
	this.img01.hide();
	this.img02.delay(2000).fadeOut(1000);
	this.img03.delay(2000).fadeIn(1000, function() {
		sprash.animation04();
	});
	this.img06.delay(2000).fadeOut(1000);
}
Sprash.prototype.animation04 = function() {
	this.img02.hide();
	this.img03.delay(2000).fadeOut(1000, function() {
		sprash.finish();
	});
}
Sprash.prototype.finish = function() {
	this.bodyElement.css({'overflow':'auto', 'overflow-x':'hidden'});
	this.img03.hide();
	this.sprashElement.fadeOut(2000, function() {
		sprash.sprashElement.hide();
		$(window).resize();
	});
}
//--------------------- Sprash ---------------------//


$(window).resize(function() {
	setSize('.bg', 1280, 630);
	setSize('.bg2', 1280, 884);
});


function setSize(target, imgW, imgH) {
	var winW = $(window).width();
	var winH = $(window).height();
	
	var scaleW = winW / imgW;
	var scaleH = winH / imgH;
	var fixScale = Math.max(scaleW, scaleH);
	
	var setW = imgW * fixScale;
	var setH = imgH * fixScale;

	var moveX = Math.floor((winW - setW) / 2);
	var moveY = Math.floor((winH - setH) / 2);

	$(target).css({
		'width':	setW,
		'height':	setH,
		'left':		moveX,
		'top':		moveY
	});
}

