// aprende.js //
// 이 파일은 웹사이트에서 이벤트(클릭, 마우스 오버 등)를 통해 움직이는 액션(Accordion layout, Dashboard, Quick tab)을 적용한다. //
// 그리고 다운로드 버튼 내부에 있는 텍스트 변경, 브라우져 크기가 변경될 때마다 브라우져의 너비와 높이 값을 추출하고 그 값에 따라 해당되는 함수를 실행한다. //
// 마지막으로 Accessibility 상태를 저장하는 Cookie 값을 저장, 삭제하는 함수를 실행한다. //

jQuery(document).ready(function($) {
	// Extract User Agent //
	$("#block-system-main").children("content").text(null);
	
	//===========================//
	// ===== 사용할 변수를 선언한다. ======//
	//===========================//

	// Public Variables //
	var current_url = $(location).attr('href'); 					// 현재 주소
	current_url = current_url.replace("http://" , "");			// 현재 주소에서 http://를 제거			
	var current_domain = current_url.split("/");				// 현재 주소를 '/'를 기준으로 잘라서 current_domain 배열에 저장
	var chk_quickmenu = false;
	var chk_search = false;
	var chk_accessibility = false;
	var window_width;														// Web Browser width
	var window_height;														// Web Browser Height
	var content_height = $(".wrap").height() - $(".header").height();			// Content Layout height
	// var form_text = $("form").children("div").text();
	
	// Variables - Today : 오늘 날짜를 생성한다. //
	var date = new Date();
	var today_month = String(date.getMonth()+1);		// 현재 달
	var today_day = date.getDate();									// 현재 날
	var today_year = date.getFullYear();							// 현재 년
	if(today_month.length == 1) { today_month = "0" + String(today_month); }		// 1 ~ 9일까지 한 자리 수 날짜 앞에 0을 붙인다.
	var today = today_month + "/" + today_day + "/" + today_year;							// 오늘 날짜 (12/31/2014 )
	
	// Admin Overlay 레이아웃이 스크롤 가능하도록 iframe 내부 css를 수정한다. //
	$("iframe.overlay-element").load(function() {
		$("iframe.overlay-element").contents().find("body.overlay").css("overflow", "auto");
	});
		
	/* current_state = 1 : Desktop, current_state = 2 : Tablet,	current_state = 3 : mobile */
	//	Desktop //
	$(window).load(function() {
		// 대쉬보드를 구성하는 블럭의 높이를 자동으로 계산한다. //
		$main6 = $(".main6");
		var main6_height = $main6.height();

		if(main6_height >= 378 && main6_height <= 380) {
			poll_autoHeight(1);
		}
		else if(main6_height >= 306 && main6_height >= 308 ) {
			poll_autoHeight(2);
		}

		// Main content - Masonry : #masonry_container 내부의 item 클래스를 가진 모든 요소들을 웹 브라우저 너비에 따라 재배치하는 기능이다. 
		// ( Secondary menu - Campus virtual 페이지(node/1724, node/1725)는 Frontpage와 같은 구조이지만 Masonry 기능을 사용하지 않는다. )
		if(!$("body").hasClass("page-node-1724") && !$("body").hasClass("page-node-1725")) {
			$('#masonry_container').masonry({
				columnWidth: 1,
				itemSelector: '.item',
				stamp: '.item-margin-top',
				isAnimated: true
			});

			$("#masonry_container").find(".item").each(function() {
				$("#masonry_container").height += $(this).height();
			});
		}
	});
			
	// Save Accessibility state : Accessibility는 Cookie값을 저장하여 사용여부를 판별한다. //
	var accessibility_value = getCookie("accessibility");
	if(accessibility_value == 1) {
		$("body").addClass("accessibility");
		/* Header */
		$(".accessibility").find(".logo").children(".logo_container").children("a").eq(0).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_1_disabled.jpg");
		$(".accessibility").find(".logo").children(".logo_container").children("a").eq(1).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_2_disabled.jpg");
		$(".accessibility").find(".logo").children(".logo_container").children("a").eq(2).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_3_disabled.jpg");
		/* Main Footer */
		$(".body").find(".footer_logo").find("img").eq(0).attr("src", "/sites/all/themes/aprende/images/f_logo1_disabled.jpg");
		$(".body").find(".footer_logo").find("img").eq(1).attr("src", "/sites/all/themes/aprende/images/f_logo2_disabled.jpg");
		/* Sub Footer */
		$("body").find("#sub_footer").find(".banner_box").children(".banner1").children("img").attr("src", "/sites/all/themes/aprende/images/f_logo1_disabled.jpg");
		$("body").find("#sub_footer").find(".banner_box").children(".banner2").children("img").attr("src", "/sites/all/themes/aprende/images/f_logo2_disabled.jpg");
	}
	
	// Top menu - Accessibility button : Accessibility 버튼을 작동시킨다. //
	$(".btn_accessibility").click(function() {
		var url = $(location).attr('href');
		if(!$("body").hasClass("accessibility")) {
			setCookie("accessibility", 1, 'undefined');
			$("body").addClass("accessibility");
			/* Header */
			$(".accessibility").find(".logo").children(".logo_container").children("a").eq(0).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_1_disabled.jpg");
			$(".accessibility").find(".logo").children(".logo_container").children("a").eq(1).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_2_disabled.jpg");
			$(".accessibility").find(".logo").children(".logo_container").children("a").eq(2).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_3_disabled.jpg");
			/* Main Footer */
			$(".accessibility").find(".footer_logo").find("img").eq(0).attr("src", "/sites/all/themes/aprende/images/f_logo1_disabled.jpg");
			$(".accessibility").find(".footer_logo").find("img").eq(1).attr("src", "/sites/all/themes/aprende/images/f_logo2_disabled.jpg");
			/* Sub Footer */
			$("body").find("#sub_footer").find(".banner_box").children(".banner1").children("img").attr("src", "/sites/all/themes/aprende/images/f_logo1_disabled.jpg");
			$("body").find("#sub_footer").find(".banner_box").children(".banner2").children("img").attr("src", "/sites/all/themes/aprende/images/f_logo2_disabled.jpg");
		}
		else {
			setCookie("accessibility", '', -1);
			$("body").removeClass("accessibility");
			$("body").find(".logo").children(".logo_container").children("a").eq(0).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_1.png");
			$("body").find(".logo").children(".logo_container").children("a").eq(1).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_2.png");
			$("body").find(".logo").children(".logo_container").children("a").eq(2).children("img").attr("src", "/sites/all/themes/aprende/images/h_logo_3.png");
			/* Main Footer */
			$("body").find(".footer_logo").find("img").eq(0).attr("src", "/sites/all/themes/aprende/images/f_logo1.jpg");
			$("body").find(".footer_logo").find("img").eq(1).attr("src", "/sites/all/themes/aprende/images/f_logo2.jpg");
			/* Sub Footer */
			$("body").find("#sub_footer").find(".banner1").children("img").attr("src", "/sites/all/themes/aprende/images/f_logo1.jpg");
			$("body").find("#sub_footer").find(".banner2").children("img").attr("src", "/sites/all/themes/aprende/images/f_logo2.jpg");
			
		}
		return false;
	});

	// Group 탭 삭제 //
	if(!$("body").hasClass("node-type-networkfc")) {
		$(".page-node").find(".tabs.primary").children("li").each(function() {
			var primaryTabAnchor = $(this).children("a");
			if(primaryTabAnchor.text() == "Grupo" || primaryTabAnchor.text() == "Group") {
				$(this).remove();
			}
		});
	}

	var primaryTabLength = $(".page-node").find(".tabs.primary").children("li").length;
	if(primaryTabLength <= 1) {
		$(".page-node").find(".tabs.primary").hide();
	}
	
	
	// Header User menu : Create content 버튼을 작동시킨다. //
	$(".user_menu").find(".collapsed").children("a").removeAttr("href");
	$(".user_menu").find(".expanded").children("a").removeAttr("href");
	$(".user_menu").find(".expanded").click(function() {
		if(!$(this).hasClass("on")) {
			$(".user_menu_container").css("overflow", "visible");
			$(this).find(".menu").css("zIndex", "499");
			$(this).addClass("on");
		}
		else if($(this).hasClass("on")) {
			$(".user_menu_container").css("overflow", "hidden");
			$(this).find(".menu").css("zIndex", "0");
			$(this).removeClass("on");
		}
	});
		
	// Community Main - Featured Network : Stats 버튼을 누르면 열리는 창을 작동시킨다.  //
	if($('body').hasClass('not-logged-in')) {
		enable_featuredNetwork_state();
	}
	$(document).ajaxComplete(function() {
		enable_featuredNetwork_state();
		/*
		$(".view-featured-network").find(".views-field-nothing-2").find(".stats").click(function() {
			console.log("enable");
			var row = $(this).parents(".views-row");		// 자신이 속한 row를 찾는다.
			if(!$(this).hasClass("on")) {
				row.find(".views-field-nothing-2").before("<div class='bg_shadow'>");
				row.find(".bg_shadow").fadeIn(200);
				$(this).find(".view-stats-of-community").show();
				$(this).find(".view-stats-of-community").find(".view-content").slideDown(250);
				$(this).addClass("on");
			}
			else if($(this).hasClass("on")) {
				$(this).find(".view-stats-of-community").find(".view-content").slideUp(250);
				$(this).find(".view-stats-of-community").hide();
				row.find(".bg_shadow").fadeOut(200, function() { row.find(".bg_shadow").remove(); });
				$(this).removeClass("on");
			}
		});
		*/
	});

	function enable_featuredNetwork_state() {
		$(".view-featured-network").find(".views-field-nothing-2").find(".stats").click(function() {
			console.log("enable");
			var row = $(this).parents(".views-row");		// 자신이 속한 row를 찾는다.
			if(!$(this).hasClass("on")) {
				row.find(".views-field-nothing-2").before("<div class='bg_shadow'>");
				row.find(".bg_shadow").fadeIn(200);
				$(this).find(".view-stats-of-community").show();
				$(this).find(".view-stats-of-community").find(".view-content").slideDown(250);
				$(this).addClass("on");
			}
			else if($(this).hasClass("on")) {
				$(this).find(".view-stats-of-community").find(".view-content").slideUp(250);
				$(this).find(".view-stats-of-community").hide();
				row.find(".bg_shadow").fadeOut(200, function() { row.find(".bg_shadow").remove(); });
				$(this).removeClass("on");
			}
		});
	}
	//============================//
	// ========= User Menual ========= //
	//============================//
	$user_menual_container = $("#user_menual_container");
	
	// Menu Control - 자식이 있는 메뉴 제어 //
	$user_menual_container.find(".accordion").children("ul.parent_group").children("li.parent").children("a").click(function() {
		$parent = $(this).parent("li.parent");
		if(!$parent.hasClass("active")) {
			$parent.children("ul.child").slideDown(300);
			$parent.addClass("active");
		}
		else {
			$parent.children("ul.child").slideUp(300);
			$parent.removeClass("active");
		}
	});
	
	// 자식이 없는 메뉴 제어 //
	$user_menual_container.find(".accordion").children("ul.parent_group").children("li").children("a").click(function() {
		$parent = $(this).parent("li");
		$parent_group = $(this).parent("li").parent("ul.parent_group");
		$ancestor = $parent_group.parent("div.accordion");
		$root_ancestor = $ancestor.parent("div.interface").parent("div.chapter");
		
		var idx = $parent_group.children("li").index($parent);										// 부모의 인덱스 값
		var ancestor_idx = $user_menual_container.find(".accordion").index($ancestor);		// 선조의 인덱스 값		
		var content_id = ancestor_idx + "_" + idx + "_0"
		if(!$parent.hasClass("parent")) {
			// $root_ancestor.find(".menual_content").removeClass("active");
			// $root_ancestor.find(".menual_" + content_id).addClass("active");
		}
	});
	
	// Content Control - 자식 메뉴 제어 //
	$user_menual_container.find(".accordion").find("ul.child").children("li.children").children("a").click(function() {
		$("body").css("overflowY", "hidden");
		$parent = $(this).parent("li");
		var video_title = $parent.children(".video_title").attr("value");							// 동영상 타이틀 추출
		var video_summary = $parent.children(".video_summary").attr("value");			// 동영상 개요 추출		
		var video_instruction = $parent.children(".video_instruction").attr("value");		// 동영상 과정 추출
		var video_url = $parent.children(".video_url").attr("value");								// 동영상 주소 추출
		
		$("#video_popup").children(".container").children("h2.title").text(video_title);																				// 동영상 팝업의 제목을 변경한다.
		$("#video_popup").children(".container").children(".description_box").children(".summary").children("p").text(video_summary);			// 동영상 팝업의 개요를 변경한다.
		$("#video_popup").children(".container").children(".description_box").children(".step").children("h3").after(video_instruction);				// 동영상 팝업의 과정을 변경한다.
		$("#video_popup").children(".container").children(".video_box").children(".ready_box").html("<iframe id='video_player' src='" + video_url + "' width='590' height='290' scrolling='no'></iframe>");		// 동영상 플레이어를 로드 할 iframe을 추가한다.
		
		$("#video_popup").fadeIn(300, function() {
			$("#video_popup").children(".container").children(".video_box").children(".ready_box").children("#video_player").load(function() {
				console.log("Load Vldeo player");
			});
		});
	});
	
	$("#video_popup").children(".container").children(".btn_close").click(function() {
		$("body").css("overflowY", "initial");
		$("#video_player").remove();
		$("#video_popup").children(".container").children(".description_box").children(".step").children("ol").remove();
		$("#video_popup").hide();
	});
	
	//============================//
	// Mobile 환경에서 사용하는 함수 및 이벤트 //
	//============================//
	
	// Mobile - toggle primary menu : 모바일 웹사이트의 Primary 메뉴를 여,닫는 기능을 작동시킨다. //
	$(".toggle_primary_menu").click(function() {
		if (!$(this).hasClass("on")) {
			// 현재 페이지가 Guideline 이면 index를 메뉴 길이만큼 아래로 이동시킨다. //
			if($("body").hasClass("node-type-guideline")) {
				$(".section_container").find(".right_sidebar").animate({top:601}, 300, function() {  });
			}
			$(".main_container").find(".left_sidebar").slideDown(300);
			$(this).addClass("on");
		}
		else {
			// 현재 페이지가 Guideline 이면 index를 원래 위치로 이동시킨다. //
			if($("body").hasClass("node-type-guideline")) {
				$(".section_container").find(".right_sidebar").animate({top:5}, 300, function() {  });
			}
			$(".main_container").find(".left_sidebar").slideUp(300);
			$(this).removeClass("on");
		}
	});
	
	// Mobile - Toggle search form : 모바일 웹사이트의 Search form을 여,닫는 기능을 작동시킨다. //
	$(".mobile_search_switcher").click(function() {
		if (!$(this).hasClass("on")) {
			$(".header_search_container").find(".block-search").animate({ height : 42}, 300);
			$(this).addClass("on");
		}
		else {
			$(".header_search_container").find(".block-search").animate({ height : 0}, 300);
			$(this).removeClass("on");
		}
	});
	
	// Mobile - toggle secondary menu : 모바일 웹사이트의 Secondary 메뉴 form을 여,닫는 기능을 작동시킨다.//
	$(".mobile_menu_switcher").click(function() {
		if (!$(this).hasClass("on")) {
			$(".header_container").find(".secondary_menu").slideDown(300);
			$(this).addClass("on");
		}
		else {
			$(".header_container").find(".secondary_menu").slideUp(300);
			$(this).removeClass("on");
		}
	});
	
	// 모바일 환경에서 Guideline - Right sidebar에 있는 index 레이아웃의 height 값을 추출한 후, height 값 만큼 margin-top 속성을 부여한다. //
	function extract_index_height(param) {
		if(param) {
			var idx_height = $(".node-type-guideline").find(".right_sidebar").height();
			$guideline_index = $(".node-type-guideline").find(".section_content").children(".region-section-content");
			$guideline_index.css("marginTop", idx_height);
		}
		else {
			var idx_height = $(".node-type-guideline").find(".right_sidebar").height();
			$guideline_index = $(".node-type-guideline").find(".section_content").children(".region-section-content");
			$guideline_index.css("marginTop", idx_height);
		}
	}
	
	//=========================//
	// Download 버튼에 텍스트를 적용하기 //
	//=========================//
	
	// Sub main - Download button : 다운로드 버튼에 파일경로 대신 Download 텍스트가 출력되도록 한다. //
	$(".i18n-en").find(".btn_download").children("a").text("Download");
	$(".i18n-es").find(".btn_download").children("a").text("Descargar");
	
	// Bank of Home student work Document  : 다운로드 버튼에 파일경로 대신 Download 텍스트가 출력되도록 한다. //
	$(".i18n-en.node-type-document-in-use-of-ict-for-stude").find(".field-type-file").find("a").text("Download");
	$(".i18n-en.node-type-documentiuoiff").find(".field-type-file").find("a").text("Download");
	$(".i18n-en.node-type-projectb").find(".field-type-file").find("a").text("Download");
	$(".i18n-en.node-type-bank-of-home-student-work").find(".field-type-file").find("a").text("Download");
	
	$(".i18n-es.node-type-document-in-use-of-ict-for-stude").find(".field-type-file").find("a").text("Descargar");
	$(".i18n-es.node-type-documentiuoiff").find(".field-type-file").find("a").text("Descargar");
	$(".i18n-es.node-type-projectb").find(".field-type-file").find("a").text("Descargar");
	$(".i18n-es.node-type-bank-of-home-student-work").find(".field-type-file").find("a").text("Descargar");
	
	// Guideline  : 다운로드 버튼에 파일경로 대신 PDF Download 텍스트가 출력되도록 한다. //
	$(".i18n-en.node-type-guideline").find(".field-type-file").find("a").text("PDF download");		// Change Text in PDF Download Button for English
	$(".i18n-es.node-type-guideline").find(".field-type-file").find("a").text("PDF Descargar");		// Change Text in PDF Download Button for Spanish
	
	// 다운로드 파일이 웹브라우져에 출력되지 않고 다운로드 되도록 수정 //
	var guideline_url = $(".node-type-guideline").find(".field-type-file").find("a").attr("href");
	$(".node-type-guideline").find(".field-type-file").find("a").attr("href", "#none");
	$(".node-type-guideline").find(".field-type-file").find("a").click(function() {
		window.open(guideline_url);
		return false;
	});
	
	//===========================//
	// ======= Resource Main =====-===//
	//===========================//
	
	// Resource Main accordion : Resource 메인화면의 아코디언 인터페이스를 작동시킨다. //
	$(".resource_container").find(".accordion").children("div").children("p").hide();
	$(".resource_container").find(".accordion").children(".active").children("p").show();
	$(".resource_container").find(".accordion").children("div").click(function() {
		if(!$(this).hasClass("active")) {
			$(".resource_container").find(".accordion").children(".active").children("p").slideUp(300);
			$(".resource_container").find(".accordion").children("div").removeClass("active");
			$(this).children("p").slideDown(300);
			$(this).addClass("active");
		}
	});
	
	// Resource description icon : Resource의 CW, UOL, LO 페이지에 있는 Description 내부 아이콘의 마우스 오버 효과를 적용한다. //
	// 왼쪽에 배치된 아이콘 //
	$(".description").find(".icon1").find(".left_icon").find("a").hover(function() {		
		var parent = $(this).parent("li");
		var image_name = $(this).children("img").attr("src");
		var image_name_array = image_name.split(".");
		var image_on_name = image_name_array[0] + "_on.png";
		$(this).children("img").attr("src", image_on_name);
		
		var idx = $(".node-type-lo").find(".description").find(".icon1").find(".left_icon").find("li").index(parent);	
	}, function() {
		var image_on_name = $(this).children("img").attr("src");
		var image_name = image_on_name.replace("_on", "");
		$(this).children("img").attr("src", image_name);
	});
	//오른쪽에 배치된 아이콘 //
	$(".description").find(".icon1").find(".right_icon").find("a").hover(function() {		
		var parent = $(this).parent("li");
		var image_name = $(this).children("img").attr("src");
		var image_name_array = image_name.split(".");
		var image_on_name = image_name_array[0] + "_on.png";
		$(this).children("img").attr("src", image_on_name);
		
		var idx = $(".node-type-lo").find(".description").find(".icon1").find(".left_icon").find("li").index(parent);	
	}, function() {
		var image_on_name = $(this).children("img").attr("src");
		var image_name = image_on_name.replace("_on", "");
		$(this).children("img").attr("src", image_name);
	});

	//=================================//
	// ========== Start Courseware ==========//
	//=================================//
	
	var chk_resource_popup = false;
	
	// Resource main - 비활성화 된 Grade 버튼의 링크는 작동되지 않도록 한다. //
	$(".resource_container").find(".grade_list").children("li").children("a").click(function() {
		if($(this).parent("li").hasClass("disable")) {
			return false;
		}
	});
	
	if($("body").hasClass("node-type-courseware")) {
		$courseware = $(".courseware");
		
		var css_class = $courseware.attr("class");
		var css_class_array1 = css_class.split(" ");
		var css_class_array2 = css_class_array1[1].split("_");
		
		var subject = css_class_array2[0];		// 과목명
		var grade = css_class_array2[1];			// Grade
		
		$courseware.find(".quicktab").children("li").each(function() {
			if($(this).hasClass(subject)) {
				$(this).addClass("active");
			}
			
			$(".grade_group." + subject).show();
		});
		
		// Courseware - 비활성화 된 Grade 버튼의 링크는 작동되지 않도록 한다. //
		$courseware.find(".grade_group").children(".grade_list").children("li").children("a").click(function() {
			if($(this).parent("li").hasClass("disable")) {
				return false;
			}
		});
		
		// Grade 버튼 중 과목과 학년이 일치하는 버튼을 활성화 한다. //
		$courseware.find(".box_body").find(".grade_group").find(".list").each(function() {
			var parent = $(this).parent(".grade_list").parent(".grade_group");
			if(parent.hasClass(subject) && $(this).hasClass(grade)) {
				$(this).removeClass("disable");
			}
		});
		
		// 과목을 선택한다. //
		$courseware.find(".quicktab").children("li").click(function() {		
			var idx = $courseware.find(".quicktab").children("li").index(this);				// Subject 탭의 index를 추출한다.
			$courseware.find(".quicktab").children("li").removeClass("active");			// 모든 Subject 탭을 비활성화 한다.
			$(".courseware").find(".box_body").find(".grade_group").hide();				// 모든 과목에 대한 Grade 버튼 그룹을 감춘다.
			$(this).addClass("active");																				// 선택한 Subject 탭을 활성화 한다.
			$courseware.find(".box_body").find(".grade_group").eq(idx).show();		// 선택한 과목에 대한 Grade 버튼 그룹을 보이게 한다.
			
			if(idx == 2) { var select_subject = "language"; }
			if(idx == 1) { var select_subject = "math"; }
			if(idx == 0) { var select_subject = "science"; }
			
			if(subject == select_subject) { $(".section_group").show(); }
			else { $(".section_group").hide(); }
		});
		
		// UDA 리스트를 오픈한다. //
		$courseware.find(".section_list").children(".list").children(".section").click(function() {
			var parent = $(this).parent(".list");
			
			if(!parent.hasClass("active")) {
				parent.children(".container").slideDown(300);
				parent.addClass("active");
			}
			else {
				parent.children(".container").slideUp(300);
				parent.removeClass("active");
			}
		});
		
		// Metadata Popup을 작동시킨다 .//
		$(".btn_detail").click(function() {
			var css_class = $(this).attr("class");
			var css_class_array1 = css_class.split(" ");
			
			var content_id = css_class_array1[1];			
			$(".resource_popup_container").each(function() {
				$(this).hide();
				if($(this).hasClass(content_id)) {
					if(current_state == 3) {
						$(this).show();
						// $(this).children(".bg_shadow").show();
						$(".courseware").hide();
					}
					else {
						$(this).fadeIn(300);
					}
					chk_resource_popup = true;
				}
			});
			
		});
	}
	
	if($("body").hasClass("node-type-lo")) {
		$(".btn_detail").click(function() {
			if(current_state == 3) {
				$(".uol_popup").hide();
				$(".resource_popup_container").show();
			}
			else {
				$(".resource_popup_container").fadeIn(300);
			}
			chk_resource_popup = true;
		});
	}
	
	// 모든 팝업의 닫기 버튼을 작동시킨다. 
	$(".popup").children(".btn_close").click(function() {
		chk_resource_popup = false;
		if(current_state == 3) {
			$(".courseware").show();
			$(".uol_popup").show();
		}
		$(this).parent(".popup").parent(".resource_popup_container").hide();
	});
	
	// DR page : Dr 페이지에 있는 다운로드 버튼의 텍스트를 수정한다. //
	$(".node-type-dr.i18n-es").find(".field-name-field-download-link").find("a").text("Descargar");
	$(".node-type-dr.i18n-en").find(".field-name-field-download-link").find("a").text("Download");	
	
	//==================================//
	// ========== End Courseware ===========//
	//=================================//


	
	// =============== Poll =============== //
	
	// Poll  Color : 각 Role에 출력되는 Color를 다르게 출력하기 위해 Class를 추가한다. //
	var menu_structure = $(".region-left-sidebar").find(".block-menu").find("h2").text();
	if(menu_structure == "Teachers" || menu_structure == "Docentes" ) {
		$(".view-poll ").addClass("poll_teacher");
	}
	else if (menu_structure == "Students" || menu_structure == "Estudiante" ) {
		$(".view-poll ").addClass("poll_student");
	}
	else if (menu_structure == "Family & Community" || menu_structure == "Familia y Comunidad" ) {
		$(".view-poll ").addClass("poll_family");
	}
	else if (menu_structure == "Researchers" || menu_structure == "Investigadores" ) {
		$(".view-poll ").addClass("poll_researcher");
	}
	else if (menu_structure == "Univ Professors" || menu_structure == "Docentes Superior" ) {
		$(".view-poll ").addClass("poll_univ_professor");
	}
	else if (menu_structure == "Univ Students" || menu_structure == "Estidiantes Superior" ) {
		$(".view-poll ").addClass("poll_univ_student");
	}
		
	// Remove Poll title link : Poll의 타이틀에 있는 링크를 해제한다. //
	$(".node-poll").children("h2").children("a").attr("href", "#none");
	$(".node-poll").children("h2").children("a").css("cursor", "default");
	
	// Forum : 토픽과 포스트, 댓글 개수 하단에 Topics, Posts, Replies 텍스트를 출력한다.  //
	if($("body").hasClass("page-forum")) {
		$(".page-forum").find("table").find(".topics").each(function() {
			var topic_number = $(this).text();
			$(this).html(topic_number + "<span>Topics</span>");
		});
		
		$(".page-forum").find("table").find(".posts").each(function() {
			var topic_number = $(this).text();
			$(this).html(topic_number + "<span>Posts</span>");
		});
		
		$(".page-forum").find("table").find(".replies").each(function() {
			var topic_number = $(this).text();
			$(this).html(topic_number + "<span>Replies</span>");
		});
	}
	
	// User Profile //
	if($("body").hasClass("page-user")) {
		var url_view = $(".page-user").find(".primary").children("li").eq(0).children("a").attr("href");
		var url_bookmark = $(".page-user").find(".primary").children("li").eq(1).children("a").attr("href");
		var url_edit = $(".page-user").find(".primary").children("li").eq(2).children("a").attr("href");
		var url_question = $(".page-user").find(".primary").children("li").eq(3).children("a").attr("href");
		
		$(".page-user").find(".user_button").find(".view").children("a").attr("href", url_view);
		$(".page-user").find(".user_button").find(".bookmark").children("a").attr("href", url_bookmark);
		$(".page-user").find(".user_button").find(".edit").children("a").attr("href", url_edit);
		$(".page-user").find(".user_button").find(".question").children("a").attr("href", url_question);
	}
	
	// Bookmark //
	if($(".node-experienceiuoift").find(".flag-bookmarks").hasClass("first")) {
		$(".node-experienceiuoift").find(".first").before("<div class='bookmark_label'>Bookmark</div>");
	}
	
	// Community calendar //
	$(".i18n-en.page-community-calendars").find(".date-prev").children("a").text("Prev");		// 달력 Prev 텍스트 왼쪽에 있던 << 화살표를 삭제하고 Prev 텍스트만 출력
	$(".i18n-en.page-community-calendars").find(".date-next").children("a").text("Next");		// 달력 Next 텍스트 왼쪽에 있던 << 화살표를 삭제하고 Next 텍스트만 출력
	$(".i18n-es.page-community-calendars").find(".date-prev").children("a").text("Anterior");		// 달력 Prev 텍스트 왼쪽에 있던 << 화살표를 삭제하고 Prev 텍스트만 출력
	$(".i18n-es.page-community-calendars").find(".date-next").children("a").text("Siguiente");		// 달력 Next 텍스트 왼쪽에 있던 << 화살표를 삭제하고 Next 텍스트만 출력
	
	// My Dashboard - Quicktab //
	dashboard_controller(0);
	$(".page-mydashboard").find(".quicktabs-tabs").children("li").children("a").attr("href", "#none");
	$(".page-mydashboard").find(".dashboard_quicktab").find("li").children("a").click(function() {
		var idx = $(".page-mydashboard").find(".dashboard_quicktab").find("li").index($(this).parent("li"));
		if(!$(this).parent("li").hasClass("active")) {
			dashboard_controller(idx);
		}
		return false;
	});
	
	$(".page-mydashboard").find(".quicktabs-tabs").children("li").children("a").click(function() {
		$(".page-mydashboard").find(".quicktabs-tabs").children("li").removeClass("active");
		$(this).parent("li").addClass("active");
		
		return false;
	});
	
	function dashboard_controller(box_number) {
		$(".page-mydashboard").find(".dashboard_quicktab").find("li").removeClass("active");
		$(".page-mydashboard").find(".dashboard_quicktab").find("li").eq(box_number).addClass("active");
		
		$(".page-mydashboard").find(".region-section-content").children("div").hide();
		$(".page-mydashboard").find(".region-section-content").children("div").eq(0).show();
		$(".page-mydashboard").find(".region-section-content").children("div").eq(box_number + 1).show();
	}
	
	$(".page-mydashboard").find("#homebox-add").find("li").each(function() {
		var add_board_text = $(this).children("a").text();
		var remove_label_text = add_board_text.split(": ");
		$(this).children("a").text(remove_label_text[2]);
	});
	
	// Photo //
	if($("body").hasClass("page-community-photo")) {
		$(".page-community-photo").find(".views-field-field-dr-image").append("<div class='bg_shadow'><a href='#none' class='btn_link'>&nbsp;</a><a href='#none' class='btn_zoom colorbox init-colorbox-processed cboxElement'>&nbsp;</a></div>");
		
		$(".page-community-photo").find(".views-row").each(function() {
			var image_url = $(this).find(".views-field-field-dr-image").find(".colorbox").attr("href");
			var page_url = $(this).find(".views-field-title").find("a").attr("href");
			
			$(this).find(".bg_shadow").find(".btn_link").attr("href", page_url);
			$(this).find(".bg_shadow").find(".btn_zoom").attr("href", image_url);
		});
		
		
		$(".page-community-photo").find(".views-field-field-dr-image").mouseover(function() {
			$(this).children(".bg_shadow").show();
		});
		$(".page-community-photo").find(".views-field-field-dr-image").mouseout(function() {
			$(this).children(".bg_shadow").hide();
		});
	}
	
	// Experience //
	if($("body").hasClass("page-node-37214") || $("body").hasClass("page-node-37215")) {
		$(".image_title").find(".link_role").children("li").click(function() {
			$(".region-section-content").find(".block").hide();																		// hide All Block
			var idx = $(".image_title").find(".link_role").children("li").index(this);										// Extract as index
			
			
			if(idx == 0) {
				$(".total_view").show();
				$(".region-section-content").find(".block-system").show();
			}
			else if(idx > 0) {
				$(".sub_view").eq(idx-1).show();
			}
		});
		
		$(".views-row").each(function() {
			var node_url = $(this).find(".views-field-field-ex-youtube").find("a").attr("href");
			$(this).find(".bg_shadow").find(".view_content").children("a").attr("href", node_url);
		});
		
		$(".views-row").mouseover(function() {
			$(this).find(".bg_shadow").show();
			return false;
		})
		$(".views-row").mouseout(function() {
			$(this).find(".bg_shadow").hide();
		});
		
		$(".view-experience-of-sub-main").find(".views-row").each(function() {
			var experience_url = $(this).find(".views-field-title").find("a").attr("href");
			$(this).find(".url").attr("href", experience_url);
		});
	}
		
	//==========================================//
	//==============  List of Community ==============//
	//==========================================//
	
	// 커뮤니티의 현재 상태를 추출한다. ( Published / Unpublished ) // 
	
	if($(".node-networkfc").hasClass("node-unpublished")) {
		var community_status = false; 
	}
	else {
		var community_status = true; 
	}
	
	if(community_status) {
		$(".node-type-networkfc").find("#block-views-contributor-list-block-2").css("top", "590px");
		$(".node-type-networkfc").find("#block-views-calendar-for-community-block-1").css("top", "1178px");
		$(".node-type-networkfc").find("#block-views-poll-block-2").css("top", "1440px");
	}
	else {
		$(".node-type-networkfc").find("#block-views-contributor-list-block-2").css("top", "680px");
		$(".node-type-networkfc").find("#block-views-calendar-for-community-block-1").css("top", "1268px");
		$(".node-type-networkfc").find("#block-views-poll-block-2").css("top", "1530px");
	}
	
	var top1;
	var top2;
	var top3;
	$(".node-type-networkfc").find(".summary").click(function() {	
		$parent = $(this).parent(".node-networkfc").parent(".content").parent(".block-system").parent(".region-section-content");
		// Open //
		if(!$(this).hasClass("on")) {
			$(this).addClass("on");
			$(".node-type-networkfc").find(".field-name-body").stop(true, true).slideDown(300, function() {
				// 펼쳐진 커뮤니티 소개의 높이값을 추출한다.  //
				var complete_height = $(".node-type-networkfc").find(".field-name-body").height() + 35;
				
				// 각 블럭의 top 값을 추출한다. //
				top1 = $parent.children("#block-views-contributor-list-block-2").css('top').replace(/[^-\d\.]/g, '');
				top2 = $parent.children("#block-views-calendar-for-community-block-1").css('top').replace(/[^-\d\.]/g, '');
				top3 = $parent.children("#block-views-poll-block-2").css('top').replace(/[^-\d\.]/g, '');
				
				// 각 블럭의 애니메이션 실행 //
				$parent.children("#block-views-contributor-list-block-2").stop().animate({ top:Number(top1) + complete_height }, 300, function() {} );
				$parent.children("#block-views-calendar-for-community-block-1").stop().animate({ top:Number(top2) + complete_height }, 300, function() {} );
				$parent.children("#block-views-poll-block-2").stop().animate({ top:Number(top3) + complete_height }, 300, function() {} );
			});
		}
		// Close //
		else {
			$(this).removeClass("on");
			$(".node-type-networkfc").find(".field-name-body").stop(true, true).slideUp(300, function() {
				$parent.children("#block-views-contributor-list-block-2").stop().animate({ top:top1 }, 300, function() {} );
				$parent.children("#block-views-calendar-for-community-block-1").stop().animate({ top:top2 }, 300, function() {} );
				$parent.children("#block-views-poll-block-2").stop().animate({ top:top3 }, 300, function() {} );
			});
			
		}
	});
	
	// Agenda - News //
	$(".page-agenda-news").find(".views-row").hover(
	function() {
		if(window_width > 750) {
			$(this).find(".views-field-field-ag-image").find("img").animate({ top:"-15", left:"-15", width:241, height:300 }, 300, "easieEaseOut", function() {} );
		}
	},
	function() {
		if(window_width > 750) {
			$(this).find(".views-field-field-ag-image").find("img").animate({ top:"0", left:"0", width:216, height:270 }, 200, "easieLinear", function() {}  );
		}
	}).click(function() {
		var detail_url = $(this).find(".views-field-title").find("a").attr("href");
		$(location).attr("href", detail_url);
	});

	// Agenda - Event //
	if($("body").hasClass("page-agenda-event")) {
		var role_array = new Array();
		$(".views-row").find(".event_label").children("a").each(function() {
			var role = $(this).text();
			$(this).attr("href", "#none");
			
			if(role == "Teachers" || role == "Docentes") {
				$(this).css("backgroundColor", "#693");
			}
			else if(role == "Students" || role == "Estudiantes") {
				$(this).css("backgroundColor", "#ffad33");
			}
			else if(role == "FamilyCommunity" || role == "Familia-y-Comunidad") {
				$(this).css("backgroundColor", "#E75802");
			}
			else if(role == "Researchers" || role == "Investigadores") {
				$(this).css("backgroundColor", "#24977C");
			}
			else if(role == "UnivProfessors" || role == "DocentesSuperior") {
				$(this).css("backgroundColor", "#2797ED");
			}
			else if(role == "UnivStudents" || role == "EstudiantesSuperior") {
				$(this).css("backgroundColor", "#6e60b2");
			}
		});
	}
	
	// Agenta - Listof tje da //
	if($("body").hasClass("field-listoftheday-month")) {
		var month_text = $("#edit-field-listoftheday-month option:selected").text();
		var month_value = 0;
		if(month_text == "Enero") { month_value = 1; }
		else if(month_text == "Febrero") { month_value = 2; }
		else if(month_text == "Marzo") { month_value = 3; }
		else if(month_text == "Abril") { month_value = 4; }
		else if(month_text == "Mayo") { month_value = 5; }
		else if(month_text == "June") { month_value = 6; }
		else if(month_text == "Julio") { month_value = 7; }
		else if(month_text == "Agosto") { month_value = 8; }
		else if(month_text == "Septiembre") { month_value = 9; }
		else if(month_text == "Octubre") { month_value = 10; }
		else if(month_text == "Noviembre") { month_value = 11; }
		else if(month_text == "Diciembre") { month_value = 12; }
		
		$(".field-listoftheday-month").find("#block-global-filter-global-filter-1").find(".content").find(".form-select").after("<div class='form_month'><span class='number'>" + month_text + "</span></div>");
	}
	
	/* Social network - Changed Role Color */
	if($("body").hasClass("node-type-networkfc")) {
		$role = $(".info_container").children(".role");
		$role.find("a").each(function() {
			var role_data = $(this).text();
			
			if(role_data == "Teachers" || role_data == "Docentes" ) {
				$(this).addClass("teacher");
			}
			else if (role_data == "Students" || role_data == "Estudiantes" ) {
				$(this).addClass("student");
			}
			else if (role_data == "Family & Community" || role_data == "Familia-y-Comunidad" ) {
				$(this).addClass("family");
			}
			else if (role_data == "Researchers" || role_data == "Investigadores" ) {
				$(this).addClass("researcher");
			}
			else if (role_data == "Univ Professors" || role_data == "DocentesSuperior" ) {
				$(this).addClass("univ_professor");
			}
			else if (role_data == "Univ Students" || role_data == "EstudiantesSuperior" ) {
				$(this).addClass("univ_student");
			}
		});
	}
	
	/* Course virtual */
	if($("body").hasClass("page-node-1724") || $("body").hasClass("page-node-1725")) {
		$(".ui-accordion ui-widget").find(".views-field-title").find("a").click(function() {
			$(window).height = window_height + $(".ui-accordion-content-active").height();
			return false;
		});
	}
	
	/* Edusitios */
	if($("body").hasClass("page-edusitios")) {
		function hover_effect_for_edusitios() {
			$(".view-content").children(".views-row").children(".views-field-nothing").hover(function() {
			$(this).stop().animate({ height:188, marginTop:-154 }, 300, function() {  });
			$(this).find(".title").fadeOut(300);
			$(this).find(".body").fadeIn(300);
			},function() {
				$(this).stop().animate({ height:40, marginTop:-0 }, 300, function() {  });
				$(this).find(".title").fadeIn(300);
				$(this).find(".body").fadeOut(300);
			});
		}
		hover_effect_for_edusitios();
		
		$(document).ajaxComplete(function() {
			hover_effect_for_edusitios();
		});
	}

	/* ================== Microsite menu ================== */
	$("#microsite_panel").find(".pane-content").children(".menu").children("li").addClass("parent_menu");
	$("#microsite_panel").find(".pane-content").children(".menu").children("li").children("ul").addClass("children_menu");
	
	/* ================== Community Private & Public ================== */
	var community_visibility = $(".page-node-18980").find(".view-network-for-community").find(".views-field-group-access").find(".field-content");
	community_visibility.each(function() {
		if($(this).text() == "1") {
			$(this).addClass("private");
		}
		else if ($(this).text() == "0") {
			$(this).addClass("public");
		}	
	});

	// Quicktab Confirmation //
	if(!$("body").hasClass("node-type-createsp") && $(".section_content").find(".region").children("div").hasClass("block-quicktabs")) {
		var quicktab = $(".region").children("div.block-quicktabs");		// 노드에 퀵탭이 있을 경우 해당 퀵탭을 저장한다.
		
		quicktab.find(".quicktabs-tabpage").each(function() {
			// 승인대기 중인 form이 있는지 찾는다. //
			if($(this).find(".view-content").children("form").hasClass("confirmation")) {
				// 승인대기 중인 form이 있다면 해당 form이 있는 탭을 활성화 한다. //
				quicktab.find(".quicktabs-tabpage").addClass("quicktabs-hide");		// 퀵탭에 속한 모든 콘텐츠를 비활성화 한다.
				var idx = quicktab.find(".quicktabs-tabpage").index($(this));		// 승인대기 중인 form이 있는 탭의 인덱스를 추출한다.
				$(this).removeClass("quicktabs-hide");								// 콘텐츠 활성화
				
				quicktab.find(".quicktabs-tabs").children("li").removeClass("active");		// 활성화 된 탭을 비활성화 한다.
				quicktab.find(".quicktabs-tabs").children("li").eq(idx).addClass("active");	// 인덱스 번호에 해당하는 탭을 활성화 한다.
			}
		});
	}
	
	// Placeholder //
	// English //
	$(".i18n-en").find(".header_search").find(".form-item-search-block-form").children(".form-text").attr("placeholder", "Search");		// header search
	$(".i18n-en").find(".form-item-combine").find(".form-text").attr("placeholder", "Keyword");						// Filter - Keyword
	$(".i18n-en").find(".view-members-for-community").find(".view-filters").find(".form-item-uid").find(".form-text").attr("placeholder", "Name");						// Filter - Name
	$(".form-item-date-filter-min").find(".form-text").attr("placeholder", today);					// Filter - Min date
	$(".form-item-date-filter-max").find(".form-text").attr("placeholder", today);					// Filter - Max date
	$(".form-item-date-filter-1-min").find(".form-text").attr("placeholder", today);					// Filter - another Min date
	$(".form-item-date-filter-1-max").find(".form-text").attr("placeholder", today);				// Filter - another Max date
	$(".i18n-en.page-ldap-search").find(".view-filters").find(".views-exposed-form").find(".views-widget").find(".form-item-cn").find(".form-text").attr("placeholder", "User Name(CN)");				// LDAP Search - CN	
	$(".i18n-en.page-ldap-search").find(".view-filters").find(".views-exposed-form").find(".views-widget").find(".form-item-attribute").find(".form-text").attr("placeholder", "LDAP Attribute");				// LDAP Search - Attribute		
	// Espanol //
	$(".i18n-es").find(".header_search").find(".form-item-search-block-form").children(".form-text").attr("placeholder", "busqueda");		// header search
	$(".i18n-es").find(".form-item-combine").find(".form-text").attr("placeholder", "Palabra clave");						// Filter - Keyword
	$(".i18n-es").find(".view-members-for-community").find(".view-filters").find(".form-item-uid").find(".form-text").attr("placeholder", "nombre");						// Filter - nombre
	$(".i18n-es.page-ldap-search").find(".view-filters").find(".views-exposed-form").find(".views-widget").find(".form-item-cn").find(".form-text").attr("placeholder", "Nombre de Usuario (CN)");				// LDAP Search - CN	
	$(".i18n-es.page-ldap-search").find(".view-filters").find(".views-exposed-form").find(".views-widget").find(".form-item-attribute").find(".form-text").attr("placeholder", "LDAP Atributo");				// LDAP Search - Attribute			
	
	// Translation //
	$(".i18n-en").find("div.view.edusitios").find(".view-filters").find(".views-widget-filter-field_edusitio_category_tid").find("label").text("Search Edusitios by");
	$(".i18n-es").find("div.view.edusitios").find(".view-filters").find(".views-widget-filter-field_edusitio_category_tid").find("label").text("Buscar Edusitios por");
	$(".page-user-login.i18n-en").find(".sns_group").find("h3").text("Or log in with...");
	$(".page-user-login.i18n-es").find(".sns_group").find("h3").text("O accede con...");
	$(".i18n-en.page-teachers-bankofhomestudentwork").find(".section_content").children("h2").text("Bank of homework");
	$(".i18n-es.page-teachers-bankofhomestudentwork").find(".section_content").children("h2").text("Banco de tareas");
	$(".i18n-en.page-user-password").find(".section_content").children("h2").text("My Account");
	$(".i18n-es.page-user-password").find(".section_content").children("h2").text("Mi Cuenta");
	$(".i18n-es").find("#og-group-ref-add-more-wrapper").find(".form-item-og-group-ref-und-0-default").find("label").text("Sus grupos");
	$(".i18n-es").find("#og-group-ref-add-more-wrapper").find(".form-item-og-group-ref-und-0-default").find(".description").text("Asociar este contenido con los grupos al que pertenece.");
	$(".i18n-es").find("#og-group-ref-add-more-wrapper").find(".form-item-og-group-ref-und-0-admin").find("label").text("Otros grupos");
	$(".i18n-es").find("#og-group-ref-add-more-wrapper").find(".form-item-og-group-ref-und-0-admin").find(".description").text("Como administrador de grupos, asociar este contenido con los grupos que no pertenece.");


	// 이용약관 확인 //
	$("#term_check_container").submit(function() {
		if(!$("input:checkbox[id='check']").is(":checked")) {
			alert("Please agree Terms of Use.");
			return false;
		}
	});
	
	// Zoom in & Zoom out
	var scale = 1;				// Initial Scale
	 
	 // Zoom in //
	function scaleIn() {
		if(scale < 1.15) {
			scale += 0.05;
			zoom(scale);
		}
		else {
			alert("Maximum zooms");
		}
	}
	 
	 // Zoom out //
	function scaleOut() {
		if(scale > 0.85) {
			scale -= 0.05;
			zoom(scale);
		}
		else {
			alert("Minimum zooms");
		}
	}
	 // Modify Zoom Scale //
	function zoom(scale) {		
		var body = document.body;
		body.style.zoom = scale;  // IE
		body.style.webkitTransform = 'scale('+scale+')';  // Webkit(chrome)
		body.style.webkitTransformOrigin = '0 0';
		body.style.MozTransform = 'scale('+scale+')';  // Mozilla(firefox)
		body.style.MozTransformOrigin = '0 0';
		body.style.oTransform = 'scale('+scale+')';  // Opera
		body.style.oTransformOrigin = '0 0';
	}
	
	// Zoom in Button Click Event //
	$(".header").find(".zoom_in").bind("click", function() {				// 축소버튼 클릭
		scaleIn();
	});

	// Reset Zoom Scale Button Click Event //
	$(".header").find(".zoom_reset").bind("click", function() {			// 비율 초기화 버튼 클릭
		scale = 1;
		zoom(scale);
	});

	// Zoom Out Button Click Event //
	$(".header").find(".zoom_out").bind("click", function() {			// 확대버튼 클릭
		scaleOut();
	});

	// User Register 버튼 추가 //
	if($('body').hasClass('page-user-register')) {
		if($('body').hasClass('i18n-en')) {
			var registry_text = "Registry";
		}
		else {
			var registry_text = "Registro";	
		}
		$('.page-user-register').find(".user-info-from-cookie").find('.form-actions').append("<a href='http://aplicaciones.colombiaaprende.edu.co/php-login/controller_content.php?Vista=Q29udGVudA==&Opcion=UmVnaXN0cmFy' class='btn_registry'>" + registry_text + "</a>");
	}
		
	var old_state = 0;
	var current_state = 0;
		
	// 웹 브라우져 크기가 변경될 때마다 실행된다. //
	$(window).resize(function() {
		window_width = $(window).width();			// Web browser width
		window_height = $(window).height();			// Web browser height
		
		var header_height = $(".wrapper").children(".header").height();							// Header height
		var search_height = $(".wrapper").children(".header_search").height();				// Search bar height
		var user_height = $(".wrapper").children(".user_menu_container").height();		// User menu height

		var section_contentHeight = $(".section_container").children(".section_content").height();
		var left_sidebarHeight = $(".section_container").children(".left_sidebar").children(".region").height();

		if(section_contentHeight > left_sidebarHeight) {
			$(".section_container").children(".left_sidebar").css("height", section_contentHeight);	
		}
		else if(section_contentHeight < left_sidebarHeight) {
			// $(".section_container").children(".section_content").css("height", left_sidebarHeight);	
		}
					
		if(window_width >= 1008 && window_width <= 9999) {				// Desktop
			current_state = 1;
			// 브라우져 크기가 Desktop에 최적화 될 경우 실행한다. //
			if(current_state != old_state) {
				if($("body").hasClass("node-type-guideline")) {
					extract_index_height(false);
				}

				// Agenda Main - Layout Relocation //	
				if($("body").hasClass("page-node-1731") || $("body").hasClass("page-node-4329")) {			
					$(".section_content").css("marginTop", 0);
				}
				$(".header_container").children(".secondary_menu").css("display", "initial");
				$(".user_menu_container").css("height", "40px");

				poll_autoHeight(1);
			}
			old_state = current_state;
		}
		else if(window_width >= 751 && window_width <= 1007) {		// Tablet
			current_state = 2;
			// 브라우져 크기가 Table 에 최적화 될 경우 실행한다. //
			if(current_state != old_state) {
				$(".header_container").children(".secondary_menu").css("display", "initial");
				$(".main_container").find(".left_sidebar").removeAttr("style");
				$(".user_menu_container").css("height", "40px");
				
				// Check Resource popup //
				$(".courseware").show();
				$(".uol_popup").show();
								
				// Agenda Main - Layout Relocation //	
				if($("body").hasClass("page-node-1731") || $("body").hasClass("page-node-4329")) {			
					$(".section_content").css("marginTop", 0);
				}
				poll_autoHeight(2);
			}
			old_state = current_state;
		}
		else if(window_width <= 750) {																// Smartphone
			// 브라우져 크기가 Mobile 에 최적화 될 경우 실행한다. //
			current_state = 3;
			if(current_state != old_state) {
				$(".main_container").find(".left_sidebar").removeAttr("style");
				var user_menu_length = $(".user_menu").find(".content").children(".menu").children("li").length;
				var user_menu_height = 40 * Math.ceil(user_menu_length / 4);
				
				$(".header_container").children(".secondary_menu").css("display", "none");
				$(".user_menu_container").css("height", "80px");
				$(".main_container").find(".left_sidebar").hide();
				
				// Check Resource popup //
				if(chk_resource_popup) {
					$(".courseware").hide();
					$(".uol_popup").hide();
				}
				else {
					$(".courseware").show();
					$(".uol_popup").show();
				}
			}
			old_state = current_state;
		}
	}).resize();	

	function poll_autoHeight(state) {
		$main6 = $(".main6");
		var main6_height = $main6.height();

		if(state == 1) {
			var region_height = Math.ceil(($main6.children(".region").height() - 11) / 180);
			$main6.css("height", region_height * 200 - 20);
		}
		// Tablet //
		else if(state == 2) {
			var region_height = Math.ceil(($main6.children(".region").height() - 11) / 149);
			$main6.css("height", region_height * 160, "important");
		}
	}
});

