$(document).ready(function(){
	
	//MAIN ·Ñ¸µ
	 var i =0;
		var interval="";
     function formatText(index, panel) {
		  return index + "";
	    }
		
		function fadeInOuts(){
		
			if (i>=2){
			   $('.view').fadeOut(3000);
			   $('.view:eq(0)').fadeIn(3000);			 
			   i=0;	
			}
			else{
				 $('.view').fadeOut(3000);
				 i=i+1;
				 $('.view:eq('+i+')').fadeIn(3000);					
				}
		}
		function delay(){
			 interval_go();
			setTimeout(interval_go,8000);
			}

			function interval_go(){
			 interval = setInterval(fadeInOuts,8000);
			}
			interval_go();			
			
			//store
			$('.menuArea li ').hover(function() {
				if($(this).is('.on')){	
					// mouseover
					var menuimg = $(this).children().attr("src");
					$(this).children().attr('src',menuimg.replace('On.png','On.png'));	
				}else {			
		 			// mouseover
					var menuimg = $(this).children().attr("src");
					$(this).children().attr('src',menuimg.replace('Off.png','On.png'));
				}			
		 		}, function() {
		 			if($(this).is('.on')){	
						// mouseover
						var menuimg = $(this).children().attr("src");
						$(this).children().attr('src',menuimg.replace('On.png','On.png'));	
					}else {			
			 			// mouseover
						var menuimg = $(this).children().attr("src");
						$(this).children().attr('src',menuimg.replace('On.png','Off.png'));					
					}
				});
			$('.menuArea li').css('cursor','pointer');	
			$('.menuArea li').click(function(){
				$('.storeAddress').show();
				var id = $(this).attr('id');
				var map = "."+id;
				$('.storeMenu').hide();
				$(map).show();
				$(map).children().children().eq(0).addClass('on');				
				var img = $(map).children().children().eq(0).children().attr("alt");
				//alert(img);
				$('#storeMap').children().attr('src','/images/store/map/'+img+'.png');
				$('.storeAddress').children().attr('src','/images/store/address/'+img+'.png');

				var menuimg2 = $(this).children().attr("src");				
				var menuimg3 = $('.menuArea li.on').children().attr("src");
				$('.menuArea li.on').children().attr('src',menuimg3.replace('On.png','Off.png'));
				$('.menuArea li.on').removeClass('on');
				$(this).addClass('on');
				$(this).children().attr('src',menuimg2.replace('On.png','On.png'));			
			});	
			
						
			$('.storeMenu li a').click(function(){
				$('.storeAddress').show();
				var img = $(this).attr("alt");			
				//alert(img);
				$('.storeMenu li.on').removeClass('on');
				$(this).parent().addClass('on');
				$('#storeMap').children().attr('src','/images/store/map/'+img+'.png');
				$('.storeAddress').children().attr('src','/images/store/address/'+img+'.png');
			});
			
			
			
			//star lookbook 
			$('#starList > a').click(function(){
				var big = $(this).children().attr("alt");			
				$('#layerstyle').children().children().attr('src','');
				$('#layerstyle').children().attr('src','/images/style/big/'+big+'.png');
				$('#layerstyle').show();
			});
			
			$('#lookList > a').click(function(){
				var big = $(this).children().attr("alt");		
				$('#layerstyle').children().children().attr('src','');
				$('#layerstyle').children().children().attr('src','/images/style/big/'+big+'.png');
				$('#layerstyle').show();
			});
			
			// collection			
			$('#cyworld').click(function(){
				var cyworldImg = $("#thumbNav a").index($("#thumbNav a.cur")[0]);				
				var collectImg = $(".collectionList li").eq(cyworldImg).children().attr('src');				
				var collection = collectImg.substr(collectImg.lastIndexOf("/") + 1);
				//alert(collection);				
			});
			
			// collection
			$('#layerstyle .pre').click(function(){
				var lookSom = $("#lookList a").size();				
				var lookBig = $("#layerstyle .close").find('img').attr("src");
				var lookBig2 = lookBig.substr(lookBig.lastIndexOf("/") + 1);
				var lookBig3 = lookBig2.substring(0, lookBig2.length - 4);
				var lookLok = $("#lookList img").index($("#lookList img[alt='"+lookBig3+"']")[0]) - 1;
				var nextimg = $("#lookList img").eq(lookLok).attr("alt");
				
				if(lookSom == lookLok ){
					$('.pre').show();
					$('.next').hide();
				} else if (lookLok == 0){
					$('.next').show();
					$('.pre').hide();
				} else {
					$('.next').show();
					$('.pre').show();
				}
					
				$('#layerstyle').children().children().attr('src','');
				$('#layerstyle').children().children().attr('src','/images/style/big/'+nextimg+'.png');
				$('#layerstyle').show();
							
			});
			$('#layerstyle .next').click(function(){
				var lookSom = $("#lookList a").size();
				var lookSom2 = $("#lookList a").size()-1;
				var lookBig = $("#layerstyle .close").find('img').attr("src");
				var lookBig2 = lookBig.substr(lookBig.lastIndexOf("/") + 1);
				var lookBig3 = lookBig2.substring(0, lookBig2.length - 4);
				var lookLok = $("#lookList img").index($("#lookList img[alt='"+lookBig3+"']")[0]) + 1;
				var nextimg = $("#lookList img").eq(lookLok).attr("alt");
				
				if(lookSom2 == lookLok ){
					$('.pre').show();
					$('.next').hide();
				} else if (lookLok == 0){
					$('.next').show();
					$('.pre').hide();
				} else {
					$('.next').show();
					$('.pre').show();
				}
				
					$('#layerstyle').children().children().attr('src','');
					$('#layerstyle').children().children().attr('src','/images/style/big/'+nextimg+'.png');
					$('#layerstyle').show();
			});
			
			$('#lookList > a').click(function(){
			var lookSom2 = $("#lookList a").size();
			var lookLok2 = $(this).index()+1;
				//alert(lookSom2);
				//alert(lookLok2);
			if(lookSom2 == lookLok2 ){
				$('.pre').show();
				$('.next').hide();
			} else if (lookLok2 == 1){
				$('.next').show();
				$('.pre').hide();
			} else {
				$('.next').show();
				$('.pre').show();
			}
			
			});
			
			
			$('#blogLclose').click(function(){
				$('#layerBlog').hide();
			});	
			$('.blogX img').click(function(){
				$('#layerBlog').hide();
			});
			$('#blogLopen').click(function(){
				
				$('#layerBlog').show();
				//alert(1);
			});	
			//deemed
			var deemedW = $('#layerPop').width()/2;
			var deemedH = $('.join01').height()/2;
			var deemed1W = $('#layerFind').width()/2;
			var deemed1H = $('#layerFind').height()/2;
			var deemed2W = $('#layerLogin').width()/2;
			var deemed2H = $('#layerLogin').height()/2;
			var deemed3W = $('#layerProject').width()/2;
			var deemed3H = $('#layerProject').height()/2;
			
			$('#layerPop').css("top", "50%").css("left", "50%");
			$('#layerPop').css("margin-top", -deemedH).css("margin-left", -deemedW);
			$('#layerFind').css("top", "50%").css("left", "50%");
			$('#layerFind').css("margin-top", -deemed1H).css("margin-left", -deemed1W);
			$('#layerLogin').css("top", "50%").css("left", "50%");
			$('#layerLogin').css("margin-top", -deemed2H).css("margin-left", -deemed2W);
			$('#layerProject').css("top", "50%").css("left", "50%");
			$('#layerProject').css("margin-top", -deemed3H).css("margin-left", -deemed3W);
			
			//alert(deemedH);
			// GNB È°¼ºÈ­	
		var site = function() {
			this.navLi = $('#nav li').children('ul').hide().end();
			
			this.init();
		};		
		site.prototype = {		 	
		 	init : function() {
		 		this.setMenu();
		 	},		 	
		 	setMenu : function() {		 	
		 		this.navLi.hover(function() {
		 			// mouseover
					$(this).find('> ul').stop(true, true).slideDown('slow', 'swing');
		 		}, function() {
		 			// mouseout
		 			$(this).find('> ul').stop(true, true).hide();	
				});		 		
		 	}		 
		}		
		new site();
		
		var thisUrl = window.location;
		var thisIndex = thisUrl.toString().substring(thisUrl.toString().lastIndexOf("/")+1);
		
		if(thisIndex == "campaign.asp" || thisIndex =="winter.asp"|| thisIndex =="fall.asp"|| thisIndex =="summer.asp"|| thisIndex =="spring.asp"){
			
			var gnbImgon = $('img[alt=Collection]').attr("src");
			$('.gnb img[alt=Collection]').attr('src',gnbImgon.replace('Off.png','On.png'));
			
			$('.gnb > li').hover(function(){
				if($(this).children().children().is('img[alt=Collection]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Collection]').attr("src");
					$('.gnb img[alt=Collection]').attr('src',gnbImgon.replace('On.png','Off.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
			}
			},function(){
				if($(this).children().children().is('img[alt=Collection]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Collection]').attr("src");
					$('.gnb img[alt=Collection]').attr('src',gnbImgon.replace('Off.png','On.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
				}
			})
		}
	
		if(thisIndex == "lookbook.asp" || thisIndex =="withestar.asp"){
			
			
			var gnbImgon = $('img[alt=Style]').attr("src");
			$('.gnb img[alt=Style]').attr('src',gnbImgon.replace('Off.png','On.png'));
			
			$('.gnb > li').hover(function(){
				if($(this).children().children().is('img[alt=Style]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Style]').attr("src");
					$('.gnb img[alt=Style]').attr('src',gnbImgon.replace('On.png','Off.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
			}
			},function(){
				if($(this).children().children().is('img[alt=Style]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Style]').attr("src");
					$('.gnb img[alt=Style]').attr('src',gnbImgon.replace('Off.png','On.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
				}
			})			
		}
		if(thisIndex == "blog_list.asp" || thisIndex =="blog_detail.asp"){
			var gnbImgon = $('img[alt=Blog]').attr("src");
			$('.gnb img[alt=Blog]').attr('src',gnbImgon.replace('Off.png','On.png'));
			
			$('.gnb > li').hover(function(){
				if($(this).children().children().is('img[alt=Blog]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Blog]').attr("src");
					$('.gnb img[alt=Blog]').attr('src',gnbImgon.replace('On.png','Off.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
			}
			},function(){
				if($(this).children().children().is('img[alt=Blog]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Blog]').attr("src");
					$('.gnb img[alt=Blog]').attr('src',gnbImgon.replace('Off.png','On.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
				}
			})	
		}
		
		if(thisIndex == "event_list.asp" || thisIndex =="event_detail.asp"){
			var gnbImgon = $('img[alt=Event]').attr("src");
			$('.gnb img[alt=Event]').attr('src',gnbImgon.replace('Off.png','On.png'));
			
			$('.gnb > li').hover(function(){
				if($(this).children().children().is('img[alt=Event]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Event]').attr("src");
					$('.gnb img[alt=Event]').attr('src',gnbImgon.replace('On.png','Off.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
			}
			},function(){
				if($(this).children().children().is('img[alt=Event]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Event]').attr("src");
					$('.gnb img[alt=Event]').attr('src',gnbImgon.replace('Off.png','On.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
				}
			})
		}
		
		if(thisIndex == "satin_story.asp"  || thisIndex =="project_detail.asp"){
			var gnbImgon = $('img[alt=theSatinstory]').attr("src");
			$('.gnb img[alt=theSatinstory]').attr('src',gnbImgon.replace('Off.png','On.png'));
			
			$('.gnb > li').hover(function(){
				if($(this).children().children().is('img[alt=theSatinstory]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=theSatinstory]').attr("src");
					$('.gnb img[alt=theSatinstory]').attr('src',gnbImgon.replace('On.png','Off.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
			}
			},function(){
				if($(this).children().children().is('img[alt=theSatinstory]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=theSatinstory]').attr("src");
					$('.gnb img[alt=theSatinstory]').attr('src',gnbImgon.replace('Off.png','On.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
				}
			})	
		}
		
		if(thisIndex == "store.asp"){
			var gnbImgon = $('img[alt=Store]').attr("src");
			$('.gnb img[alt=Store]').attr('src',gnbImgon.replace('Off.png','On.png'));
			
			$('.gnb > li').hover(function(){
				if($(this).children().children().is('img[alt=Store]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Store]').attr("src");
					$('.gnb img[alt=Store]').attr('src',gnbImgon.replace('On.png','Off.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
			}
			},function(){
				if($(this).children().children().is('img[alt=Store]')){
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
				}else {
					var gnbImgon = $('img[alt=Store]').attr("src");
					$('.gnb img[alt=Store]').attr('src',gnbImgon.replace('Off.png','On.png'));
					var gnbImgonSrc = $(this).children().children().attr("src");				
					$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
				}
			})
		}
		
		if(thisIndex == "" || thisIndex =="sitemap.asp" || thisIndex =="sitemap.asp"){		
			
			$('.gnb li').hover(function(){
				var gnbImgonSrc = $(this).children().children().attr("src");				
				$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
			},function(){
				var gnbImgonSrc = $(this).children().children().attr("src");				
				$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
			});	
		}
		
		$('.gnb li ul li').hover(function(){
			var gnbImgonSrc = $(this).children().children().attr("src");				
			$(this).children().children().attr('src',gnbImgonSrc.replace('Off.png','On.png'));
		},function(){
			var gnbImgonSrc = $(this).children().children().attr("src");				
			$(this).children().children().attr('src',gnbImgonSrc.replace('On.png','Off.png'));
		});

});	
