jQuery(function($) {
	$('div.weekly-bestseller,div.event-banner,div.environment,div.luxury').tabs({ fxFade: true, fxSpeed: 'normal' });
	/* ÀÌº¥Æ® ¹è³Ê */
	var eventList = $('div.event-banner ul.menu');
	eventList.find('img').each(function(i) {
		if(i == 0) {
			$(this).attr("src",$(this).attr("src").replace("_off.gif", "_on.gif"));
		}
		$(this).click(function(){
			eventList.find('img').each(function() {
				$(this).attr("src",$(this).attr("src").replace("_on.gif", "_off.gif"));
			});
			$(this).attr("src",$(this).attr("src").replace("_off.gif", "_on.gif"));
		});
		$(this).mouseover(function(){
			eventList.find('img').each(function() {
				$(this).attr("src",$(this).attr("src").replace("_on.gif", "_off.gif"));
			});
			$(this).attr("src",$(this).attr("src").replace("_off.gif", "_on.gif"));
		});		
	});

	/* Ä£È¯°æ³ó»ê¹° */
	var environmentList = $('div.environment ul.menu');
	environmentList.find('img').each(function(i) {
		if(i == 0) {
			$(this).attr("src",$(this).attr("src").replace("_off.gif", "_on.gif"));
		}
		$(this).click(function(){
			environmentList.find('img').each(function() {
				$(this).attr("src",$(this).attr("src").replace("_on.gif", "_off.gif"));
			});
			$(this).attr("src",$(this).attr("src").replace("_off.gif", "_on.gif"));
		});
	});

	/* ¸íÇ°°ü */
	var luxuryList = $('div.luxury ul.menu');
	luxuryList.find('img').each(function(i) {
		if(i == 0) {
			$(this).attr("src",$(this).attr("src").replace("_off.gif", "_on.gif"));
		}
		$(this).click(function(){
			luxuryList.find('img').each(function() {
				$(this).attr("src",$(this).attr("src").replace("_on.gif", "_off.gif"));
			});
			$(this).attr("src",$(this).attr("src").replace("_off.gif", "_on.gif"));
		});
	});

	/* NHºê·£µå°ü */
	var nhList = $('div.nh-brand ul li');
	var thisList;
	var nhListFirst = $('div.nh-brand ul li:first-child');
	var currentNum = 0;
	var nextNum;
	nhList.find('p').hide();
	nhListFirst
		.find('h3').hide().end()
		.find('p').slideDown('slow').end();
	nhList.each(function(){
		$(this).click(function() {
			nhList
				.find('p').hide().end()
				.find('h3').show().end();
			$(this)
				.find('h3').hide().end()
				.find('p').slideToggle('slow').end();
		});
	});
	
	var active = false;
	$('div.nh-brand').everyTime(3000, 'controlled', function(i) {
		if(i < nhList.size() + 1) {
			currentNum =  i;
		} else {
			currentNum =  i % nhList.size();
			if(currentNum < 0)
				currentNum = nhList.size();
		}		
		nextNum = currentNum + 1;

		if(nextNum > nhList.size())
			nextNum = 1;
		
		nhList
			.find('p').hide().end()
			.find('h3').show().end();
		
		$('div.nh-brand ul li:nth-child('+ nextNum +')')
			.find('h3').hide().end()
			.find('p').slideToggle('slow').end();
		
	});
	$('div.nh-brand').mouseover(function() {
		$(this).stopTime('controlled');
	});
	
	$('div.nh-brand').mouseout(function() {
		$(this).everyTime(3000, 'controlled', function(i) {

			//alert(i);
			//alert(nhList.size());
			if(i < nhList.size() + 1) {
				currentNum =  i;
			} else {
				currentNum =  i % nhList.size();
				if(currentNum < 0)
					currentNum = nhList.size();
				if(currentNum == 0)
					currentNum = 5;
			}
		
			//alert(currentNum);

			if(currentNum > nhList.size())
				currentNum = 1;
			
			nhList
				.find('p').hide().end()
				.find('h3').show().end();
			
			$('div.nh-brand ul li:nth-child('+ currentNum +')')
				.find('h3').hide().end()
				.find('p').slideToggle('slow').end();
			
		});	
	});

	/* ÃßÃµ NH ½ºÅä¾î */
	var recommendNhstore =  $('div.recommend-nhstore');
	var itemScale = 2;
	var startCount = 1;
	var endCount = itemScale;
	var itemSize;
	var cnt = 1;
	
	if((recommendNhstore.find('li').size() % itemScale) == 0) {
		itemSize = recommendNhstore.find('li').size() / itemScale;
	} else {
		itemSize = Math.ceil(recommendNhstore.find('li').size() / itemScale);
	}
	
	
	recommendNhstore.find('li').each(function(i) {
		$(this).hide();
		if(i < itemScale) {
			$(this).show();
		}
		recommendNhstore.find('span.prev img').css({'opacity':'0.6','cursor':'default'});
	});

	recommendNhstore.find('span.prev').click(function() {
		if(cnt - 1 == 0) {
			recommendNhstore.find('span.prev img').css({'opacity':'0.6','cursor':'default'});
			return;
		} else {
			recommendNhstore.find('span.next img').css({'opacity':'1','cursor':'pointer'});
		}
		--cnt;
		if(endCount <= recommendNhstore.find('li').size()) {
			
			recommendNhstore.find('li').hide();
			startCount = startCount - itemScale;
			
			
			for(i = 0; i < itemScale; i++) {
				//alert("startCount + i="+(startCount+i));
				recommendNhstore.find('li:nth-child(' + (startCount+i) + ')').show();
			}
			
		}
		if(cnt - 1 == 0) {
			recommendNhstore.find('span.prev img').css({'opacity':'0.6','cursor':'default'});
			return;
		} else {
			recommendNhstore.find('span.next img').css({'opacity':'1','cursor':'pointer'});
		}
		
	});
	recommendNhstore.find('span.next').click(function() {
		
		if(cnt == itemSize) {
			return;
		}
		
		if(endCount <= recommendNhstore.find('li').size()) {
			recommendNhstore.find('li').hide();
			startCount = startCount + itemScale;
			
			
			for(i = 0; i < itemScale; i++) {
				//alert("startCount + i="+(startCount+i));
				recommendNhstore.find('li:nth-child(' + (startCount+i) + ')').show();
			}
		}
		
		if(++cnt == itemSize) {
			recommendNhstore.find('span.next img').css({'opacity':'0.6','cursor':'default'});
		} else {
			recommendNhstore.find('span.prev img').css({'opacity':'1','cursor':'pointer'});
		}
		
	});
	
	
	
	
});
/* Á¦ÈÞ¾÷Ã¼ */
jQuery(function($) {
	var affiliated =  $('div.affiliated');
	var affiliatedShopList = affiliated.find('ul li');
	var cnt;
	
	affiliated.everyTime(2000, 'affiliated', function(i) {
		if(i - 1 == 0)
			return;
		else(i - 1 != 0)
			cnt = (i - 1) % affiliatedShopList.size() + 1;
		
		affiliated
			.find('ul li')
			.each(function(n) {
				affiliated
					.find('ul li:nth-child(' + (n+1) + ')')
					.hide();
			})
			.end()
			.find('ul li:nth-child(' + (cnt) + ')')
			.fadeIn("slow")
			.end();
	});
	
	
});
/* ÇÑÁ¤Æ¯°¡ */
jQuery(function($) {
	var ceilingPrice =  $('div.ceiling-price');
	var itemScale = 1;
	var startCount = 1;
	var endCount = itemScale;
	var itemSize;
	var cnt = 1;
	
	if((ceilingPrice.find('li').size() % itemScale) == 0) {
		itemSize = ceilingPrice.find('li').size() / itemScale;
	} else {
		itemSize = Math.ceil(ceilingPrice.find('li').size() / itemScale);
	}
	
	
	ceilingPrice.find('li').each(function(i) {
		$(this).hide();
		if(i < itemScale) {
			$(this).show();
		}
		ceilingPrice.find('span.prev img').css({'opacity':'0.6','cursor':'default'});
	});

	ceilingPrice.find('span.prev').click(function() {
		if(cnt - 1 == 0) {
			ceilingPrice.find('span.prev img').css({'opacity':'0.6','cursor':'default'});
			return;
		} else {
			ceilingPrice.find('span.next img').css({'opacity':'1','cursor':'pointer'});
		}
		--cnt;
		if(itemScale <= ceilingPrice.find('li').size()) {
			
			ceilingPrice.find('li').fadeOut("slow");
			startCount = startCount - itemScale;
			for(i = 0; i < itemScale; i++) {
				ceilingPrice.find('li:nth-child(' + (startCount+i) + ')').fadeIn("slow");
			}
		}
		if(cnt - 1 == 0) {
			ceilingPrice.find('span.prev img').css({'opacity':'0.6','cursor':'default'});
			return;
		} else {
			ceilingPrice.find('span.next img').css({'opacity':'1','cursor':'pointer'});
		}
	});
	ceilingPrice.find('span.next').click(function() {
		if(cnt == itemSize) {
			return;
		}
		
		if(itemScale <= ceilingPrice.find('li').size()) {
			ceilingPrice.find('li').fadeOut("fast");
			startCount = startCount + itemScale;
			for(i = 0; i < itemScale; i++) {
				ceilingPrice.find('li:nth-child(' + (startCount+i) + ')').fadeIn("slow");
			}
		}
		
		if(++cnt == itemSize) {
			ceilingPrice.find('span.next img').css({'opacity':'0.6','cursor':'default'});
		} else {
			ceilingPrice.find('span.prev img').css({'opacity':'1','cursor':'pointer'});
		}
	});
});

