/**
 * Filename: init.js
 * Website: for Maiko-henshin Studio Shiki
 *	
 */
 
$(function() {
	// Top Slide
/*
	if ($.cookie('cookieData') == null) {
		var _clientHeight = document.documentElement.clientHeight;
		var _contensHeight = $('#producedShiki').position().top;
		var _posCampaign = $('#contents').position().top;

		if (_clientHeight < _contensHeight) {
			$('html,body').delay(300).animate({
				'scrollTop':_contensHeight
			}, 1500, function() {
				$(this).animate({
					'scrollTop':_posCampaign
				}, 1500, function() {
					$(this).delay(300).animate({
						'scrollTop':0
					}, 2000, writeCookie);
				});
			});
		}
		
		function writeCookie() {
			$.cookie('cookieData', "", {expires:1});
			movieStart();
		}
	} else {
		movieStart();
	}
*/

	// Flash Movie
	function movieStart() {
		swfobject.embedSWF("/assets/swf/movie.swf", "flashContents", "900", "510", "7.0.0", null, null, {'wmode':'opaque'});
	}
	
	
	function bc30Campaign() {
		var _ttl01W = 285,
			_ttl01H = 31;
		var _ttl02W = 317,
			_ttl02H = 30;
		var _ttl03W = 608,
			_ttl03H = 45;
		var _priceElement = $('#campaignPrice'),
			_price = 13000,
			_countPrice = 10,
			_speed = 1000,
			_timer = null;
			_timer2 = null;
		var _gaya = '<div id="gaya">'
			+ '<p id="gaya01" class="gaya">おっ！</p>'
			+ '<p id="gaya02" class="gaya">おっ！！</p>'
			+ '<p id="gaya03" class="gaya">おおおっ！</p>'
			+ '<p id="gaya04" class="gaya">おおっ！</p>'
			+ '<p id="gaya05" class="gaya">おおおっ！</p>'
			+ '<p id="gaya06" class="gaya">おっ！</p>'
			+ '<p id="gaya07" class="gaya">おおっ！</p>'
			+ '<p id="gaya08" class="gaya">おっ！</p>'
			+ '<p id="gaya09" class="gaya">おおっ！</p>'
			+ '<p id="gaya10" class="gaya">おおおっ！</p>'
			+ '<p id="gaya11" class="gaya">おおっ！</p>'
			+ '<p id="gaya12" class="gaya">おっ！</p>'
			+ '</div>';
		var _gaya13 = '<p id="gaya13">せーの!!</p>';
		var _gayalist = '#gaya01, #gaya02, #gaya03, #gaya04, #gaya05, #gaya06, #gaya07, #gaya08, #gaya09, #gaya10, #gaya11, #gaya12';
		
		$('#campaignPrice').html(_price);
		$('#bc30Ttl01 img').css({
			'width': _ttl01W * 3,
			'height': _ttl01H * 3
		});
		$('#bc30Ttl02 img').css({
			'width': _ttl02W * 3,
			'height': _ttl02H * 3
		});
		$('#bc30Ttl03 img').css({
			'width': _ttl03W * 3,
			'height': _ttl03H * 3
		});
		
		$('#bc30Ttl01 img').animate({
			'width': _ttl01W,
			'height': _ttl01H
		}, 1000, "easeOutCubic", function() {
			$('#bc30Ttl02 img').delay(100).show().animate({
				'width': _ttl02W,
				'height': _ttl02H
			}, 1000, "easeOutCubic", function() {
				$('#bc30Ttl03 img').delay(100).show().animate({
					'width': _ttl03W,
					'height': _ttl03H
				}, 1000, "easeOutCubic", function() {
					$('#bc30cData').fadeIn(500, function() {
						function priceSet() {
							_price = _price - _countPrice;
							_priceElement.html(_price);
							
							if (_price == 7900) {
								_priceElement.animate({
									'font-size': '300%'
								}, _speed);
								_timer = setTimeout(priceSet, 10);
							} else if (_price == 6900) {
								clearTimeout(_timer);
								$('#pleasePriceDown').delay(1000).fadeIn();
								$('#pleasePriceDown').animate({
									'top': -20
								}, _speed, function() {
									$(this).delay(1000).fadeOut(300, function() {
										jQuery(this).css('top', 20).html("もうひと声！！");
										_timer = null;
										_timer2 = setTimeout(priceSet, 100);
										_priceElement.animate({
											'font-size': '400%'
										}, _speed);
									});
								});
							} else if (_price == 5900) {
								clearTimeout(_timer2);
								$('#pleasePriceDown').delay(1000).fadeIn();
								$('#pleasePriceDown').animate({
									'top': -20
								}, _speed, function() {
									$(this).delay(1000).fadeOut(300, function() {
										_timer2 = null;
										_timer2 = setTimeout(priceSet, 100);
									});
								});
							} else if (_price == 5800) {
								clearTimeout(_timer2);
								jQuery('#gaya01').delay(200).show(0, function() {
									$(this).delay(1000).show(0, function() {
										_timer2 = null;
										_timer2 = setTimeout(priceSet, 40);
									});
								});
							} else if (_price == 5700) {
								clearTimeout(_timer2);
								jQuery('#gaya02').delay(200).show(0);
								jQuery('#gaya03').delay(400).show(0);
								jQuery('#gaya03').delay(600).show(0);
								jQuery('#gaya04').delay(800).show(0, function() {
									$(this).delay(1000).show(0, function() {
										_timer2 = null;
										_timer2 = setTimeout(priceSet, 80);
									});
								});
							} else if (_price == 5500) {
								clearTimeout(_timer2);
								jQuery('#gaya05').delay(200).show(0);
								jQuery('#gaya06').delay(400).show(0);
								jQuery('#gaya07').delay(600).show(0);
								jQuery('#gaya08').delay(800).show(0);
								jQuery('#gaya09').delay(950).show(0);
								jQuery('#gaya10').delay(1100).show(0);
								jQuery('#gaya11').delay(1250).show(0);
								jQuery('#gaya12').delay(1400).show(0);
								jQuery('#gaya').delay(2000).hide(0, function() {
									jQuery(_gayalist).html("もう一声！！");
									jQuery(this).delay(1000).fadeIn(300, function() {
										jQuery(this).delay(1000).fadeOut(500);
										jQuery('#gaya13').delay(800).show(0).animate({
											'font-size': '77%'
										}, 600, "easeOutExpo", function() {
											jQuery(this).html("せーの!!")
											jQuery(this).delay(400).animate({
												'font-size': '600%'
											}, 400, "easeOutExpo", function() {
												jQuery(this).delay(500).fadeOut(200, function() {
													_timer2 = null;
													_timer2 = setTimeout(priceSet, 10);
												});
											});
										});	
									});
								});
							} else if (_price == 5200) {
								clearTimeout(_timer2);
								_priceElement.delay(800).show(0, function() {
									_timer2 = null;
									_timer2 = setTimeout(priceSet, 200);
									jQuery(this).animate({
										'font-size': '600%'
									}, 1000, "easeOutBounce");
								});
							} else if (_price == 5100) {
								clearTimeout(_timer2);
								_priceElement.delay(800).show(0, function() {
									_timer2 = null;
									_timer2 = setTimeout(priceSet, 200);
									jQuery(this).animate({
										'font-size': '800%'
									}, 1000, "easeOutBounce");
								});
							} else if (_price == 5000) {
								clearTimeout(_timer2);
								_priceElement.delay(800).show(0, function() {
									_timer2 = null;
									_timer2 = setTimeout(priceSet, 200);
								
									jQuery(this).animate({
										'font-size': '1200%'
									}, 1000, "easeOutBounce");
								});
							} else if (_price == 4900) {
								clearTimeout(_timer2);
								$('.bc30Banner').delay(1000).fadeIn(500, function() {
									movieStart();
								});
								$('#playArea').delay(1500).fadeOut(500);
							} else {
								_timer = setTimeout(priceSet, 8);
							}
						}
						priceSet();
					});
				});
			});
		});
		$('html,body').css('overflow-x','hidden');
		$('#bc30c').show(0).append('<p id="pleasePriceDown">まだまだ頑張ります！！</p>' + _gaya);
		$('#bc30c').append(_gaya13);
		$('#gaya13').hide();
		$('#bc30Ttl02 img, #bc30Ttl03 img, #bc30cData').hide();
		$('.bc30Banner').hide();
		
	}
	$(window).load(function() {
		$('#loading').hide();
		bc30Campaign();
	});
	
	var _loading = '<div id="loading"><img src="/assets/imgs/common/loading.gif" alt="" width="48" height="48" /></div>'
	$('#mainDisplay').append(_loading);
	
	// Delete Cookie
/*
	if ($.cookie('cookieData') != null) {
		$.cookie('cookieData', '', {expires:-1});
	}
*/
});