// Set Cookie : Cookie를 생성한다. //
function setCookie(cookie_name, cookie_value, cookie_date) {
	var expire = new Date();
	expire.setDate(expire.getDate() + cookie_date);
	cookies = cookie_name + '=' + escape(cookie_value) + '; path=/ '; // 한글 깨짐을 막기위해 escape(cookie_value)를 합니다.
	if(typeof cookie_date != 'undefined') cookies += ';expires=' + expire.toGMTString() + ';';
	document.cookie = cookies;
}

// Get Cookie  지정한 Cookie를 삭제한다. //
function getCookie(cookie_name) {
	cookie_name = cookie_name + '=';
	var cookieData = document.cookie;
	var start = cookieData.indexOf(cookie_name);
	var cookie_value = '';
	if(start != -1) {
		start += cookie_name.length;
		var end = cookieData.indexOf(';', start);
		if(end == -1) end = cookieData.length;
		cookie_value = cookieData.substring(start, end);
	}
	return unescape(cookie_value);
};
/*
 * Example usage:
 * $(elem).animate( {top: 100}, $.easie(0.25,0.1,0.25,1.0) );
 */
 
/*
 * jquery.easie.js:
 * http://www.github.com/jaukia/easie
 *
 * Version history:
 * 1.0.1 Semver versioning for jQuery plugins repository
 * 1.0.0 Initial public version
 *
 * LICENCE INFORMATION:
 *
 * Copyright (c) 2011 Janne Aukia (janne.aukia.com),
 * Louis-Rémi Babé (public@lrbabe.com).
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL Version 2 (GPL-LICENSE.txt) licenses.
 *
 * LICENCE INFORMATION FOR DERIVED FUNCTIONS:
 *
 * Function cubicBezierAtTime is written by Christian Effenberger, 
 * and corresponds 1:1 to the WebKit project function.
 * "WebCore and JavaScriptCore are available under the 
 * Lesser GNU Public License. WebKit is available under 
 * a BSD-style license."
 *
 
 
이 파일은 시간의 흐름에 따라 움직이거나, Fade-in Fade-out, 또는 크기와 형태가 변하는 액션에 가속도를 적용하는 Plug-in 파일이다.
적용할 수 있는 가속도의 종류는 http://jaukia.github.io/easie/ 이 곳에서 확인할 수 있다.
 */

