var nav_state = 'collapse';

function check_nav(htmlcontent1, htmlcontent2){	
		if(document.getElementById("navigation").offsetHeight > 230){
			document.getElementById("alle_anzeigen").innerHTML='<a onClick="mem_Blind(\'pulldown\',\''+htmlcontent1+'\',\''+htmlcontent2+'\');" id="pulldown_btn">alle Genres anzeigen</a>';
			document.getElementById("alle_anzeigen").className = 'collapse';
		}
		if(getParameter(window.top.location.search.substring(1),'nav') == 1){		
			nav_state = 'expand';
			document.getElementById("pulldown_btn").innerHTML=htmlcontent2;
		} else {
			document.getElementById("pulldown").className = 'collapse';
			nav_state = 'collapse';
			document.getElementById("pulldown_btn").innerHTML=htmlcontent1;
		}		
}
function mem_Blind(elem_name, htmlcontent1, htmlcontent2){
		if(nav_state == 'collapse'){
			mem_BlindDown(elem_name, htmlcontent2);
		} else {
			mem_BlindUp(elem_name, 225, 225, htmlcontent1);
		}
	}
function change_loc(elem){	
		if(nav_state == 'expand'){
				if(window.top.location.search.indexOf('?')!=-1 && window.top.location.search.indexOf('?nav=')==-1)
					{
						trenner='&'
					} else {						
						trenner='?'
					};
				document.location.href=elem.href+trenner+"nav=1";
				return false;
			}
		return true;
	}
function getParameter ( queryString, parameterName ) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
		if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
			if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
				if ( end == -1 ) {
				end = queryString.length
				}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
			}
		// Return "null" if no parameter has been found
		return "null";
		}
}

function mem_BlindUp(elem_name, size, percent, htmlcontent1)
{
	nav_state = 'collapse';
	document.getElementById("pulldown_btn").innerHTML=htmlcontent1;
	document.getElementById("pulldown_btn").className = 'collapse';
    if(typeof mem_Blind_State == 'undefined')
        mem_Blind_State = new Object();
    if(typeof mem_Blind_State[elem_name] == 'undefined')
        mem_Blind_State[elem_name] = new Object();
    if(typeof mem_Blind_State[elem_name].state == 'undefined')
        mem_Blind_State[elem_name].state = 1;
    if(typeof mem_Blind_State[elem_name].lock == 'undefined')
        mem_Blind_State[elem_name].lock = 0;
    if(typeof percent == 'undefined')
        percent = false;
    if(typeof size == 'undefined')
        size = 0;
        
    if(mem_Blind_State[elem_name].lock == 1)
        window.setTimeout("mem_BlindUp('"+elem_name+"')",100);
    else
    {
        if(mem_Blind_State[elem_name].state == 1)
        {
            mem_Blind_State[elem_name].lock = 1;
            // BlindUp elem
            mem_Blind_State[elem_name].s_height = document.getElementById(elem_name).offsetHeight;
            if(percent==true)
                mem_Blind_State[elem_name].t_height = (document.getElementById(elem_name).offsetHeight * size) / 100;
            else
                mem_Blind_State[elem_name].t_height = size;

            mem_Blind_State[elem_name].overflow = document.getElementById(elem_name).style.overflow;
            document.getElementById(elem_name).style.overflow = 'hidden';
            
            mem_Blind_State[elem_name].interval = window.setInterval("mem_BlindUp_do('"+elem_name+"')", 1);
        }
    }	
}

function mem_BlindDown(elem_name, htmlcontent2)
{
	nav_state = 'expand';
	document.getElementById("pulldown_btn").innerHTML=htmlcontent2;
	document.getElementById("pulldown_btn").className = 'expand';
    if(typeof mem_Blind_State == 'undefined')
        mem_Blind_State = new Object();
    if(typeof mem_Blind_State[elem_name] == 'undefined')
        mem_Blind_State[elem_name] = new Object();
    if(typeof mem_Blind_State[elem_name].state == 'undefined')
        mem_Blind_State[elem_name].state = 0;
    if(typeof mem_Blind_State[elem_name].lock == 'undefined')
        mem_Blind_State[elem_name].lock = 0;
    var childs = document.getElementById(elem_name).childNodes;
    for(var i=0; i < childs.length; i++)
    {
        if(childs[i].nodeType!=3)
        {
            mem_Blind_State[elem_name].t_height = childs[i].scrollHeight;
            break;
        }
    }
        
    //mem_Blind_State[elem_name].t_height = document.getElementById(elem_name).scrollHeight;
    
    if(mem_Blind_State[elem_name].lock == 1)
        window.setTimeout("mem_BlindDown('"+elem_name+"')",100);
    else
    {
        if(mem_Blind_State[elem_name].state == 0)
        {
            mem_Blind_State[elem_name].lock = 1;
            // BlindUp elem
            mem_Blind_State[elem_name].s_height = document.getElementById(elem_name).offsetHeight;
            
            mem_Blind_State[elem_name].interval = window.setInterval("mem_BlindDown_do('"+elem_name+"')", 1);
        }
    }
}

function mem_BlindUp_do(elem_name)
{
    var step_size = 5;
    
   // alert(mem_Blind_State[elem_name].s_height+' --- '+mem_Blind_State[elem_name].t_height);
    
    if(mem_Blind_State[elem_name].s_height > mem_Blind_State[elem_name].t_height)
    {
        mem_Blind_State[elem_name].s_height = mem_Blind_State[elem_name].s_height - step_size;
        if(mem_Blind_State[elem_name].s_height < mem_Blind_State[elem_name].t_height)
            mem_Blind_State[elem_name].s_height = mem_Blind_State[elem_name].t_height;
        document.getElementById(elem_name).style.height = mem_Blind_State[elem_name].s_height+'px';    
    }
    else
    {
        mem_Blind_State[elem_name].state = 0;
        mem_Blind_State[elem_name].lock = 0;  
        window.clearInterval(mem_Blind_State[elem_name].interval);
    }
}

function mem_BlindDown_do(elem_name)
{
    var step_size = 5;

    if(mem_Blind_State[elem_name].s_height < mem_Blind_State[elem_name].t_height)
    {
        mem_Blind_State[elem_name].s_height = mem_Blind_State[elem_name].s_height + step_size;
        if(mem_Blind_State[elem_name].s_height > mem_Blind_State[elem_name].t_height)
            mem_Blind_State[elem_name].s_height = mem_Blind_State[elem_name].t_height;
        document.getElementById(elem_name).style.height = mem_Blind_State[elem_name].s_height+'px';    
    }
    else
    {
        mem_Blind_State[elem_name].state = 1;
        mem_Blind_State[elem_name].lock = 0;  
        document.getElementById(elem_name).style.overflow = mem_Blind_State[elem_name].overflow;
        window.clearInterval(mem_Blind_State[elem_name].interval);
    }
}
