/* No need to change anything after this */
	$.bannerGallery = {
		MAIN_OBJ : "",
		SUBS_OBJ : "",
		INDEX : 0,
		SPEED : 1000,
		TIMER : 10000,
		INTERVAL : null,
		
		init : function () {
			$.bannerGallery.MAIN_OBJ = $("#main-banner-list li");
			$.bannerGallery.MAIN_OBJ
				.hide()
			    .bind("click", this.main_click)
			    .bind("mouseout", this.exit)
			    .bind("mouseover", function(){$.bannerGallery.stop()})
			    .eq(0).fadeIn($.bannerGallery.SPEED);
			
			$.bannerGallery.SUBS_OBJ = $("#sub-banner-list li a");
			$.bannerGallery.SUBS_OBJ
				.bind("click", this.sub_click)
				.bind("mouseover", this.enter)
				.bind("mouseout", this.exit)
				.eq(0).addClass("current");
			                        
			$.bannerGallery.INTERVAL = setInterval($.bannerGallery.play, $.bannerGallery.TIMER);
		},
		enter : function() {
			$.bannerGallery.stop();
			
			var $obj = $(this);
			var $index = $.bannerGallery.SUBS_OBJ.index(this);
			$.bannerGallery.INDEX = $index;
			
			if ($obj.hasClass("current")) return;
			
			$.bannerGallery.MAIN_OBJ
				.hide()
				.css("z-index", "1");
			$.bannerGallery.MAIN_OBJ
				.eq($index).css("z-index", "100")
				.fadeIn($.bannerGallery.SPEED);
			$.bannerGallery.SUBS_OBJ.removeClass("current");
			$obj.addClass("current");
		},
		play : function() {
			var $num = ($.bannerGallery.INDEX < $.bannerGallery.SUBS_OBJ.size() - 1)? ++$.bannerGallery.INDEX : 0;
			
			$.bannerGallery.MAIN_OBJ
				.hide()
				.css("z-index", "1");
			$.bannerGallery.MAIN_OBJ
				.eq($num).css("z-index", "100")
				.fadeIn($.bannerGallery.SPEED, function(){
					$.bannerGallery.SUBS_OBJ.removeClass("current");
					$.bannerGallery.SUBS_OBJ.eq($num).addClass("current");
					$.bannerGallery.INDEX = $num;
				});
		},
		main_click : function() {
			var $obj = $(this);
			var $index = $.bannerGallery.MAIN_OBJ.index(this) + 1;
			banner_track('/banner/top/01/main0' + $index);
		},
		sub_click : function() {
			var $obj = $(this);
			var $index = $.bannerGallery.SUBS_OBJ.index(this) + 1;
			banner_track('/banner/top/01/sub0' + $index);
		},
		exit : function() {
			$.bannerGallery.INTERVAL = setInterval($.bannerGallery.play, $.bannerGallery.TIMER);
		},
		stop : function() {
			clearInterval($.bannerGallery.INTERVAL);
			$.bannerGallery.INTERVAL = null;
		}
	}
	
	$(document).ready(function() {
		$.bannerGallery.init();
	});