/*jslint sub: true */

jQuery(document).ready(function($) {
    "use strict";

    var prefix = "easie",
        ease = "Ease",
        easeIn = prefix+ease+"In",
        easeOut = prefix+ease+"Out",
        easeInOut = prefix+ease+"InOut",
        names = ["Quad","Cubic","Quart","Quint","Sine","Expo","Circ"];

    $.easie = function(p1x,p1y,p2x,p2y,name,forceUpdate) {
        name = name || [prefix,p1x,p1y,p2x,p2y].join("-");
        if ( !$.easing[name] || forceUpdate ) {
            // around 40x faster with lookup than without it in FF4
            var cubicBezierAtTimeLookup = makeLookup(function(p) {
                // the duration is set to 5.0. this defines the precision of the bezier calculation.
                // the animation is ok for durations up to 5 secs with this.
                // with the lookup table, the precision can be high without any big penalty.
                return cubicBezierAtTime(p,p1x,p1y,p2x,p2y,5.0);
            });
    
            $.easing[name] = function(p, n, firstNum, diff) {
                return cubicBezierAtTimeLookup.call(null, p);
            }
            $.easing[name].params = [p1x,p1y,p2x,p2y];
        }
        return name;
    }

    var $easie = $.easie;

    // default css3 easings

    $easie(0.000, 0.000, 1.000, 1.000, prefix+"Linear");
    $easie(0.250, 0.100, 0.250, 1.000, prefix+ease);
    $easie(0.420, 0.000, 1.000, 1.000, easeIn);
    $easie(0.000, 0.000, 0.580, 1.000, easeOut);
    $easie(0.420, 0.000, 0.580, 1.000, easeInOut);

    // approximated Penner equations, from:
    // http://matthewlein.com/ceaser/
    
    $easie(0.550, 0.085, 0.680, 0.530, easeIn+names[0]);
    $easie(0.550, 0.055, 0.675, 0.190, easeIn+names[1]);
    $easie(0.895, 0.030, 0.685, 0.220, easeIn+names[2]);
    $easie(0.755, 0.050, 0.855, 0.060, easeIn+names[3]);
    $easie(0.470, 0.000, 0.745, 0.715, easeIn+names[4]);
    $easie(0.950, 0.050, 0.795, 0.035, easeIn+names[5]);
    $easie(0.600, 0.040, 0.980, 0.335, easeIn+names[6]);
                    
    $easie(0.250, 0.460, 0.450, 0.940, easeOut+names[0]);
    $easie(0.215, 0.610, 0.355, 1.000, easeOut+names[1]);
    $easie(0.165, 0.840, 0.440, 1.000, easeOut+names[2]);
    $easie(0.230, 1.000, 0.320, 1.000, easeOut+names[3]);
    $easie(0.390, 0.575, 0.565, 1.000, easeOut+names[4]);
    $easie(0.190, 1.000, 0.220, 1.000, easeOut+names[5]);
    $easie(0.075, 0.820, 0.165, 1.000, easeOut+names[6]);
                    
    $easie(0.455, 0.030, 0.515, 0.955, easeInOut+names[0]);
    $easie(0.645, 0.045, 0.355, 1.000, easeInOut+names[1]);
    $easie(0.770, 0.000, 0.175, 1.000, easeInOut+names[2]);
    $easie(0.860, 0.000, 0.070, 1.000, easeInOut+names[3]);
    $easie(0.445, 0.050, 0.550, 0.950, easeInOut+names[4]);
    $easie(1.000, 0.000, 0.000, 1.000, easeInOut+names[5]);
    $easie(0.785, 0.135, 0.150, 0.860, easeInOut+names[6]);

    function makeLookup(func,steps) {
        var i;
        steps = steps || 101;
        var lookupTable = [];
        for(i=0;i<(steps+1);i++) {
            lookupTable[i] = func.call(null,i/steps);
        }
        return function(p) {
            if(p===1) return lookupTable[steps];
            var sp = steps*p;
            // fast flooring, see
            // http://stackoverflow.com/questions/2526682/why-is-javascripts-math-floor-the-slowest-way-to-calculate-floor-in-javascript
            var p0 = Math.floor(sp);
            var y1 = lookupTable[p0];
            var y2 = lookupTable[p0+1];
            return y1+(y2-y1)*(sp-p0);
        }
    }

    // From: http://www.netzgesta.de/dev/cubic-bezier-timing-function.html
    // 1:1 conversion to js from webkit source files
    // UnitBezier.h, WebCore_animation_AnimationBase.cpp
    function cubicBezierAtTime(t,p1x,p1y,p2x,p2y,duration) {
        var ax=0,bx=0,cx=0,ay=0,by=0,cy=0;
        // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
        function sampleCurveX(t) {return ((ax*t+bx)*t+cx)*t;}
        function sampleCurveY(t) {return ((ay*t+by)*t+cy)*t;}
        function sampleCurveDerivativeX(t) {return (3.0*ax*t+2.0*bx)*t+cx;}
        // The epsilon value to pass given that the animation is going to run over |dur| seconds. The longer the
        // animation, the more precision is needed in the timing function result to avoid ugly discontinuities.
        function solveEpsilon(duration) {return 1.0/(200.0*duration);}
        function solve(x,epsilon) {return sampleCurveY(solveCurveX(x,epsilon));}
        // Given an x value, find a parametric value it came from.
        function solveCurveX(x,epsilon) {var t0,t1,t2,x2,d2,i;
            function fabs(n) {if(n>=0) {return n;}else {return 0-n;}}
            // First try a few iterations of Newton's method -- normally very fast.
            for(t2=x, i=0; i<8; i++) {x2=sampleCurveX(t2)-x; if(fabs(x2)<epsilon) {return t2;} d2=sampleCurveDerivativeX(t2); if(fabs(d2)<1e-6) {break;} t2=t2-x2/d2;}
            // Fall back to the bisection method for reliability.
            t0=0.0; t1=1.0; t2=x; if(t2<t0) {return t0;} if(t2>t1) {return t1;}
            while(t0<t1) {x2=sampleCurveX(t2); if(fabs(x2-x)<epsilon) {return t2;} if(x>x2) {t0=t2;}else {t1=t2;} t2=(t1-t0)*0.5+t0;}
            return t2; // Failure.
        }
        // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
        cx=3.0*p1x; bx=3.0*(p2x-p1x)-cx; ax=1.0-cx-bx; cy=3.0*p1y; by=3.0*(p2y-p1y)-cy; ay=1.0-cy-by;
        // Convert from input time to parametric value in curve, then from that to output time.
        return solve(t, solveEpsilon(duration));
    }
});;
/*
 * jQuery UI Touch Punch 0.2.2
 *
 * Copyright 2011, Dave Furfero
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 * Depends:
 *  jquery.ui.widget.js
 *  jquery.ui.mouse.js
 */
