/**
 * frame(액자)형식의 온오프를 가진 이미지엘리먼트의 부모(앵커)에게 연결된 함수
 */
function imageFrameUi(){
	$$(".frameImg").each(function(item){
		item.observe("mouseover",function(){
			this.down("img").src = (this.down("img").src).replace(".gif","On.gif");
		});
		item.observe("mouseout",function(){
			this.down("img").src = (this.down("img").src).replace("On.gif",".gif");
		});
	});
};

/**
 * 메인페이지 우측하단 "전시토크,평론"에 사용하는 Ui Class입니다.
 */
var talkReviewUiClass = new Class.create({
	initialize:function(){
		this.titSet = $("talkReview").select("h2 a");
		this.divSet = $("talkReview").select(".talkReviewCont");
		this.index = 0;
	},
	//사용자 입력을 받는 함수들 
	talkView:function(){
		this.index = 0;
		this.setTab(this.index);
		this.setDiv(this.index);
	}, 
	reviewView:function(){
		this.index = 1;
		this.setTab(this.index);
		this.setDiv(this.index);
	},
	//사용자 입력이 없는 내부동작 함수들
	setTab:function(index){
		$(this.titSet).each(function(item,i){
			item.down("img").src = (item.down("img").src).replace("On.gif",".gif");
			if(index==i){
				item.down("img").src = (item.down("img").src).replace(".gif","On.gif");
			};
		});
	},
	setDiv:function(index){
		this.divSet.each(function(item){
			item.hide();
		});
		this.divSet[index].show();
	}
});
/**
 * 메인페이지 우측 상단에 있는 "HOT10" 의 Ui Class입니다.
 */
var mainHotUiClass = new Class.create({
	initialize:function(){
		this.titSet = $("mainHot10").select("h3 a");
		this.divSet = $("mainHot10").select(".hot10Cont");
		this.icoImg = $("hot10More").down("img");
		this.index = 0;
	},
	//사용자 입력을 받는 함수들
	exView:function(){ // 전시 보기
		this.index = 0;
		this.setTab(this.index);
		this.setDiv(this.index);
		this.resetView();
	},
	arView:function(){ // 작가보기
		this.index = 1;
		this.setTab(this.index);
		this.setDiv(this.index);
		this.resetView();
	},
	halfView:function(){ // 6~10위 보기
		if((this.icoImg.src).indexOf("/images/main/btnUpArrow.gif")=="-1"){
			this.divSet[this.index].select("li").each(function(item,i){
				if(i<5){item.hide();}
			});
			this.icoImg.src = "/images/main/btnUpArrow.gif";
		}else{
			this.resetView();
		};
	},
	//사용자 입력이 없는 내부동작 함수들
	resetView:function(){ // 초기화 하는 함수
		$R(0,1).each(function(num){
			this.divSet[num].select("li").each(function(item,i){
				if(i<5){item.show();}
			});
		}.bind(this));
		this.icoImg.src = "/images/main/btnDownArrow.gif";
	},
	setTab:function(index){ //탭 온오프
		$(this.titSet).each(function(item){
			item.removeClassName("tabOn");
		});
		this.titSet[index].addClassName("tabOn");
	},
	setDiv:function(index){ //리스트 div들 온오프
		$(this.divSet).each(function(item){
			item.hide();
		});
		this.divSet[index].show();
	}
});
	
	
/**
 * 전시일정에서 오늘 날짜가 찍히는 함수
 */
function galleryScheduleToday(day) {
	var container = $("galleryWeekBox");
	var itemH = container.down(".itemCalendarHeader").getHeight() +container.down(".itemCalendar").getHeight() ;
	itemH = itemH -2;
	var itemLeft = (day-1)*20;
	container.down(".itemToday").setStyle({						
		"height": itemH,
		"marginLeft" : itemLeft+"px"
	});
	container.down(".itemToday2").setStyle({
		"height": itemH,
		"marginLeft" : itemLeft+"px"
	});
}

