$(document).ready(function(){
	hideallmenus_boot();
	$('#leftmenubox').children('ul').find('a').each(function(){
		$(this).click(function(){
		if($(this).parent().attr('class') != 'active'){
			if($(this).attr('href') == '#'){hideallmenus();}
				$(this).parent().attr('class','active');
				//$(this).parent().find('ul').css('display','block');
				$(this).parent().find('ul').slideDown();
			}
			else {
				$(this).parent().find('ul').slideUp();
				$(this).parent().attr('class','');
			}
		});
	});
	
	//request parameters
	var lm;
	var brand_id;
	var queryString_real = window.location.pathname;

	var queryString;// = window.top.location.search.substring(1);
	
	queryString = $('body').find('form').eq(0).attr('action');
	queryString = queryString.replace(/%3d/g,'=');
	queryString = queryString.replace(/\+/g,'&');
	
	//lm = gup(queryString,'lm');	
	
	var lm_new=getCookie("lm");
if (lm_new!=null && lm_new!="" && lm_new!="-1")
                {
                lm = lm_new;
                }
	
	
	brand_id = gup(queryString,'MOBU_ShopArtikelId_ShopArtikel.BrandId');
	abonrr_id = gup(queryString,'AbonGrId');
	
	
	
	if(lm != null){
		lm = parseInt(lm);
		//alert(abonrr_id + ' - ' + lm);
		
		if(brand_id != null){
			brand_id = parseInt(brand_id);
			var li_id = '#lm_' + lm;
			$(li_id).attr('class','active');
			$(li_id).find('ul').css('display','block');
			$(li_id).children().find('a').each(function(){
				if($(this).attr('class').indexOf('_b') > 0){
					if(brand_id == parseInt($(this).attr('class').split('_b')[1])){
						$(this).parent().attr('class','active');
					}
				}
			});
		}
		if(abonrr_id != null){
			abonrr_id = parseInt(abonrr_id);
			var li_id = '#lm_' + lm;
			$(li_id).attr('class','active');
			$(li_id).find('ul').css('display','block');
			$(li_id).children().find('a').each(function(){
				if($(this).attr('class').indexOf('_a') > 0){
					if(abonrr_id == parseInt($(this).attr('class').split('_a')[1])){
						$(this).parent().attr('class','active');
					}
				}
			});
		}
	}
	
	//left menu blue blocks font size
	$('.actiontitle').each(function(){
		var th = $(this).find('span').height();
		if(th > 30){
			$(this).find('span').css('font-size','14px');
		}
	});
	//end left menu blue blocks font size
	$('#leftmenubox').css('visibility','visible');

$('.actionul > li').each(function(){
var lmpar = $(this).attr('id').split('_')[1];
$(this).find('a').click(function(){
setCookie("lm",lmpar,1);
});
});

$('#header').find('a').each(function(){$(this).click(function(){setCookie("lm",-1,1);});});
$('#menu').find('a').each(function(){$(this).click(function(){setCookie("lm",-1,1);});});
$('#footer').find('a').each(function(){$(this).click(function(){setCookie("lm",-1,1);});});













	
});//document ready end
function hideallmenus_boot(){
	$('#leftmenubox').children().find('li').each(function(){
		$(this).attr('class','');
		$(this).find('ul').css('display','none');
	});
}
function hideallmenus(){
	$('#leftmenubox').children().find('li').each(function(){
		$(this).attr('class','');
		//$(this).find('ul').css('display','none');
		$(this).parent().find('ul').slideUp();
	});
}

function gup(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 getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString() +';path=/');
document.cookie=c_name + "=" + c_value;
}
