(function($) {
	
	var cur_index = 0;

	function changeBestReview(i){	
		$('ul.bestReviewTab li').each(function(index){
			var src = $('ul.bestReviewTab li:eq(' + index + ') img').attr('src');
			src = src.replace('On.gif', '.gif');
			$('ul.bestReviewTab li:eq(' + index + ') img').attr('src', src);
		});

		var cur_src = $('ul.bestReviewTab li:eq(' + i + ')').children().attr('src');			
		cur_src = cur_src.replace('.gif', 'On.gif');
		$('ul.bestReviewTab li:eq(' + i + ')').children().attr('src', cur_src);

		$('div.bestReviewList > div').hide();
		$('div.bestReviewList > div:eq(' + i + ')').show();
		
		cur_index += 1;
		if ( cur_index > 2 ) cur_index = 0;
	}
	
	// BEST REVIEW ÀÌ¹ÌÁö ·Ñ¸µ Ã³¸®
	/*
	$(function() {
		$('ul.bestReviewTab li').css('cursor', 'pointer');
		$('ul.bestReviewTab li').mouseover(function(){			
			var index = $(this).prevAll().length;
			clearInterval(alertTimerId);
			changeBestReview(index);			
		});
		$('div.bestReview').mouseover(function(){			
			clearInterval(alertTimerId);
		});		
		$('div.bestReview').mouseout(function(){			
			alertTimerId = setInterval ( function(){changeBestReview(cur_index)}, 3000 );
		});
	});
	
	alertTimerId = setInterval ( function(){changeBestReview(cur_index)}, 3000 );
	*/

	// MD'S PICK Ç°¸ñ ÅÇ ÀÌº¥Æ® Ã³¸® 
	$(function() {
		$('ul.mdsPickTab').css('cursor', 'pointer');
		$('ul.mdsPickTab li').mouseover(function(){
			var index = $(this).prevAll().length;
			
			$('ul.mdsPickTab li').each(function(index){
				var src = $('ul.mdsPickTab li:eq(' + index + ') img').attr('src');
				src = src.replace('On.gif', '.gif');
				$('ul.mdsPickTab li:eq(' + index + ') img').attr('src', src);
			});
			
			var cur_src = $(this).children().attr('src');			
			cur_src = cur_src.replace('.gif', 'On.gif');
			$(this).children().attr('src', cur_src);
			
			$('ul.mdsPickList').hide();
			$('ul.mdsPickList:eq(' + index + ')').show();
		});
	});
	
	// BEST SPECIAL 
		// 1. Brand Best 100
		// 2. Hot Item
		
	$(function() {
		var c_idx = 0;
		var f_slide = true;
		var s_slide = true;
		
		$('#bestSpecialList1 ul').each(function(index){
			var left = index * 762;
			$('#bestSpecialList1 ul:eq(' + index + ')').css({
				'position'	: 'absolute',
				'top'		: '0px',
				'left'		: left + 'px'
			});
		});
		
		$('#bestSpecialList2 ul').each(function(index){
			var left = index * 762;
			$('#bestSpecialList2 ul:eq(' + index + ')').css({
				'position'	: 'absolute',
				'top'		: '0px',
				'left'		: left + 'px'
			});
		});
		
		function move_r(id) {
			if ( id == '1' ) f_slide = false;
			if ( id == '2' ) s_slide = false;
			
			var cnt = $('#bestSpecialList' + id + ' ul').length;
			//if ( cnt == 3 && c_idx != 0 ) {
			//	$('#bestSpecialList1 ul:first').remove();
			//}
			
			var html = $('#bestSpecialList' + id + ' ul:first').html();			
			var last_left = $('#bestSpecialList' + id + ' ul:last').position().left;
			last_left += 762;
			$('#bestSpecialList' + id).append("<ul>" + html + "</ul>");
			
			$('#bestSpecialList' + id + ' ul:last').css({
				'position'	: 'absolute',
				'top'		: '0px',
				'left'		: last_left + 'px'
			});
			var cnt = 0;
			$('#bestSpecialList' + id + ' ul:last').addClass("bestSpecialList");

			$('#bestSpecialList' + id + ' ul').animate({
				left : '-=762'
			}, 500, function(){
				c_idx += 1;
				cnt++;
				if ( cnt == $('#bestSpecialList' + id + ' ul').length ) { 
					if ( id == '1' ) f_slide = true;
					if ( id == '2' ) s_slide = true;
					$('#bestSpecialList' + id + ' ul:first').remove();
				}
			})
		}
		
		function move_l(id) {
			if ( id == '1' ) f_slide = false;
			if ( id == '2' ) s_slide = false;
			
			var cnt = $('#bestSpecialList' + id + ' ul').length;
			//if ( cnt == 3 && c_idx > 0 ) {
			//	$('#bestSpecialList1 ul:first').remove();
			//}
			
			var html = $('#bestSpecialList' + id + ' ul:last').html();
			var first_left = $('#bestSpecialList' + id + ' ul:first').position().left;
			first_left -= 762;
			$('#bestSpecialList' + id).prepend("<ul>" + html + "</ul>");
			$('#bestSpecialList' + id + ' ul:last').remove();
			
			$('#bestSpecialList' + id + ' ul:first').css({
				'position'	: 'absolute',
				'top'		: '0px',
				'left'		: first_left + 'px'
			});
			var cnt = 0;
			$('#bestSpecialList' + id + ' ul:first').addClass("bestSpecialList");

			$('#bestSpecialList' + id + ' ul').animate({
				left : '+=762'
			}, 500, function(){
				c_idx -= 1;					
				cnt++;
				if ( cnt == $('#bestSpecialList' + id + ' ul').length ) {
					if ( id == '1' ) f_slide = true;
					if ( id == '2' ) s_slide = true;
					//$('#bestSpecialList' + id + ' ul:last').remove();
				}
			});
		}
		
		$('img.rScrollBtn:eq(0)').click(function(){
			if ( f_slide ) move_r('1');
		});
		$('img.rScrollBtn:eq(1)').click(function(){
			if ( s_slide ) move_r('2');
		});
		
		$('img.lScrollBtn:eq(0)').click(function(){
			if ( f_slide ) move_l('1');
		});
		$('img.lScrollBtn:eq(1)').click(function(){
			if ( s_slide ) move_l('2');
		});
		
	});	

	// ¸ÞÀÎ ºñÁÖ¾ó ÇÁ·Î¸ð¼Ç ( ¸ÞÀÎ ÇÁ·Î¸ð¼Ç ÀÌ¹ÌÁö )
	$(function() {
		$('img.visualSelect').css('cursor', 'pointer');
		$('div.selectMainPromotion img.visualSelect').mouseover(function(){
			var index = $(this).prevAll().length;
			$("#mainVisual img").hide();
			$("#mainVisual img:eq(" + index + ")").show();
		});
	});

	// HOT TREND 5 ½½¶óÀÌµù
	$(function() {
		var c_idx = 0;
		var f_slide = true;
		
		$('div.hotTrandProd div.products').each(function(index){
			var left = index * 773;
			$('div.hotTrandProd div:eq(' + index + ')').css({
				'position'	: 'absolute',
				'top'		: '0px',
				'left'		: left + 'px'
			});
		});
		
		function move_r() {
			f_slide = false;
			
			var cnt = $('div.hotTrandProd div').length;
			
			var html = $('div.hotTrandProd div:first').html();
			var last_left = $('div.hotTrandProd div:last').position().left;
			last_left += 773;
			
			$('div.hotTrandProd').append("<div>" + html + "</div>");
			
			$('div.hotTrandProd div:last').css({
				'position'	: 'absolute',
				'top'		: '0px',
				'left'		: last_left + 'px'
			});
			var cnt = 0;
			$('div.hotTrandProd div:last').addClass("products");

			$('div.hotTrandProd div').animate({
				left : '-=773'
			}, 500, function(){
				c_idx += 1;
				cnt++;
				if ( cnt == $('div.hotTrandProd div').length ) { 
					f_slide = true;
				}
			})
		}
		
		function move_l() {
			f_slide = false;
			
			var cnt = $('div.hotTrandProd div').length;
			
			var html = $('div.hotTrandProd div:last').html();
			var first_left = $('div.hotTrandProd div:first').position().left;
			first_left -= 773;
			$('div.hotTrandProd').prepend("<div>" + html + "</div>");
			//$('div.hotTrandProd div:last').remove();
			
			$('div.hotTrandProd div:first').css({
				'position'	: 'absolute',
				'top'		: '0px',
				'left'		: first_left + 'px'
			});
			var cnt = 0;
			$('div.hotTrandProd div:first').addClass("products");

			$('div.hotTrandProd div').animate({
				left : '+=773'
			}, 500, function(){
				c_idx -= 1;					
				cnt++;
				if ( cnt == $('div.hotTrandProd div').length ) {
					f_slide = true;
				}
			});
		}
		
		$('img.rScrollBtn1:eq(0)').click(function(){
			if ( f_slide ) move_r();
		});
		
		$('img.lScrollBtn1:eq(0)').click(function(){
			if ( f_slide ) move_l();
		});
		
	});	


})(jQuery);

