// not animated collapse/expand
function togglePannelStatus(content){
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    toggleChevronIcon(content);
}

function togglePannelStatus2(content)
{
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    toggleChevronIcon2(content);
}
function togglePannelStatus3(content)
{
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    toggleChevronIcon3(content);
}
/*
function togglePannelStatus4(content)
{
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    toggleChevronIcon4(content);
}

*/


// current animated collapsible panel content
var currentContent = null;
var currentContent2 = null;
var currentContent3 = null;
//var currentContent4 = null;



function getPreviousSibling(elem){
	elem = document.getElementById(elem);
	elem = elem.previousSibling;
	do {
		elem = elem.previoussibling;
	} 
	while (elem.tagName == 'undefined');
}


function getNextSibling(startBrother){
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
} 



function check(content, interval, step, curent_bx) {
	
	
	
	panel_1 = getNextSibling(document.getElementById('box1'));
	panel_2 = getNextSibling(document.getElementById('box2'));
	panel_3 = getNextSibling(document.getElementById('box3'));
	/*
	panel_4 = getNextSibling(document.getElementById('box4'));
	
	*/
	
	

	if (panel_1.style.display != 'none' && curent_bx!=1) togglePannelAnimatedStatus(panel_1,5,5);
	
	if (panel_2.style.display != 'none' && curent_bx!=2) togglePannelAnimatedStatus2(panel_2,5,5);
	
	if (panel_3.style.display != 'none' && curent_bx!=3) togglePannelAnimatedStatus3(panel_3,5,5);
	/*
	if (panel_4.style.display != 'none' && curent_bx!=4) togglePannelAnimatedStatus4(panel_4,10,10);
	*/
	
	if (curent_bx==1) {
		togglePannelAnimatedStatus(panel_1,5,5);
	}
	
	if (curent_bx==2) {
		togglePannelAnimatedStatus2(panel_2,5,5);
	}
	if (curent_bx==3) {
		togglePannelAnimatedStatus3(panel_3,5,5);
	}
	/*
	if (curent_bx==4) {
		togglePannelAnimatedStatus4(panel_4,10,10);
	}
	*/
	
}




function togglePannelAnimatedStatus(content, interval, step){
    // wait for another animated expand/collapse action to end
	
    //if (currentContent==null)
    //{
        currentContent = content;
        var expand = (content.style.display=="none");
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight-30;
		
		

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon(content);
                
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    //}
}


function togglePannelAnimatedStatus2(content, interval, step){
    // wait for another animated expand/collapse action to end
	

    //if (currentContent==null)
   // {
        currentContent2 = content;
        var expand = (content.style.display=="none");
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight-30;
		
		

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon2(content);
                
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus2("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
   // }
}


function togglePannelAnimatedStatus3(content, interval, step){
    // wait for another animated expand/collapse action to end
	

    //if (currentContent==null)
   // {
        currentContent3 = content;
        var expand = (content.style.display=="none");
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight-30;
		
		

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon3(content);
                
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus3("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
   // }
}

/*
function togglePannelAnimatedStatus4(content, interval, step){
    // wait for another animated expand/collapse action to end
	
    //if (currentContent==null)
   // {
        currentContent4 = content;
        var expand = (content.style.display=="none");
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight;
		
		

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon4(content);
                
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus4("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
   // }
}

*/
function togglePannelAnimatingStatus(interval,
    step, max_height, step_height)
{
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent.style.display = "none";
        currentContent.style.height = "";
        currentContent = null;
    }
}

function togglePannelAnimatingStatus2(interval,
    step, max_height, step_height)
{
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent2.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus2("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent2.style.display = "none";
        currentContent2.style.height = "";
        currentContent2 = null;
    }
}


function togglePannelAnimatingStatus3(interval,
    step, max_height, step_height)
{
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent3.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus3("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent3.style.display = "none";
        currentContent3.style.height = "";
        currentContent3 = null;
    }
}
/*
function togglePannelAnimatingStatus4(interval,
    step, max_height, step_height)
{
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent4.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus4("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent4.style.display = "none";
        currentContent4.style.height = "";
        currentContent4 = null;
    }
}


*/
// change chevron icon into either collapse or expand


function toggleChevronIcon(content){
		//alert (content.id);
	if (document.getElementById('menu1').className == "selected") {
		//document.getElementById('menu1').className = ""
	} else {
		//document.getElementById('menu1').className = "selected"
	}
}

function toggleChevronIcon2(content){
	if (document.getElementById('menu2').className == "selected") {
		//document.getElementById('menu2').className = ""
	} else {
		//document.getElementById('menu2').className = "selected"
	}
}
function toggleChevronIcon3(content){
	if (document.getElementById('menu3').className == "selected") {
		//document.getElementById('menu3').className = ""
	} else {
		//document.getElementById('menu3').className = "selected"
	}
}
/*
function toggleChevronIcon4(content){
}
*/
