// JavaScript Document

function createCookie(name,value,days) {
    if (days) {
	    var date = new Date();
	    date.setTime(date.getTime()+(days*24*60*60*1000));
	    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}
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 _getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
        function menuState(menuName){
            if(GetCookie (menuName+'Index') == null )
			{
				return;
			}
            else 
		      document.getElementById(menuName + GetCookie (menuName+'Index') + 'Content').style.height = GetCookie(menuName+ 'ContentHeight');
              document.getElementById(menuName + GetCookie (menuName+'Index') + 'Content').style.display = 'block';
              window.accordion_jso.lastClicked = document.getElementById(menuName+GetCookie (menuName+'Index'));
			  window.accordion_jso.runAccordion(menuName,GetCookie (menuName+'Index') ,GetCookie(menuName+ 'ContentHeight'), true, this);
              window.accordion_jso.openAccordion = menu + GetCookie (menuName+'Index') + 'Content';
              window.accordion_jso.setImage(document.getElementById(menuName+"Image"+GetCookie(menuName+'Index')));
            }
        
window.accordion_jso = {
    //ContentHeight: 200,
    TimeToSlide: 250.0,
    openAccordion: '',
    lastClicked: null,
	
     //index:点击行的索引
	 //高度有多少行
	 //menuCount  menu子集个数
    runAccordion: function(menuName,index,menuContentHeight,animate)
    {        
	        //初始化所有高度
			   window.accordion_jso.ContentHeight=menuContentHeight;
			
			var nID = menuName + index + "Content";
			if(animate == false) window.accordion_jso.TimeToSlide=35.0;
		
            if(window.accordion_jso.openAccordion == nID) 
			{
			   nID = '';
			   createCookie(menuName+'Index',null,0) ;
	           createCookie(menuName+'ContentHeight',menuContentHeight,0) ;
			}
            else
			{ 
			    createCookie(menuName+'Index',index,0) ;
	        	createCookie(menuName+'ContentHeight',menuContentHeight,0) ;
			}
            setTimeout("window.accordion_jso.animate("
              + new Date().getTime() + "," + window.accordion_jso.TimeToSlide + ",'"
              + window.accordion_jso.openAccordion + "','" + nID + "')", 22);
         
          window.accordion_jso.openAccordion = nID;
          
          var d = document.getElementById(menuName+"Image"+index);
          if(window.accordion_jso.lastClicked != null && d != window.accordion_jso.lastClicked) 
                window.accordion_jso.setImage(window.accordion_jso.lastClicked, 1);
         
          window.accordion_jso.setImage(d);
          window.accordion_jso.lastClicked = d;
		window.accordion_jso.TimeToSlide=250.0;
        },

        animate: function(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 = window.accordion_jso.ContentHeight + 'px';
           
            if(closing != null)
            {
              closing.style.display = 'none';
              closing.style.height = '0px';
            }
            return;
          }
          timeLeft -= elapsedTicks;
          var newClosedHeight =
              Math.round((timeLeft/window.accordion_jso.TimeToSlide) * window.accordion_jso.ContentHeight);
          if(opening != null)
          {
            if(opening.style.display != 'block')
              opening.style.display = 'block';
            opening.style.height =
                (window.accordion_jso.ContentHeight - newClosedHeight) + 'px';
          }
          if(closing != null)
            closing.style.height = newClosedHeight + 'px';
          setTimeout("window.accordion_jso.animate(" + curTick + "," + timeLeft + ",'"
              + closingId + "','" + openingId + "')", 22);
        },
		
        setImage: function (o, force){
        /*
         if(o.getAttribute("Xstate") == "opened" || force == 1){

                o.src=o.src.replace(/_open\.gif/,'_closed.gif');
                o.setAttribute("Xstate","closed");
               }
          else{
               o.src=o.src.replace(/_closed\.gif/,'_open.gif');
               o.setAttribute("Xstate","opened");
              }
              */
         }
}
