/*var carousel={

	prevItem:{element:{},index:0},
	nextItem:{element:{},index:0},
	mainItem:{element:{},	index:0},
	intervalKey:{},
	$items:$('.carousel-item'),

	init: function(){

		$('.ctrl-btn a.prev').bind('click',function(e){
			e.preventDefault();
			carousel.backMove();
		});
		$('.ctrl-btn a.next').bind('click',function(e){
			e.preventDefault();
			carousel.move();
		});

		this.$items.find('.carousel-image > a ,.ctrl-btn').hover(function(){carousel.pause();},function(){carousel.start();});
		$('.ctrl-btn a.pause').toggle(function(){
			if($(this).attr('class') != "start") {
				carousel.pause();
				$(this).removeClass('pause').addClass('start');
			}
		},function(){
			if($(this).attr('class') != "pause") {
				carousel.start();
				$(this).removeClass('start').addClass('pause');
			}
		});

		this.start();
	},

	start:function(){
		this.intervalKey = setInterval(function(){carousel.move();},5000)
	},

	pause:function(){
		clearInterval(carousel.intervalKey);
	},

	getItem: function(){
		this.$items.each(function(i,el) {
           if($(el).hasClass('active')) {
				carousel.mainItem.element = $(el);
				carousel.mainItem.index = i;
			}
        });

		if(this.mainItem.index + 1 < this.$items.size()){
			this.nextItem.element = this.$items.eq(this.mainItem.index+1);
			this.nextItem.index = this.mainItem.index + 1;
		}
		else{
			this.nextItem.element = this.$items.eq(0);
			this.nextItem.index = 0;
		}

		if (this.mainItem.index - 1 >= 0){
			this.prevItem.element = this.$items.eq(this.mainItem.index-1);
			this.prevItem.index = this.mainItem.index - 1;
		}
		else{
			this.prevItem.element = this.$items.eq(-1);
			this.prevItem.index = this.$items.size() - 1;
		}


	},
	setItem: function(){
		this.prevItem.element.css({'left':'-1000px'});
		this.nextItem.element.css({'left':'1000px'});
	},

	move: function(){
		this.getItem();
		//this.setItem();

		if ($.browser.msie && parseInt($.browser.version) <= 8)
		{
			this.mainItem.element.get(0).style.removeAttribute('filter');
			this.nextItem.element.get(0).style.removeAttribute('filter');
		}

		this.mainItem.element.animate({
			"opacity":0,'left':'-1000px'
		},1000,function(){
			$(this).removeClass('active').css('display','none');
		});
		this.nextItem.element.css('display','block').animate({
			"opacity":1,'left':'0px'
		},1000,function(){
			$(this).addClass('active');
		});
	},
	backMove:function(){
		this.getItem();
		this.setItem();

		this.mainItem.element.animate({
			'right':'-1000px',
			'opacity':0
		},1000,function(){
			$(this).removeClass('active').css('display','none');
		});
		this.prevItem.element.css('display','block').animate({
			'left':'0px',
			'opacity':1
		},1000,function(){$(this).addClass('active')});
	}
}*/

var banner = {

	$page: $('.main-section02 .ctrl-info .page'),
	$total: $('.main-section02 .ctrl-info .tot'),
	$prev: $('.main-section02 .ctrl-info .prev'),
	$pause: $('.main-section02 .ctrl-info .pause'),
	$next: $('.main-section02 .ctrl-info .next'),
	$btns: $('.main-section02 .ctrl-info .control'),
	$items: $('.main-section02 .info > a'),
	index: 0,
	interval_key: {},

	init:function(){

		// total count setting
		this.$total.text(this.$items.size());

		// get index number
		this.$items.each(function(i){
			if($(this).attr('class')=="active") this.index = i;
		});

		// bind event
		this.$next.bind('click',function(e){
			e.preventDefault();
			banner.next();
		});
		this.$prev.bind('click',function(e){
			e.preventDefault();
			banner.prev();
		});
		this.$pause.toggle(function(){
			$(this).removeClass('pause').addClass('play');
			banner.stop();
		},function(){
			$(this).removeClass('play').addClass('pause');
			banner.play();
		});
		this.$btns.hover(function(){banner.stop();},function(){
			if($(banner.$pause).hasClass('pause')){
				banner.play();
			}
		});
		this.$items.hover(function(){banner.stop();},function(){
			if($(banner.$pause).hasClass('pause')){
				banner.play();
			}
		});

		// auto rolling play
		this.play();

	},
	next: function(){
		this.$items.eq(this.index).fadeOut(0,function(){
			if(jQuery.browser.msie){
				$(this).get(0).style.removeAttribute('filter');
			}
		});
		if(this.index+1 < this.$items.size()) this.index = this.index+1;
		else this.index = 0;
		this.$items.eq(this.index).fadeIn(0,function(){
			if(jQuery.browser.msie){
				$(this).get(0).style.removeAttribute('filter');
			}
		});
		this.$page.text(this.index+1)
	},
	prev: function(){
		this.$items.eq(this.index).fadeOut(0,function(){
			if(jQuery.browser.msie){
				$(this).get(0).style.removeAttribute('filter');
			}
		});
		if(this.index-1 >= 0) this.index = this.index-1;
		else this.index = this.$items.size()-1;
		this.$items.eq(this.index).fadeIn(0,function(){
			if(jQuery.browser.msie){
				$(this).get(0).style.removeAttribute('filter');
			}
		});
		this.$page.text(this.index+1)
	},
	play: function(){
		this.interval_key = setInterval(function(){banner.next()},3000);
	},
	stop: function(){
		clearInterval(banner.interval_key);
	}

}

var myicon = {
	bind:function(){
		$('.my-icon .prev').bind('click',function(e){
			e.preventDefault();
			$(this).hide();
			$(this).parent().find('.next').show();
			$(this).next('.wrap').animate({'left':'0'});
		});
		$('.my-icon .next').bind('click',function(e){
			e.preventDefault();
			$(this).parent().find('.prev').show();
			$(this).hide();
			$(this).prev('.wrap').animate({'left':'-310px'});
		});
	}
};


$(document).ready(function(e) {

	$('.board-link').hover(function(e){
		var index = $('.board-link').index($(this));
		$('.articleDetail').hide().eq(index).show();
		$('.board-link').removeClass('on');
		$(this).addClass('on');
	}/*,function(){
		$(this).removeClass('on');
	}*/);
	//carousel.init();
	banner.init();
	myicon.bind();
	
	/*마우스 커서*/
	$(".da-slider .ctrl-btn a").css("cursor", "pointer");
	$(".main-section02 .my-icon > a").css("cursor", "pointer");
});