(function($){
	$(function(){
		$('.lb .no').hide();
			   
		//return top
		$('.return a').click(function(){
			if($('body').scrollTop() != 0){
				$('body').animate({'scrollTop':'0'},300);
			}
			if($('html').scrollTop() != 0){
				$('html').animate({'scrollTop':'0'},300);
			}
			return false;
		});
			   
		//rollover
		$('a img').hover(
			function(){
				if(!$(this).hasClass('false')){
					$(this).attr('src',$(this).attr('src').replace('_off', '_on'));
				}
			},
			function(){
				if(!$(this).hasClass('cur')){
					$(this).attr('src',$(this).attr('src').replace('_on', '_off'));
				}
			}
		);
		
		//header
		$('#home').parent('a').addClass('home');
		$('#search a').eq(0).addClass('achileesHome');
		
		//footer
		$('#grovalfooter .groval760 .f03').live('click',function(){
			return false;										 
		});
		
		//footSearch
		$('#footSearch .form dl').hide();
		$('#footSearch .ui li img').click(function(){
			var name = $(this).parents('ul').attr('class').split(' ');
			var num = $('#footSearch .ui .' + name[0] + ' li img').index(this);
			if(name[0] != 'genre'){
				if(num != 0){
					$('#footSearch .ui .' + name[0] + ' li img').eq(0).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(0).attr('src').replace('_on','_off'));
					if($('#footSearch .form .' + name[0] + ' input').eq(num - 1).attr('checked')){
						$('#footSearch .form .' + name[0] + ' input').eq(num - 1).attr('checked',false);
						$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src').replace('_on','_off'));
						var flag = true;
						for(var i = 0;i < $('#footSearch .ui .' + name[0] + ' li').size();i++){
							if($('#footSearch .ui .' + name[0] + ' li img').eq(i).attr('src').indexOf('_on') != -1){
								flag = false;
								break;
							}
						}
						if(flag){
							$('#footSearch .ui .' + name[0] + ' li img').eq(0).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(0).attr('src').replace('_off','_on'));
						}
					}
					else{
						$('#footSearch .form .' + name[0] + ' input').eq(num - 1).attr('checked',true);
						$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src').replace('_off','_on'));
					}
				}
				else{
					$('#footSearch .form .' + name[0] + ' input').attr('checked',false);
					for(var i = 0;i < $('#footSearch .ui .' + name[0] + ' li').size();i++){
						$('#footSearch .ui .' + name[0] + ' li img').eq(i).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(i).attr('src').replace('_on','_off'));
					}
					$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src').replace('_off','_on'));
				}
			}
			else{
				$('#footSearch .form .' + name[0] + ' input').eq(num).attr('checked',true);
				for(var i = 0;i < $('#footSearch .ui .' + name[0] + ' li').size();i++){
					$('#footSearch .ui .' + name[0] + ' li img').eq(i).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(i).attr('src').replace('_on','_off'));
				}
				$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src',$('#footSearch .ui .' + name[0] + ' li img').eq(num).attr('src').replace('_off','_on'));
			}
		});
		
		var footSearchBtm = ($('#footSearch').height() - 5) * -1;
		$('#footSearch').css('bottom',footSearchBtm + 'px');
		var footSearchFlag = true;
		$('#footSearch .slideBtn img').click(
			function(){
				if(footSearchFlag){
					footSearchFlag = false;
					$('#footSearch').stop().animate({'bottom':'0'},500);
				}
				else{
					footSearchFlag = true;
					$('#footSearch').stop().animate({'bottom':footSearchBtm + 'px'},400);
				}
			}
		);
		$('#footSearch').mouseleave(
			function(){
				footSearchFlag = true;
				$('#footSearch').stop().animate({'bottom':footSearchBtm + 'px'},400);
			}
		);
		
		//new
		var newItemNum = $('#content .side .new ul li').size();
		var newItemHeight = 0;
		for(var i = 0;i < newItemNum;i++){
			if(i == 0){
				$('#content .side .new ul li').eq(i).css('left',10 + 'px');
			}
			else{
				$('#content .side .new ul li').eq(i).css('left',110 * i + 10 + 'px');
			}
			if($('#content .side .new ul li').eq(i).height() > newItemHeight){
				newItemHeight = $('#content .side .new ul li').eq(i).height();
			}
		}
		$('#content .side .new ul').height(newItemHeight);
		$('#content .side .new .prev').css('top',(newItemHeight - 17) / 2 + 15 + 'px');
		$('#content .side .new .next').css('top',(newItemHeight - 17) / 2 + 15 + 'px');
		var newItemFlag = 0;
		$('#content .side .new .prev').hide();
		$('#content .side .new .prev').click(
			function(){
				$('#content .side .new ul li').animate({'left':'+=110px'},500);
				newItemFlag--;
				if(newItemFlag == 0){
					$('#content .side .new .prev').hide();
				}
				else{
					$('#content .side .new .next').show();
				}
			}
		);
		$('#content .side .new .next').click(
			function(){
				$('#content .side .new ul li').animate({'left':'-=110px'},500);
				newItemFlag++;
				if(newItemFlag == (newItemNum - 2)){
					$('#content .side .new .next').hide();
				}
				else{
					$('#content .side .new .prev').show();
				}
			}
		);
		
		//LightBox
		$('body').append('<div id="lightBoxBg"></div>');
		$('#lightBoxBg').hide();
		$('body').append('<div id="lightBox"></div>');
		$('#lightBox').hide();
		var colorAry = new Array('syunsoku','skechers','spalding','achilles_sorbo','benetton','marieclaire','rurubu','puchipio','flashpal','helthylife','character','boots','mineRelax','amane');
		$('.lb').click(function(){
			var no = $(this).children('.no').text().replace('(','').replace(')','');
			var color = $(this).children('img').attr('src').replace('/common/shoesImg/','').replace(no + '_','').replace('_100x100.jpg','');
			for(var i = 0;i < 14;i++){
				color = color.replace(colorAry[i] + '/','');
			}
			$('#lightBoxBg').height($(document).height());
			LightBoxGet(no,color);
		});
		function LightBoxGet(no,color){
			$.get(
				'/common/tmp/lightBox.php?no=' + no + '&defColor=' + color,
				null,
				function(data,status){
					$('#lightBox').html(data);
					$('#lightBox').css('top',($(window).height() - $('#lightBox').height()) / 2 + $(document).scrollTop());
					$('#lightBoxBg').fadeTo(500,0.5);
					$('#lightBox').fadeIn(500);
					var height = 0;
					for(var i = 0;i < $('#lightBox .rightBox .list01 li').size();i++){
						if($('#lightBox .rightBox .list01 li').eq(i).height() > height){
							height = $('#lightBox .rightBox .list01 li').eq(i).height();
						}
					}
					for(var i = 0;i < $('#lightBox .rightBox .list01 li').size();i++){
						$('#lightBox .rightBox .list01 li').eq(i).height(height);
					}
				},
				'html'
			);
		}
		$('#lightBoxBg').click(function(){
			lightBoxClose();
		});
		$('#lightBox .close').live('click',
			function(){
				lightBoxClose();
			}
		);
		$('#lightBox .function .btn').live('click',
			function(){
				var href1 = window.location.href;
				var href2 = $(this).children('a').attr('href').split('#');
				if((href1.lastIndexOf(href2[0])) != -1) {
					lightBoxClose();
				}
			}
		);
		function lightBoxClose(){
			$('#lightBoxBg').fadeOut(300);
			$('#lightBox').fadeOut(300);
		}
		$('#lightBox .rightBox li').live('click',
			function(){
				$('#lightBox .rightBox li').removeClass('cur');
				$(this).addClass('cur');
				var src = $(this).children('img').attr('src');
				src = src.replace('60x60','400x400');
				$('#lightBox .view img').attr('src',src);
			}
		);
		
		//img
		$('img').live('mousedown',function(){return false;}).live('contextmenu',function(){return false;});
	});

})(jQuery);
