
/**/
if(typeof $x =='undefined') $x={};

$x.ready = {}

$x.goback = function(){
	history.back();
}

/* ページ内スクロール */
$x.ready.page_scroll = function(){
	var $func = 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 }, 1200, 'quart');
				return false;
			}
		}
	}
	$('a[href*=#]').not('.no-scroll').click( $func );
}
// jQuery.easingの追加
if( !jQuery.easing.quart){
	jQuery.easing.quart = function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; };
}
$(function(){$x.ready.page_scroll()});




$x.sitefunc =
{
header_char: {
	status: null,
	timer: 0,
	prop: [ 0 ],
	mode: 0,
	offset_y: 20,
	run: function(){
		var x = $x.sitefunc.header_char;
		if( x.status != null ) clearTimeout( x.timer  );
		if( x.status == null ){ x.status = 0; x.mode = -1; }
		var tstop = false;
		x.status++;
		var n = x.status;
		if( n > 63 ){
			x.status = 0;
			if( x.mode == -1 )  tstop = true;
		}
		if( !tstop ){
			n = Math.floor( Math.sin( (n+5)/ 10 )*10 ) -5+x.offset_y;
			$('#header-char').css( { 'top': ''+n+'px' } );
			var t = 20;
			x.timer = setTimeout(  x.run,  t );
		}else {
			x.move_off();
		}
	},
	move_hover:function(){
		var x = $x.sitefunc.header_char;
		if( x.mode == 0 ){ x.run(); }
		x.mode = 1;
	},
	move_out:function(){
		$x.sitefunc.header_char.mode = -1;
	},
	move_off:function(){
		var x = $x.sitefunc.header_char;
		x.status = 0; x.mode = 0;
		$('#header-char').css( { 'top': x.offset_y+'px' } );
	}
}

// animation start
}
$(function(){
	var x1 = $x.sitefunc.header_char;
	var y = $('#header-char').css('top').replace('px','');
	x1,offset_y = y;//alert(y);
	x1.run();
	$('#header-char').hover(function(){x1.move_hover()},function(){x1.move_out()});
});



/* gallery rotator */
$x.gallery_rotator = {
	set: function(){
	//Set Variables
	var flow_main_ID = '#'+$(this).find('img').attr("class"); //Get image class name
	var flow_main = flow_main_ID+' .flow_main';
	var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
	var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
	var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
	var imgDescHeight = $(flow_main).find('.block').height(); //Find the height of the "block"
	//Animate the Description
	$(flow_main+" .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() { //Pull the block down (negative bottom margin of its own height)
	$(flow_main+" .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); //swap the html of the block, then pull the block container back up and set opacity
	$(flow_main+" img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
	});

	//Show active list-item
	$(flow_main_ID+" .flow_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
	$(this).addClass('active');  //Add class of 'active' on the selected list
	return false; 
	}
}
$(function(){
	$(".flow_main .desc").show();
	$(".flow_main .block").animate({ opacity: 0.85 }, 1 );

	$(".flow_thumb li.first-active").addClass('active'); 
	$(".flow_thumb li.first-active").each( function(){$x.gallery_rotator.set.call(this)} );
	$(".flow_thumb li").click(
		function(){return $x.gallery_rotator.set.call(this); }
	).hover(
		function(){ $(this).addClass('hover');  },
		function() { $(this).removeClass('hover'); }
	);
	$("a.collapse").click( function(){
		$(".main_banner .block").slideToggle(); 
		$("a.collapse").toggleClass("show");
	});
});


$x.rotate = function( elm, deg ){
	var elm = ( typeof( elm ) == 'string' ) ? $(elm) : elm;
	var s = 'rotate('+deg+'deg)';
	elm.css( { '-webkit-transform':s, '-moz-transform':s, '-o-transform':s, '-ms-transform':s, 'transform':s } );
	// ie
	s = navigator.userAgent.toLowerCase();
	var ps = s.indexOf("msie");
	if(ps!=-1){
		var pe = s.indexOf(";",ps);
		var ver = parseInt( s.substring( ps+5,pe ) );
		if( ver<9 ){ // ie version of css transform working. 9?
			var rad = deg * Math.PI/180;
			var cos = Math.cos(rad), sin = Math.sin(rad);
			elm.each( function(){
				var w = this.offsetWidth, h = this.offsetHeight;
				s = "progid:DXImageTransform.Microsoft.Matrix(M11="+cos+",M12=-"+sin+",M21="+sin+",M22="+cos+",sizingMethod='auto expand')";
				$(this).css( { filter: s } );
				var mt = parseInt( $(this).css( 'top' ) ) || 0, ml = parseInt( $(this).css( 'left' ) ) || 0;
				$(this).css( {  'top': mt + 1/2 * (h - w * sin - h * cos) + "px" } );
				$(this).css( {  'left': ml + 1/2 * (w - h * sin - w * cos) + "px" } );
			});
		}
	}
}

$x.siteMaker = {
	data:[
		// [ '#container', '<div id="container-top"></div>', '<div id="container-bottom"></div>', { 'margin': '0', 'border':'none' } ]
	],
	onLoaded: function(){
		var x = $x.siteMaker;
		var data = x.data;
		var i, ii;
		if( data.length ){ for( i=0; i<x.data.length; i++ ){ if( data[i] ){ if( data[i][0]){
			var elm = $(data[i][0]);
			if( elm.size() > 0 ){
				if( data[i][1] ){
					if( typeof( data[i][1] ) == 'string' ){
						elm.prepend(data[i][1]);
					}else {
						for( ii=0; ii<data[i][1].length; ii++){ if(data[i][1][ii]){ elm.prepend( data[i][1][ii] ) } }
					}
				}
				if( data[i][2] ) elm.append(data[i][2]);
				if( data[i][3] ) elm.css(data[i][3]);
			}
		}}}}
	}
}
$(function(){
	$x.siteMaker.onLoaded();
});

