/**
 * @name index.js
 * (c) United Arrows Ltd.
 */

(function($){
	$(function() {


	//carouselBoxHeightSet();
			


	/*#carouselBoxMens*/
		$("#carouselBoxMens").carouFredSel({
			scroll :{
				items : 4,
				duration : 1500
			}, 
			auto :{
				play:false
			},
		items : 4,
		width : "620px",
		next : {
			button : "#mensItemArea .btNext"
		},
		prev : {
			button : "#mensItemArea .btPrev"
		}
		 });
	/*#carouselBoxWomens*/
		$("#carouselBoxWomens").carouFredSel({
			scroll :{
				items : 4,
				duration : 1500
			}, 
			auto :{
				play:false
			},
		items : 4,
		width : "620px",
		next : {
			button : "#womensItemArea .btNext"
		},
		prev : {
			button : "#womensItemArea .btPrev"
		}
		 });
		
		//append radius
		$('.radius').each(function(){
		$(this)
		.css('position','relative')
		.append('<div class="radiusImg tl"><img src="/imgs/index/radius-tl.png"></div>')
		.append('<div class="radiusImg tr"><img src="/imgs/index/radius-tr.png"></div>')
		.append('<div class="radiusImg bl"><img src="/imgs/index/radius-bl.png"></div>')
		.append('<div class="radiusImg br"><img src="/imgs/index/radius-br.png"></div>')
		.find('div.radiusImg')
		.css('position','absolute')
		.end()
		.find('div.tl')
		.css('top','0px')
		.css('left','0px')
		.find('img').css('vertical-align','top').end()
		.end()
		.find('div.tr')
		.css('top','0px')
		.css('right','0px')
		.find('img').css('vertical-align','top').end()
		.end()
		.find('div.bl')
		.css('bottom','0px')
		.css('left','0px')
		.find('img').css('vertical-align','bottom').end()
		.end()
		.find('div.br')
		.css('bottom','0px')
		.css('right','0px')
		.find('img').css('vertical-align','bottom').end()
		.end()
		.end();
		$.autoEnablePNG();
		});	
		
		
		// slider
		var
			slider,
			mainVisualArea,
			mainVisualImg,
			thumbList
		;
		
		$(function(){
			$("#slide").each(function(){
									  
				var cnt = 0;
				var intervalID;
									  
				slider = $(this);
				mainVisualArea = slider.find(".mainVisual");
				mainVisualImg = mainVisualArea.find("img");
				thumbList = slider.find(".thumbs li");
				thumbAList = slider.find(".thumbs li a");
				thumbList.find("imgs").each(function(){
					var img = new Image();
					img.src = this.src;
				})

				thumbList.find("a").each(function(){
					$(this).attr("_href",$(this).attr("rel"))
					$(this).hover( 
						function(){
							cnt = thumbList.index( $(this).parent());
							clearInterval(intervalID);
							focus( $(this) , 400 );
						}
						,function(){
							intervalID = setInterval(intervalFunc, 5000);
						})
				});

				intervalID = setInterval(intervalFunc, 5000);
				focus( thumbAList.first() );

				function focus( a , speed ){
					var s = 1000;
					if( speed ){
						s = speed;
					}
					thumbAList.removeClass( "on" );
					a.addClass("on");
					mainVisualArea
						.height(mainVisualImg.height())
						.css("background", "transparent url("+mainVisualImg.attr("src")+") no-repeat left top")
					;
					mainVisualArea.find("a").attr( "href" , a.attr("href") )
						.attr( "target" , a.attr("target") )
					mainVisualImg
						.hide()
						.attr("src", a.attr("_href"))
						.attr( "alt" , a.text() )
						.fadeIn( s );
				}

				function intervalFunc(){
					cnt++;
					var arr = thumbList.get();
					if(cnt == arr.length) cnt = 0;
					focus( $(arr[cnt]).find("a") );
				}
				
			});

			$(".resize").each(function(){
				$(this).easyThumbnail().show();
			});
			
			//news
			$("#newsBox li:last").addClass("last");
			
			//news
			if( $("#infoSection").length ) {
				var left_height = $("#hotIntems").height() + $("#styling").height() + 40;
                left_height = 448;
				while( left_height < $("#newsSection").height() ){
					$("#newsBox li:last").remove();
					$("#newsBox li:last").addClass("last");
				}
				$("#newsSection").css( "height" ,  left_height -1  );
			}else{
				$("#newsSection").css("margin-bottom","0");
//				var left_height = $("#hotIntems").height() + $("#styling").height() + $("#blog").height() + 80;
                var left_height = 448;
 				while( left_height < $("#newsSection").height() ){
					$("#newsBox li:last").remove();
					$("#newsBox li:last").addClass("last");
				}
			}
		});
	});
})(jQuery);
