﻿// JScript File
menu_status = new Array();


//function SetOnMenuLoad()
//{
//    var CurrentMenuItem = GetCookie ("ActiveMenuItem");
//    if(CurrentMenuItem != null)
//    {
//        document.getElementById(CurrentMenuItem).className = 'show';
//    }
//}

function SetCookie (name, value) 
{
        //creating expiration date

        var ExpireyDate = new Date();
//        1000 - The number of milliseconds in a second.
//        60 (first one) - The number of seconds in a minute.
//        60 (second one) - The number of minutes in an hour.
//        24 - The number of hours in a day.
//        365 - The number of days in a year.
        ExpireyDate.setTime(ExpireyDate.getTime() + 1000 * 60 * 30 )
        
        
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        //var expires = (argc > 2) ? argv[2] : null;
        var expires = ExpireyDate;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}

function showHide(theid){
    if (document.getElementById) 
	{// close all other menu sections
	    SetCookie("ActiveMenuItem", theid);

	    if (theid != 'mymenu16') document.getElementById("mymenu16").className = 'hide';	
	    if (theid != 'mymenu15') document.getElementById("mymenu15").className = 'hide';	         
		if(theid != 'mymenu14')document.getElementById("mymenu14").className = 'hide';	        
		if(theid != 'mymenu13')document.getElementById("mymenu13").className = 'hide';		
		if(theid != 'mymenu12')document.getElementById("mymenu12").className = 'hide';		        
		if(theid != 'mymenu12')document.getElementById("mymenu12").className = 'hide';		
		if(theid != 'mymenu11')document.getElementById("mymenu11").className = 'hide';
		if(theid != 'mymenu10')document.getElementById("mymenu10").className = 'hide';			
		if(theid != 'mymenu9')document.getElementById("mymenu9").className = 'hide';			
		if(theid != 'mymenu8')document.getElementById("mymenu8").className = 'hide';		
		if(theid != 'mymenu7')document.getElementById("mymenu7").className = 'hide';
		if(theid != 'mymenu6')document.getElementById("mymenu6").className = 'hide';
		if(theid != 'mymenu5')document.getElementById("mymenu5").className = 'hide';
		if(theid != 'mymenu4')document.getElementById("mymenu4").className = 'hide';
		if(theid != 'mymenu3')document.getElementById("mymenu3").className = 'hide';
		if(theid != 'mymenu2')document.getElementById("mymenu2").className = 'hide';
		if(theid != 'mymenu1')document.getElementById("mymenu1").className = 'hide';	
		
		
//		var switch_id = document.getElementById(theid);
//	    switch_id.className = 'show';
        $('#'+theid).switchClass('hide','show',500,'easeOutBounce');
		
       // if(menu_status[theid] != 'show') {
       //    switch_id.className = 'show';
       //    menu_status[theid] = 'show';
      //  }else{
      //     switch_id.className = 'hide';
       //    menu_status[theid] = 'hide';
       // }
    }
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

var ContentHeight = 100;
var TimeToSlide = 1500.0;

var openAccordion = '';

function runAccordion(index) {
    SetCookie("ActiveMenuItem", index);
    var nID = "Accordion" + index + "Content";
    if (openAccordion == nID)
        nID = '';

    setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "')", 33);

    openAccordion = nID;
}



function animate(lastTick, timeLeft, closingId, openingId) {
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var opening = (openingId == '') ? null : document.getElementById(openingId);
    var closing = (closingId == '') ? null : document.getElementById(closingId);

    if (timeLeft <= elapsedTicks) {
        if (opening != null)
            opening.style.height = ContentHeight + '%';// 'px';
//              opening.style.height = '35%';
        if (closing != null) {
            closing.style.display = 'none';
            closing.style.height = '0px';
        }
        return;
    }

    timeLeft -= elapsedTicks;
    var newClosedHeight = Math.round((timeLeft / TimeToSlide) * ContentHeight);

    if (opening != null) {
        if (opening.style.display != 'block')
            opening.style.display = 'block';
//          opening.style.height = (ContentHeight - newClosedHeight) + 'px';
           opening.style.height = '100%';

    }

    if (closing != null)
        closing.style.height = newClosedHeight + 'px';

    setTimeout("animate(" + 0 + "," + 0 + ",'"
      + closingId + "','" + openingId + "')", 33);
//     setTimeout("animate(" + curTick + "," + timeLeft + ",'"
//      + closingId + "','" + openingId + "')", 33);
}

function SetOnMenuLoad2() 
{
    var CurrentMenuItem = GetCookie("ActiveMenuItem");
    if (CurrentMenuItem != null) {
        runAccordion(CurrentMenuItem);
    }
    else {
        runAccordion(1);
    }
}
