var timerlen = 5;
var slideAniLen = 250;

var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var dir = new Array();
var moving = new Array();
var themeRoot = themeDisplay.getPathThemeImages();

var prevNav = "";
var prevNavTyl = ""

var navModuleCount = new Array();
navModuleCount[1] = 3;
navModuleCount[2] = 2;
navModuleCount[3] = 3;

var jkmPortletsArray = new Array(3);
	
jkmPortletsArray [0] = new Array(3);

jkmPortletsArray [0][0] = "JKM_MC_AEROBIC_SM1_WAR_jkm_portal";
jkmPortletsArray [0][1] = "JKM_MC_STRENGTHENING_SM1_WAR_jkm_portal";
jkmPortletsArray [0][2] = "JKM_MC_STRETCHING_SM1_WAR_jkm_portal";

jkmPortletsArray [1] = new Array(2);

jkmPortletsArray [1][0] = "JKM_BL_HEALTHY_SM1_WAR_jkm_portal";
jkmPortletsArray [1][1] = "JKM_BL_BMI_SM1_WAR_jkm_portal";

jkmPortletsArray [2] = new Array(3);

jkmPortletsArray [2][0] = "JKM_EA_LIVING_SM1_WAR_jkm_portal";
jkmPortletsArray [2][1] = "JKM_EA_PAIN_SM1_WAR_jkm_portal";
jkmPortletsArray [2][2] = "JKM_EA_WEATHER_TPL_WAR_jkm_portal";

function slidedown(objname, whichNav){
	if (objname == "nav") {
		var moduleCount = navModuleCount[whichNav];
		var numModuleRows = moduleCount/3;
		if ((moduleCount % 3) > 0) {
			numModuleRows = Math.floor(moduleCount / 3) + 1;
		}
		
		document.getElementById('nav').style.height = 54 + (111 * numModuleRows) + "px";
		document.getElementById('navContent').style.height = 6 + (111 * numModuleRows) + "px";

		if (document.getElementById('nav').style.display == "block") {
			if (prevNav == whichNav) {
				slideup(objname);
				return;
			}

			for (x=1; x<4; x++) {
				document.getElementById('nav_'+x).setAttribute("src",themeRoot+"/jkm/nav_"+x+"_off.gif");
				document.getElementById('portlets_' + x).style.display = 'none';
			}
			
			document.getElementById('portlets_' + whichNav).style.display = 'block';
			document.getElementById('nav_'+whichNav).setAttribute("src",themeRoot+"/jkm/nav_"+whichNav+"_ro.gif");
			
			if (whichNav != "1")
				document.getElementById('nav_1').onmouseout = function(){this.src=themeRoot+'/jkm/nav_1_off.gif';};
			else
				document.getElementById('nav_1').onmouseout = function(){this.src=themeRoot+'/jkm/nav_1_on.gif';};
			
			if (whichNav != "2")
				document.getElementById('nav_2').onmouseout = function(){this.src=themeRoot+'/jkm/nav_2_off.gif';};
			else
				document.getElementById('nav_2').onmouseout = function(){this.src=themeRoot+'/jkm/nav_2_on.gif';};
			
			if (whichNav != "3")
				document.getElementById('nav_3').onmouseout = function(){this.src=themeRoot+'/jkm/nav_3_off.gif';};
			else
				document.getElementById('nav_3').onmouseout = function(){this.src=themeRoot+'/jkm/nav_3_on.gif';};
			
			prevNav = whichNav;
			return;
		}

		for (x=1; x<4; x++) {
			document.getElementById('nav_'+x).setAttribute("src",themeRoot+"/jkm/nav_"+x+"_off.gif");
		}

		if (whichNav != "1")
			document.getElementById('nav_1').onmouseout = function(){this.src=themeRoot+'/jkm/nav_1_off.gif';};
		
		if (whichNav != "2")
			document.getElementById('nav_2').onmouseout = function(){this.src=themeRoot+'/jkm/nav_2_off.gif';};
		
		if (whichNav != "3")
			document.getElementById('nav_3').onmouseout = function(){this.src=themeRoot+'/jkm/nav_3_off.gif';};
		
	} else {
		document.getElementById('nav_tyl').style.height = "486px";
		if(document.getElementById(objname).style.display == "block") {
			if (prevNavTyl == whichNav) {
				slideup(objname);
				return;
			}
		} else
			prevNavTyl = whichNav;
	}

	moving[objname] = true;
	dir[objname] = "down";
	startslide(objname, whichNav);
}

function slideup(objname){
	if(moving[objname])
		return;

	if(document.getElementById(objname).style.display == "none")
		return;

	moving[objname] = true;
	dir[objname] = "up";
	startslide(objname);

	if (objname == "nav") {
		for (x=1; x<4; x++) {
			document.getElementById('nav_'+x).setAttribute("src",themeRoot+"/jkm/nav_"+x+"_on.gif");
		}
		
		document.getElementById('nav_1').onmouseout = function(){this.src=themeRoot+'/jkm/nav_1_on.gif';};
		document.getElementById('nav_2').onmouseout = function(){this.src=themeRoot+'/jkm/nav_2_on.gif';};
		document.getElementById('nav_3').onmouseout = function(){this.src=themeRoot+'/jkm/nav_3_on.gif';};
	}
}