/* ¼­ºñ½º¼¥ */
jQuery(function($) {
	var serviceShop =  $('div.service-shop');
	var serviceShopList = serviceShop.find('ul li');
	var cnt;
	
	var imgs1 = Array();
	var imgs2 = Array();
	for(i = 1; i < serviceShopList.size() + 1; i++){
		imgs1[i] = new Image();
		imgs2[i] = new Image();
		imgs1[i].src = "/images/main/service_shop0" + i + "_on.gif";
		imgs2[i].src = "/images/main/service_shop0" + i + "_off.gif";
		
	}
	
	serviceShop.everyTime(2000, 'controlled2', function(i) {
		if(i - 1 == 0)
			cnt = 1;
		else
			cnt = (i - 1) % serviceShopList.size() + 1;
		
		serviceShop
			.find('ul li')
			.each(function(n) {
				serviceShop
					.find('ul li:nth-child(' + (n+1) + ') a img')
					//.attr({src: "/images/main/service_shop0"+(n+1)+"_off.gif"});
					.attr({src: imgs2[n+1].src});
			})
			.end()
			.find('ul li:nth-child(' + (cnt) + ') a img')
			//.attr({src: "/images/main/service_shop0"+(cnt)+"_on.gif"})
			.attr({src: imgs1[cnt].src})
			.end()
			.find('p')
			.hide()
			.end()
			.find('p.photo_'+ (cnt))
			.fadeIn("slow")
			.end();
	});
});