jQuery(document).ready(function(b) {
	b.support.touch="ontouchend" in document;if(!b.support.touch){return;}var c=b.ui.mouse.prototype,e=c._mouseInit,a;function d(g,h){if(g.originalEvent.touches.length>1){return;}g.preventDefault();var i=g.originalEvent.changedTouches[0],f=document.createEvent("MouseEvents");f.initMouseEvent(h,true,true,window,1,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,0,null);g.target.dispatchEvent(f);}c._touchStart=function(g){var f=this;if(a||!f._mouseCapture(g.originalEvent.changedTouches[0])){return;}a=true;f._touchMoved=false;d(g,"mouseover");d(g,"mousemove");d(g,"mousedown");};c._touchMove=function(f){if(!a){return;}this._touchMoved=true;d(f,"mousemove");};c._touchEnd=function(f){if(!a){return;}d(f,"mouseup");d(f,"mouseout");if(!this._touchMoved){d(f,"click");}a=false;};c._mouseInit=function(){var f=this;f.element.bind("touchstart",b.proxy(f,"_touchStart")).bind("touchmove",b.proxy(f,"_touchMove")).bind("touchend",b.proxy(f,"_touchEnd"));e.call(f);};
});;
/**
 * jQuery Masonry v2.1.08
 * A dynamic layout plugin for jQuery
 * The flip-side of CSS Floats
 * http://masonry.desandro.com
 *
 * Licensed under the MIT license.
 * Copyright 2012 David DeSandro
 
 
 이 파일은 지정한 HTML 태그들을 브라우져의 크기에 따라 재배치 시키는 기능을 구현하기 위해 필요한 Plug-in 파일이다.
 위에 있는 URL로 이동하면 이 Plug-in에 대한 보다 자세한 정보를 확인할 수 있다
 */
