/**
 * @author doramong
 */
$(function(){
	// min-width:1000px;
})

var pu = {};

pu.ie6Check = function(){
	return ($.browser.msie && $.browser.version=="6.0") ? true : false;
}
/*
pu.ie6MinWidth = function(id){//매개변수 min-width 적용할 id 값(String)
	var jqEl = $(id);
	var bomWidth = $(window).width();
	var width;
	
	if ( bomWidth > 1000 ) {
		width = 1000+(bomWidth-1000);
		console.log("width : "+width); 	
	} else {
		width = 1000;
	}
	
	console.log("width : "+width);
	
	jqEl.css("width",width);
	jqEl = null;	
}
*/

pu.mainSlide = function(){
  var currentPosition = 0;
  var slideWidth = 950;
  var pagingButtonWidth = 20;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
  var slideAnimated = true;
  var slideInterval;
  var sildeTime = 3000;
  
  startSlideInterval = function(){
  	slideInterval = setInterval(function(){
  		slideAnimate($("#pg1_v .pg1_v_btn").eq(currentPosition),new Object());
  	},sildeTime);
  }
  
  stopSlideInterval = function(){
  	if(slideInterval){	
  		clearInterval(slideInterval);
  		slideInterval = null;
  	}
  }
  
  $('#slidesContainer, #pg1_v').bind("mouseenter",function(){
  	 stopSlideInterval();
  }).bind("mouseleave",function(){
  	 startSlideInterval();			
  });
  
  $('#slidesContainer').css('overflow', 'hidden');

  slides.wrapAll('<div id="slideInner"></div>').css({
      'float' : 'left',
      'width' : slideWidth
    });

  $('#slideInner').css('width', slideWidth * numberOfSlides);
  $(".pg_v").css('width', pagingButtonWidth * numberOfSlides);
  
  
  $("#pg1_v .pg1_v_btn").bind('click', function(){
  	//stopSlideInterval();
  	slideAnimate($(this));
  	//startSlideInterval();
  });
  
  $("#pg1_prev").bind('click',function(){
  	if(slideAnimated){
  		currentPosition -= 1;
  		if(currentPosition==-1) currentPosition = numberOfSlides-1;
	  	slideAnimate($("#pg1_v .pg1_v_btn").eq(currentPosition));
  	}
  });
  
  $("#pg1_next").bind('click',function(){
  	if(slideAnimated){
	  	currentPosition += 1;
	  	if(currentPosition==numberOfSlides) currentPosition = 0;
	  	slideAnimate($("#pg1_v .pg1_v_btn").eq(currentPosition));
	}
  });
  
  slideAnimate = function(jObj,type){
  	if(slideAnimated){
  		slideAnimated = false;
	  	
	  	$("#pg1_v .pg1_v_btn").each(function(){
	  		$(this).find("a").text("●");
	  	});
	  	
	  	if(type){
	  		currentPosition += 1;
	  		if(currentPosition==numberOfSlides) currentPosition = 0;
	  		$("#pg1_v .pg1_v_btn").eq(currentPosition).find("a").text("○");
	  	}else{
	  		jObj.find("a").text("○");
	  		currentPosition = $("#pg1_v .pg1_v_btn").index(jObj);
	  	}
	  	
	  	$(".slideContent div:visible").fadeOut(function(){
	  		$(".slideContent div").eq(currentPosition).fadeIn();
	  	});
	  	
	  	$('#slideInner').animate({
	      	'marginLeft' : slideWidth*(-currentPosition)
	    },{'easing': "easeInExpo",
	    	complete: function() {
      			slideAnimated = true;
    		}
	    });
	    jObj = null;
    }
  }
  startSlideInterval();	
}

