var weie_stack = "pic_00";
var weie_roop_stack = "pic_00";
var weie_query = "";
var weie_timer_id = null;
var weie_timer_msec = 5000;
var weie_length = 0;
var weie_next_num = 0;

function weImageEffectInit( aQuery, aTimerMsec )
{
	weie_query = aQuery;
	weie_length = $( weie_query + " .pic_box div" ).length;

	if( typeof(aTimerMsec) != "undefined" ){
		weie_timer_msec = aTimerMsec;
	}

	$( weie_query + " .pic_box div" ).each(
		function( index, elm ){
			//tmp_index = index - 1;
			tmp_index = index;
			now_index = index;

			$( weie_query + " .pic_box div:eq(" + index + ") img" ).attr( "rel", "pic_" + (now_index+1) );

			$( weie_query + " .pic_box div:eq(" + index + ") img" ).mouseover(
				function(event){
					var pic_class = $(this).attr("rel");

					weie_stack = pic_class;

					clearTimeout(weie_timer_id);
					weie_timer_id = null;
				}
			);

			$( weie_query + " .pic_box div:eq(" + index + ") img" ).mouseout(
				function(event){
					weie_roop_stack = weie_stack;
					weie_timer_id = setTimeout( weImageEffectRoop , weie_timer_msec );
				}
			);

			//if( index != 0 ){
/*
				if( now_index <= 9 ){
					now_index = "0" + index;
				}
*/
				$( weie_query + " .btn_list li:eq(" + tmp_index +") img" ).attr( "rel", "pic_" + (now_index+1) );

				$( weie_query + " .btn_list li:eq(" + tmp_index +") img"  ).mouseover(
					function(event){
						var pic_class = $(this).attr("rel");

						if( weie_stack != pic_class ) {
							weie_next_num = pic_class;

							$( weie_query + " .pic_box ." + weie_stack ).fadeOut( "normal", weImageEffectFadeIn );

							weie_stack = pic_class;
						}

						clearTimeout(weie_timer_id);
						weie_timer_id = null;
					}
				);

				$( weie_query + " .btn_list li:eq(" + tmp_index +") img"  ).mouseout(
					function(event){
						weie_roop_stack = weie_stack;
						weie_timer_id = setTimeout( weImageEffectRoop , weie_timer_msec );
					}
				);

				if( index > 0 ){
					$( elm ).hide();
				}
			//}

			
		}
	);

	weie_timer_id = setTimeout( weImageEffectRoop , weie_timer_msec );
}

function weImageEffectRoop()
{
	var now_num = new Number( weie_stack.replace("pic_", "") );
	var next_num = 1;

	var now_index = now_num;
/*
	if( now_index <= 9 ){
		now_index = "0" + now_index;
	}
*/
	if( (now_num+1) <= weie_length){
		next_num = now_num+1;
	}
/*
	if( next_num <= 9 ){
		next_num = "0" + next_num;
	}
*/
	weie_next_num = "pic_" + next_num;
	$( weie_query + " .pic_box .pic_" + now_index ).fadeOut( "normal", weImageEffectFadeIn );

	weie_stack = "pic_" + next_num;

	weie_timer_id = setTimeout( weImageEffectRoop , weie_timer_msec );
}

function weImageEffectFadeIn()
{
	$( weie_query + " .pic_box ." + weie_next_num ).fadeIn();
}