(function(e,t,n){"use strict";var r=t.event,i;r.special.smartresize={setup:function(){t(this).bind("resize",r.special.smartresize.handler)},teardown:function(){t(this).unbind("resize",r.special.smartresize.handler)},handler:function(e,t){var n=this,s=arguments;e.type="smartresize",i&&clearTimeout(i),i=setTimeout(function(){r.dispatch.apply(n,s)},t==="execAsap"?0:100)}},t.fn.smartresize=function(e){return e?this.bind("smartresize",e):this.trigger("smartresize",["execAsap"])},t.Mason=function(e,n){this.element=t(n),this._create(e),this._init()},t.Mason.settings={isResizable:!0,isAnimated:!1,animationOptions:{queue:!1,duration:500},gutterWidth:0,isRTL:!1,isFitWidth:!1,containerStyle:{position:"relative"}},t.Mason.prototype={_filterFindBricks:function(e){var t=this.options.itemSelector;return t?e.filter(t).add(e.find(t)):e},_getBricks:function(e){var t=this._filterFindBricks(e).css({position:"absolute"}).addClass("masonry-brick");return t},_create:function(n){this.options=t.extend(!0,{},t.Mason.settings,n),this.styleQueue=[];var r=this.element[0].style;this.originalStyle={height:r.height||""};var i=this.options.containerStyle;for(var s in i)this.originalStyle[s]=r[s]||"";this.element.css(i),this.horizontalDirection=this.options.isRTL?"right":"left";var o=this.element.css("padding-"+this.horizontalDirection),u=this.element.css("padding-top");this.offset={x:o?parseInt(o,10):0,y:u?parseInt(u,10):0},this.isFluid=this.options.columnWidth&&typeof this.options.columnWidth=="function";var a=this;setTimeout(function(){a.element.addClass("masonry")},0),this.options.isResizable&&t(e).bind("smartresize.masonry",function(){a.resize()}),this.reloadItems()},_init:function(e){this._getColumns(),this._reLayout(e)},option:function(e,n){t.isPlainObject(e)&&(this.options=t.extend(!0,this.options,e))},layout:function(e,t){for(var n=0,r=e.length;n<r;n++)this._placeBrick(e[n]);var i={};i.height=Math.max.apply(Math,this.colYs);if(this.options.isFitWidth){var s=0;n=this.cols;while(--n){if(this.colYs[n]!==0)break;s++}i.width=(this.cols-s)*this.columnWidth-this.options.gutterWidth}this.styleQueue.push({$el:this.element,style:i});var o=this.isLaidOut?this.options.isAnimated?"animate":"css":"css",u=this.options.animationOptions,a;for(n=0,r=this.styleQueue.length;n<r;n++)a=this.styleQueue[n],a.$el[o](a.style,u);this.styleQueue=[],t&&t.call(e),this.isLaidOut=!0},_getColumns:function(){var e=this.options.isFitWidth?this.element.parent():this.element,t=e.width();this.columnWidth=this.isFluid?this.options.columnWidth(t):this.options.columnWidth||this.$bricks.outerWidth(!0)||t,this.columnWidth+=this.options.gutterWidth,this.cols=Math.floor((t+this.options.gutterWidth)/this.columnWidth),this.cols=Math.max(this.cols,1)},_placeBrick:function(e){var n=t(e),r,i,s,o,u;r=Math.ceil(n.outerWidth(!0)/this.columnWidth),r=Math.min(r,this.cols);if(r===1)s=this.colYs;else{i=this.cols+1-r,s=[];for(u=0;u<i;u++)o=this.colYs.slice(u,u+r),s[u]=Math.max.apply(Math,o)}var a=Math.min.apply(Math,s),f=0;for(var l=0,c=s.length;l<c;l++)if(s[l]===a){f=l;break}var h={top:a+this.offset.y};h[this.horizontalDirection]=this.columnWidth*f+this.offset.x,this.styleQueue.push({$el:n,style:h});var p=a+n.outerHeight(!0),d=this.cols+1-c;for(l=0;l<d;l++)this.colYs[f+l]=p},resize:function(){var e=this.cols;this._getColumns(),(this.isFluid||this.cols!==e)&&this._reLayout()},_reLayout:function(e){var t=this.cols;this.colYs=[];while(t--)this.colYs.push(0);this.layout(this.$bricks,e)},reloadItems:function(){this.$bricks=this._getBricks(this.element.children())},reload:function(e){this.reloadItems(),this._init(e)},appended:function(e,t,n){if(t){this._filterFindBricks(e).css({top:this.element.height()});var r=this;setTimeout(function(){r._appended(e,n)},1)}else this._appended(e,n)},_appended:function(e,t){var n=this._getBricks(e);this.$bricks=this.$bricks.add(n),this.layout(n,t)},remove:function(e){this.$bricks=this.$bricks.not(e),e.remove()},destroy:function(){this.$bricks.removeClass("masonry-brick").each(function(){this.style.position="",this.style.top="",this.style.left=""});var n=this.element[0].style;for(var r in this.originalStyle)n[r]=this.originalStyle[r];this.element.unbind(".masonry").removeClass("masonry").removeData("masonry"),t(e).unbind(".masonry")}},t.fn.imagesLoaded=function(e){function u(){e.call(n,r)}function a(e){var n=e.target;n.src!==s&&t.inArray(n,o)===-1&&(o.push(n),--i<=0&&(setTimeout(u),r.unbind(".imagesLoaded",a)))}var n=this,r=n.find("img").add(n.filter("img")),i=r.length,s="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",o=[];return i||u(),r.bind("load.imagesLoaded error.imagesLoaded",a).each(function(){var e=this.src;this.src=s,this.src=e}),n};var s=function(t){e.console&&e.console.error(t)};t.fn.masonry=function(e){if(typeof e=="string"){var n=Array.prototype.slice.call(arguments,1);this.each(function(){var r=t.data(this,"masonry");if(!r){s("cannot call methods on masonry prior to initialization; attempted to call method '"+e+"'");return}if(!t.isFunction(r[e])||e.charAt(0)==="_"){s("no such method '"+e+"' for masonry instance");return}r[e].apply(r,n)})}else this.each(function(){var n=t.data(this,"masonry");n?(n.option(e||{}),n._init()):t.data(this,"masonry",new t.Mason(e,this))});return this}})(window,jQuery);;
/* Modernizr custom build of 1.7: csstransitions */
window.Modernizr=function(a,b,c){function G(){}function F(a,b){var c=a.charAt(0).toUpperCase()+a.substr(1),d=(a+" "+p.join(c+" ")+c).split(" ");return!!E(d,b)}function E(a,b){for(var d in a)if(k[a[d]]!==c&&(!b||b(a[d],j)))return!0}function D(a,b){return(""+a).indexOf(b)!==-1}function C(a,b){return typeof a===b}function B(a,b){return A(o.join(a+";")+(b||""))}function A(a){k.cssText=a}var d="1.7",e={},f=!0,g=b.documentElement,h=b.head||b.getElementsByTagName("head")[0],i="modernizr",j=b.createElement(i),k=j.style,l=b.createElement("input"),m=":)",n=Object.prototype.toString,o=" -webkit- -moz- -o- -ms- -khtml- ".split(" "),p="Webkit Moz O ms Khtml".split(" "),q={svg:"http://www.w3.org/2000/svg"},r={},s={},t={},u=[],v,w=function(a){var c=b.createElement("style"),d=b.createElement("div"),e;c.textContent=a+"{#modernizr{height:3px}}",h.appendChild(c),d.id="modernizr",g.appendChild(d),e=d.offsetHeight===3,c.parentNode.removeChild(c),d.parentNode.removeChild(d);return!!e},x=function(){function d(d,e){e=e||b.createElement(a[d]||"div");var f=(d="on"+d)in e;f||(e.setAttribute||(e=b.createElement("div")),e.setAttribute&&e.removeAttribute&&(e.setAttribute(d,""),f=C(e[d],"function"),C(e[d],c)||(e[d]=c),e.removeAttribute(d))),e=null;return f}var a={select:"input",change:"input",submit:"form",reset:"form",error:"img",load:"img",abort:"img"};return d}(),y=({}).hasOwnProperty,z;C(y,c)||C(y.call,c)?z=function(a,b){return b in a&&C(a.constructor.prototype[b],c)}:z=function(a,b){return y.call(a,b)},r.csstransitions=function(){return F("transitionProperty")};for(var H in r)z(r,H)&&(v=H.toLowerCase(),e[v]=r[H](),u.push((e[v]?"":"no-")+v));e.input||G(),e.crosswindowmessaging=e.postmessage,e.historymanagement=e.history,e.addTest=function(a,b){a=a.toLowerCase();if(!e[a]){b=!!b(),g.className+=" "+(b?"":"no-")+a,e[a]=b;return e}},A(""),j=l=null,e._enableHTML5=f,e._version=d,g.className=g.className.replace(/\bno-js\b/,"")+" js "+u.join(" ");return e}(this,this.document);