function startslide(objname, whichNav){
	obj[objname] = document.getElementById(objname);

	endHeight[objname] = parseInt(obj[objname].style.height);
	startTime[objname] = (new Date()).getTime();

	if(dir[objname] == "down"){
		obj[objname].style.height = "1px";
		
		if (objname == "nav") {
			for (x=1; x<4; x++) {
				document.getElementById('portlets_' + x).style.display = 'none';
			}
			document.getElementById('portlets_' + whichNav).style.display = 'block';
			document.getElementById('nav_'+whichNav).setAttribute("src",themeRoot+"/jkm/nav_"+whichNav+"_ro.gif");
			prevNav = whichNav;
		} else {
			prevNavTyl = whichNav;
		}
	}

	obj[objname].style.display = "block";

	timerID[objname] = setInterval('slidetick(\'' + objname + '\');',timerlen);
}

function slidetick(objname){
	var elapsed = (new Date()).getTime() - startTime[objname];

	if (elapsed > slideAniLen)
		endSlide(objname)
	else {
		var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
		if(dir[objname] == "up")
			d = endHeight[objname] - d;

		obj[objname].style.height = d + "px";
    }
    
    return;
}

function endSlide(objname){
	clearInterval(timerID[objname]);

    if(dir[objname] == "up") {
		obj[objname].style.display = "none";
		
		if (objname == "nav") {
			document.getElementById('nav_bottom').style.cursor = 'default';
			document.getElementById('nav_bottom').setAttribute("src",themeRoot+"/jkm/nav_bottom_closed.gif");
			document.getElementById('nav_bottom').onmouseover = function(){document.getElementById('nav_bottom').setAttribute("src",themeRoot+"/jkm/nav_bottom_closed.gif");};
			document.getElementById('nav_bottom').onmouseout = function(){document.getElementById('nav_bottom').setAttribute("src",themeRoot+"/jkm/nav_bottom_closed.gif");};
		} else {
			document.getElementById('nav_ty_bottom').setAttribute("src",themeRoot+"/jkm/nav_ty_bottom_closed_off.gif");
			document.getElementById('nav_ty_bottom').onmouseover = function(){document.getElementById('nav_ty_bottom').setAttribute("src",themeRoot+"/jkm/nav_ty_bottom_closed_on.gif");};
			document.getElementById('nav_ty_bottom').onmouseout = function(){document.getElementById('nav_ty_bottom').setAttribute("src",themeRoot+"/jkm/nav_ty_bottom_closed_off.gif");};
			
			reInitializeProductModule();
		}
	} else {
		if (objname == "nav") {
			document.getElementById('nav_bottom').style.cursor = 'pointer';
			document.getElementById('nav_bottom').setAttribute("src",themeRoot+"/jkm/nav_bottom_opened_off.gif");
			document.getElementById('nav_bottom').onmouseover = function(){document.getElementById('nav_bottom').setAttribute("src",themeRoot+"/jkm/nav_bottom_opened_on.gif");};
			document.getElementById('nav_bottom').onmouseout = function(){document.getElementById('nav_bottom').setAttribute("src",themeRoot+"/jkm/nav_bottom_opened_off.gif");};
		} else {
			document.getElementById('nav_ty_bottom').setAttribute("src",themeRoot+"/jkm/nav_ty_bottom_opened_off.gif");
			document.getElementById('nav_ty_bottom').onmouseover = function(){document.getElementById('nav_ty_bottom').setAttribute("src",themeRoot+"/jkm/nav_ty_bottom_opened_on.gif");};
			document.getElementById('nav_ty_bottom').onmouseout = function(){document.getElementById('nav_ty_bottom').setAttribute("src",themeRoot+"/jkm/nav_ty_bottom_opened_off.gif");};
		}
    }

	obj[objname].style.height = endHeight[objname] + "px";

	delete(moving[objname]);
	delete(timerID[objname]);
	delete(startTime[objname]);
	delete(endHeight[objname]);
	delete(obj[objname]);
	delete(dir[objname]);

	return;
}

function reInitializeProductModule() {
	for (x=1; x<3; x++) {
		document.getElementById('nav_tyl_prod' + x).style.display = 'none';
		
		for (y=1; y<4; y++) {
			document.getElementById('nav_tyl_prod' + x + '_tab' + y).style.display = 'none';
		}
		
		document.getElementById('nav_5_x_0' + x).setAttribute("src",themeRoot+"/jkm/nav_5_x_0"+x+"_off.gif");
	}
	
	document.getElementById('nav_5_x_01').setAttribute("src",themeRoot+"/jkm/nav_5_x_01_on.gif");
	document.getElementById('nav_5_x_02').setAttribute("src",themeRoot+"/jkm/nav_5_x_02_off.gif");
	document.getElementById('nav_5_x_03').setAttribute("src",themeRoot+"/jkm/nav_5_x_03_off.gif");
	
	document.getElementById('nav_5_x_01').onmouseover = function(){this.src=themeRoot+'/jkm/nav_5_x_01_on.gif';};
	document.getElementById('nav_5_x_01').onmouseout = function(){this.src=themeRoot+'/jkm/nav_5_x_01_on.gif';};

	document.getElementById('nav_5_x_02').onmouseover = function(){this.src=themeRoot+'/jkm/nav_5_x_02_ro.gif';};
	document.getElementById('nav_5_x_02').onmouseout = function(){this.src=themeRoot+'/jkm/nav_5_x_02_off.gif';};

	document.getElementById('nav_5_x_03').onmouseover = function(){this.src=themeRoot+'/jkm/nav_5_x_03_ro.gif';};
	document.getElementById('nav_5_x_03').onmouseout = function(){this.src=themeRoot+'/jkm/nav_5_x_03_off.gif';};

	document.getElementById('nav_tyl_prod1').style.display = 'block';
	document.getElementById('nav_tyl_prod1_tab1').style.display = 'block';
	
	prevProductModule = 1;
	prevProductModuleTab = 1;
}