var is_out = true
var photoNum = 4
var photoWidth = 700
var slideWidth = 0
var duration = 900
var interval = 5000 //mili seconds

jQuery(function($){
  //main visual				
  $('.slideSwitch').each(function(i){
    $(this).mouseenter(function(){
	  is_out = false
	  //console.log(i);
	  $('.slideSwitch').removeClass('on')
	  $(this).addClass('on')
	  $('#slider').stop().animate({marginLeft: -photoWidth*i + 'px'}, duration,'easeInOutQuart')
	  slideWidth = -photoWidth*i
    })
	.mouseleave(function () {
	  is_out = true
	})
  });
  
})

function goSlide() {
	var global_flag = true;
	var i = 1
	var sliding = function () {
	  if(is_out&&global_flag){
		slideWidth -= photoWidth
		if (slideWidth == (0-photoNum*photoWidth)){
		  slideWidth = 0
		  global_flag = false;
	    }
		$('#slider').animate({marginLeft:slideWidth+'px'}, duration,'easeInOutQuart')
		
		i = -(slideWidth/photoWidth)+1
		$('.slideSwitch').removeClass('on')
		$('#mainNavi').find('li:nth-child('+i+')').addClass('on')
	  }
	}
	setInterval(sliding,interval);
}

