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

summary:change element size full of window

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

new function() {
	
	var fadeTime = 250;	// msec
	var offClass = 'off';
	var onClass = 'on';
	
	$(document).ready( function() {
		init();
	});
	
	/**
	 * 初期化
	 */
	function init() {
		
		var $imgs = $( 'a img' );
		
		$imgs.each( function() {
			
			var src = $(this).attr( 'src' );
			var onImage = $(this).clone();
			
			if ( src.indexOf( '_off.' ) !== -1 ) {
				
				onImage.
					attr( 'src', src.replace( '_off.', '_on.' ) ).
					addClass( onClass ).
					fadeTo( 0, 0 ).
					css({
						'position': 'absolute',
						'left': '0px',
						'top': '0px'
					});
				
				var w = ( $(this).attr( 'width' ) ) ? $(this).attr( 'width' ) : $(this).width();
				var h = ( $(this).attr( 'height' ) ) ? $(this).attr( 'height' ) : $(this).height();
				
				$(this).
					addClass( offClass ).
					parent().
						append( onImage ).
						mouseover( onMouseOver ).
						mouseout( onMouseOut ).
						css({
							'display': 'block',
							'position': 'relative'
						}).
						width( w ).
						height( h );
			}
		});
		
		// IE PNG対応
		if ( typeof( DD_belatedPNG ) !== 'undefined' ) {
			DD_belatedPNG.fix( '.fade_png' );
		}
	}
	
	
	/**
	 * ロールオーバー時 イベントリスナ
	 */
	function onMouseOver( e ) {
		
		var src = $(this).children( 'img.' + offClass ).attr( 'src' );
		
		$(this).unbind( 'mouseover', onMouseOver );
		
		if ( src.indexOf( '.png' ) !== -1 ) {
			$(this).
				children( 'img.' + offClass ).
					fadeTo( fadeTime, 0 ).
				end().
				children( 'img.' + onClass ).
					fadeTo( fadeTime, 1, function(){
						$(this).parent().mouseover( onMouseOver );
					});
		}
		else {
			$(this).
				children( 'img.' + onClass ).
					fadeTo( fadeTime, 1, function(){
						$(this).parent().mouseover( onMouseOver );
					});
		}
	}
	
	/**
	 * ロールアウト時 イベントリスナ
	 */
	function onMouseOut( e ) {
		
		var src = $(this).children( 'img.' + offClass ).attr( 'src' );
		
		if ( src.indexOf( '.png' ) !== -1 ) {
			$(this).
				children( 'img.' + offClass ).
					fadeTo( fadeTime, 1 ).
				end().
				children( 'img.' + onClass ).
					fadeTo( fadeTime, 0 );
		}
		else {
			$(this).
				children( 'img.' + onClass ).
					fadeTo( fadeTime, 0 );
		}
	}
}
