﻿/*
======== table of content. =================================

Description: init /index.html
Update: 2010/06/25-
Author: Japan Electronic Industrial Arts Co.Ltd.
        http://jeia.co.jp/

============================================================
*/

new function() {
	
	if ( typeof jQuery == 'undefined' ) {
		return;
	}
	
	$(document).ready( function() {
		init();
	});
	
	/**
	 * init
	 */
	function init() {
		
		// service
		$( '#service_list .service_element' ).
		hover( overServiceElement, outServiceElement ).
		find( '.text' ).css({ display: 'block' }).hide().end().
		find( '.link span' ).css({ display: 'block' }).hide();
		
		// works
		$( '#works_list .works_element' ).
		hover( overWorksElement, outWorksElement );
	}
	
	
	/**
	 * rollover/out service_element
	 */
	var reverseClass = 'reverse';
	
	// over
	function overServiceElement( _e ) {
		
		var w = $(this).find( '.box .data' ).width();
		var h = $(this).find( '.box .data' ).height();
		
		$(this).find( '.box' ).stop().
		animate({
			width: '0px',
			left: (w / 2) + 'px'
		}, 150, 'swing', function() {
			// reverse
			$(this).addClass( reverseClass ).
			animate({
				width: w + 'px',
				left: '0px'
			}, 150, 'swing', function(){
				$(this).animate({
					width: (w + 20) + 'px',
					height: (h + 20) + 'px',
					left: '-10px',
					top: '-10px'
				}, 200, 'swing' );
				$(this).parent().find( '.link a span' ).css({
					width: (w + 20) + 'px',
					left: '-9px',
					bottom: '-9px'
				}).fadeIn();
			}).
			find( '.text' ).show();
		});
	}
	// out
	function outServiceElement( _e ) {
		
		var w = $(this).find( '.box .data' ).width();
		var h = $(this).find( '.box .data' ).height();
		
		$(this).find( '.box' ).stop().
		animate( {
			width: '0px',
			height: h + 'px',
			left: (w / 2) + 'px',
			top: '0px'
		}, 150, 'swing', function() {
			// reverse
			$(this).removeClass( reverseClass ).
			animate({
				width: w + 'px',
				left: '0px'
			}, 150, 'linear' ).
			find( '.text' ).hide();
		}).
		find( '.text' ).fadeOut().end().
		end().
		find( '.link a span' ).hide();
	}

	
	/**
	 * rollover/out works_element
	 */
	// over
	function overWorksElement( _e ) {
		$(this).addClass( 'hover' ).
			find( '.image' ).stop().fadeTo( 200, 0.4 );
	}
	// out
	function outWorksElement( _e ) {
		$(this).removeClass( 'hover' ).
			find( '.image' ).stop().fadeTo( 200, 1 );
	}
}