/**
 * 아카이브 GNB 컨트롤 함수입니다.
 * @author dstyle
 * @since 2010.09.20
 * @version 1.1
 * @history [1.0] : 작성완료 (2010.09.20)
 * @history [1.1] : 마우스아웃 시 원래오버 상태로 이동할수 있도록 함수 수정. (2010.10.05)
 */
function akiveGnbUi(){
	// 초기 변수 설정
	var nowOn = new Array();
	var gnb = $("gnbAkive").select("a");
	var gnbImg = $("gnbAkive").select("img");
	var sGnb = $("sGnbAkive");
	
	
	// 1depth값 구하기.
	gnb.each(function(item,i){
		if((/(\_On)/).test(item.down("img").src)){
			nowOn[0] = i;
			throw $break;
		};
	});
	
	//2depth값 구하기.
	/*
	sGnb.down("ul",nowOn[0]).select("a").each(function(liTem,lNum){
		if((/(On)/).test(liTem.down("img").src)){
			nowOn[1] = lNum;
			throw $break;
		};
	});
	*/
	
	// 1depth GNB에 액션 걸기
	gnb.each(function(aTem,aNum){
		aTem.num = aNum;
		aTem.observe("mouseover",function(){
			akiveMouseOver = true;
			akiveGNBTime = 0;
			gnbImg.each(function(gnbImgItem,gnbNum){
				gnbImgItem.src = (gnbImgItem.src).replace("_On.gif",".gif");
			});
			gnbImg[this.num].src = (gnbImg[this.num].src).replace(".gif","_On.gif");
			/*
			sGnb.select("ul").each(function(ulItem,ulNum){
				ulItem.hide();
			});
			sGnb.down("ul",this.num).show();
			*/
		});
		aTem.observe("mouseout",function(){
			akiveMouseOver = false;
			//akiveGNBTimer(nowOn);
		});
	});
	/*
	//2depth subGNB에 액션걸기
	sGnb.select("a").each(function(dep2ATem,dep2ANum){
		dep2ATem.observe("mouseover",function(){
			akiveMouseOver = true;
		});
		dep2ATem.observe("mouseout",function(){
			akiveMouseOver = false;
		});
	});
	*/
	
	
	
	
};
var akiveGNBTime = 0;
var akiveMouseOver = false;
function akiveGNBTimer(nowOnArr){
	if(akiveGNBTime<1000){
		setTimeout(function(){
			akiveGNBTimer(nowOnArr);
		},10);
		if(!akiveMouseOver){
			akiveGNBTime += 10;
		};
	}else{
		var gnbImg = $("gnbAkive").select("img");
		var nowImg = $("gnbAkive").down("a",nowOnArr[0]).down("img");
		var sGnb = $("sGnbAkive");
		if(nowOnArr[0]!=null){
			gnbImg.each(function(gnbImgItem,gnbNum){
				gnbImgItem.src = (gnbImgItem.src).replace("_On.gif",".gif");
			});
			nowImg.src = (nowImg.src).replace(".gif","_On.gif");
			
			sGnb.select("ul").each(function(ulItem,ulNum){
				ulItem.hide();
			});
			sGnb.down("ul",nowOnArr[0]).show();
		}else{
			gnbImg.each(function(gnbImgItem,gnbNum){
				gnbImgItem.src = (gnbImgItem.src).replace("_On.gif",".gif");
			});
			sGnb.select("ul").each(function(ulItem,ulNum){
				ulItem.hide();
			});
		}
	};
};



/**
 * 로그인 체크하여 로그인 페이지로 리턴하는 함수입니다.
 * @param userId
 * @return 
 * @author k2703
 * @since 2010.10.05
 */
function wasLogin(userId, auth) {
	var loginID = "";

	if(auth == "true") {
		return true;		
	}
	else {
		alert("로그인 후 이용해 주십시오");
		var reUrlParent = (parent.location.href).replace("http://www.akive.org","");
		reUrlParent = encodeURIComponent(reUrlParent);
		parent.location.href ="/member/login.do?rtnUrlheader="+reUrlParent;
	}
};

