/* ------------------------------------
*
*Since: 2008-04-24
*Editor: BBmedia Inc. D_sasaki
*
-------------------------------------*/
$(function(){
	// flatheight
	var setHeight = function(node,number){
		var number2 = number - 1;
		var sets = [], temp = [];
		$(node).each(function(i) {
			temp.push(this);
			if (i % number == number2) {
				sets.push(temp);
				temp = [];
			}
		});
		if (temp.length) sets.push(temp);
		
		return function(){
			$.each(sets, function() {
				$(this).flatHeights();
			});	
		}
	}
	
	var camSetHeight = setHeight('.camSection .title',4);
	var comSetHeight = setHeight('.comSection .title',4);	
	var blogSetHeight = setHeight('.blogNewsSection dl dt',4);
	var camHeightFix = true;
	var comHeightFix = true;
	
	blogSetHeight();

	//getcookie
	var value = "";
	ar_value = document.cookie.split(";");
	for(i=0; i<ar_value.length; i++){
		if(ar_value[i].indexOf("top_tab") != -1){
			value = ar_value[i].split("=")[1];
			break;
		}
	}
	if(value.indexOf("list") == -1){
		value = "";
	}
	
	if(value) {
		var defaultTabId = "#" + unescape(value);
		$(defaultTabId).addClass("on");
		var defaultContentId = "#" + $(defaultTabId).attr("href").split("#")[1];
		$(defaultContentId).show().siblings("div:visible").hide();
		
		if(value == "list02"){
			camSetHeight();
			camHeightFix = false
		}else if(value == "list03"){
			comSetHeight();
			comHeightFix = false
		}
		
	}else {
		$("#content02, #content03").hide()
		$("#list01").addClass("on")
	}
	/**/
	//margin
	var campusItem = $(".camSection").size()
	if(campusItem < 5) {
		$(".camSection").css("margin-left","15px");
		$("#content02 h2").css("margin-left","15px");
	}else {
		$("#content02").css("overflow","auto");	
	}
	
	var comunityItem = $(".comSection").size()
	if(comunityItem < 5) {
		$(".comSection").css("margin-left","15px");
		$("#content03 h2").css("margin-left","15px");
	}else {
		$("#content03").css("overflow","auto");	
	}
	
	//blogTopic
	var hiddenBlogs = $(".blogNewsSection:gt(7)");
	$(hiddenBlogs).hide();
	$("#moreBtn a").click(function(){
		$(hiddenBlogs).toggle();	
		$(this).toggleClass("open");	
		return false;
	}).focus(function(){
		$(this).blur();
	})
	
	//tab
	$("#list a").click(function(){
		$(this).addClass("on").parent().parent().find("a").not(this).removeClass("on")
		var targetID = "#" + $(this).attr("href").split("#")[1]
		$(targetID).show().siblings("div:visible").hide();
		
		var thisTabId = $(this).attr("id")
		if(thisTabId == "list02" && camHeightFix){
			camSetHeight();
			camHeightFix = false;
		}else if(thisTabId == "list03" && comHeightFix){
			comSetHeight();
			comHeightFix = false;
		}
		
		setUnloadCookie("top_tab=" + thisTabId);
		return false;	
	})
	.focus(function(){
		$(this).blur();
	})	
})

function setUnloadCookie(param){
	window.onunload = function(){
		document.cookie = param;
	}
	
}