/* ¸íÇ°°ü */
jQuery(function($) {
    var luxury =  $('div.luxury');
    var luxuryList = luxury.find('ul li');
    var cnt;

    var imgs1 = Array();
    var imgs2 = Array();
//    for(i = 1; i < luxuryList.size() + 1; i++){
//        imgs1[i] = new Image();
//        imgs2[i] = new Image();
//        imgs1[i].src = "/images/main/tab_luxury0" + i + "_on.gif";
//        imgs2[i].src = "/images/main/tab_luxury0" + i + "_off.gif";
//    }

	$('div.luxury ul.menu').find('img').each(function(i) {
        imgs1[i+1] = new Image();
        imgs2[i+1] = new Image();
		imgs1[i+1].src = $(this).attr("src").replace("_off.gif", "_on.gif");
        imgs2[i+1].src = $(this).attr("src").replace("_on.gif", "_off.gif");
    });

    luxury.everyTime(2000, 'controlled3', function(i) {
        if(i - 1 == 0)
            cnt = 1;
        else
            cnt = (i - 1) % luxuryList.size() + 1;

        luxury
            .find('ul li')
            .each(function(n) {
                luxury
                    .find('ul li:nth-child(' + (n+1) + ') a img')
                    .attr({src: imgs2[n+1].src});
            })

        luxury
            .find('ul li:nth-child(' + (cnt) + ') a')
            .click();
        luxury
            .find('ul li:nth-child(' + (cnt) + ') a img')
            .attr({src: imgs1[cnt].src});
    });
});