var windowW;
var windowH;
var currentNum = 0;
var totalNum;
var interval;
var currentEvtNum = 0;
var evtNum;
var interval2;
var countNum = 0;
var scrollPosition = [ "0" , "700" , "2100" ];    // html , body scrollTop

$(function()
{
	$(window).resize ( function ()
	{	
		windowW = 781;//$(window).width();
		windwH = 495;//$(window).height();

		//Main_visual
		$(".visual li").each(function(i)
		{	
			$(this).css ( { left:windowW * i } );
		});
		$(".visual").stop().css( { width:windowW*5, left:-currentNum*windowW } );
		$(".roll").stop().css( {width:windowW } );
		$(".visual li").stop().css( {width:windowW } );

		//Event
		$(".evt_lst li").each(function(i)
		{	
			$(this).css ( { left:windowW * i } );
		});
		$(".evt_lst").stop().css( { width:windowW*5, left:-currentEvtNum*windowW } );
		$(".evt_box").stop().css( {width:windowW } );
		$(".evt_lst li").stop().css( {width:windowW } );

		$(".mov").find("a").each(function(i)
		{
			$(this).bind( "click" , movPopStart );
		});
		

	}).resize();

	function movPopStart()
	{
		clearTimeout ( interval );
	}
	

	totalNum = $(".visual").find("li").length;
	evtNum = $(".evt_lst").find("li").length;

	for ( var i = 0; i < totalNum; i++ )
	{
		$(".btn_area").append ( '<a href="javascript:bltwrap('+i+')"><img src="/Shopmy/images/btn_bn_off.png" /></a>' );
	}
	moveBanner();
	moveEvent();
	bltwrap(0);
});

function btnLft()
{
	currentNum--;
	
	if( currentNum < 0 )
	{
		currentNum = 0;
	}
	moveBanner();
}

function btnRgt()
{
	currentNum++;

	if( currentNum > totalNum-1 )
	{
		currentNum = totalNum-1
	}
	
	moveBanner();
}

function bltwrap(id)
{
	$(".btn_area a").click ( pageMove(id) );
}

function pageMove(id)
{
	
	currentNum = id;//$(this).index();	
	if( currentNum < 0 )
	{
		currentNum = 0;
	}
	//alert(currentNum);
	moveBanner();
}

function pageAutoCount()
{
	currentNum++;
	moveBanner();
}

function moveBanner()
{
	if ( currentNum < 0 ) currentNum = totalNum-1;
	if ( currentNum > totalNum-1 ) currentNum = 0;

	$(".btn_area a").each ( function (i)
	{
		if ( i == currentNum )
		{
			$(this).find("img").attr("src" , "/Shopmy/images/btn_bn_on.png");
		}
		else
		{
			$(this).find("img").attr("src" , "/Shopmy/images/btn_bn_off.png");
		}
	});	
	
	if( currentNum == 0 )
	{
		$(".visual").stop().animate ( { left:-currentNum * windowW } );
		clearTimeout ( interval );
		interval = setTimeout ( pageAutoCount , 10000 );
	}

	else
	{
		$(".visual").stop().animate ( { left:-currentNum * windowW } );
		clearTimeout ( interval );
		interval = setTimeout ( pageAutoCount , 3500 );
	}
	
	
}

function moveEvent()
{

	$(".evt_lst").stop().animate ( { left:-currentEvtNum * windowW } );	

	currentEvtNum++;
	
	if ( currentEvtNum > evtNum-1 ) currentEvtNum = 0;
	clearTimeout ( interval2 );
	interval2 = setTimeout ( moveEvent , 3500 );
}
