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

Description: side_navi mouse hover effect
Update: 2010/06/17-
Author: Japan Electronic Industrial Arts Co.Ltd.
        http://jeia.co.jp/

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

new function() {
	
	var $body = null;
	var $base = null;
	var $modal = null;
	var baseId = 'main';
	var modalId = 'portfolio_modal';
	var expandedClass = 'expanded';
	
	if ( typeof jQuery == 'undefined' ) {
		return;
	}
	
	$(document).ready( function() {
		init();
	});
	
	/**
	 * 初期化
	 */
	function init() {
		
		$body = $( 'document, body' );
		$base = $( '#' + baseId );
		
		$( '#portfolio_navi .parent' ).click( function() {
			showChild( this );
		});
		
		$( '#portfolio_navi .child' ).each( function() {
			var w = $(this).parent().width() - 2;
			var x = $(this).parent().offset().left - $base.offset().left + 1;
			var y = $(this).parent().offset().top - $base.offset().top + $(this).parent().height();
			
			$(this).css({
				position: 'absolute',
				left: x + 'px',
				top: y + 'px',
				display: 'block',
				width: w + 'px'
			}).
			appendTo( $body.get(0) ).
			hide();
		});
	}
	
	/**
	 * show child
	 */
	function showChild( _target ) {
		
		$(_target).addClass( expandedClass );
		
		var modalHtml = [
			'<div id="',modalId,'">',
				'<div class="background">',
				'</div>',
			'</div>'
		].join('');
		
		$base.append( modalHtml );
		
		$modal = $( '#' + modalId );
		$modal.css({
			position: 'absolute',
			left: '0px',
			top: '0px',
			width: '100%',
			height: '100%'
		}).
		find( '.background' ).bind( 'click', function() {
			hideChild();
			return false;
		});
		
		var childId = $(_target).attr( 'href' );
		
		$( childId ).appendTo( $modal.get(0) ).slideDown();
	}
	
	/**
	 * hide child
	 */
	function hideChild() {
		$modal.unbind().
		find( '.child' ).fadeOut( 'fast', function() {
			$(this).appendTo( $body.get(0) );
			$modal.remove();
			$modal = null;
			
			$( '#portfolio_navi .' + expandedClass ).removeClass( expandedClass );
		});
	}
	
	
}

