//var menu_catholder = 'menu_categorie_container';
var menu_catholder = 'menu_categorie_holder';
var menu_catcontent = 'menu_categorie_content_container';
var menu_subcatholder = 'menu_subcategorie_container';
var menu_subcatcontent = 'menu_subcategorie_content_container';
var menu_ccatid;
var menusub_ccatid;
var menusub_cccatid;
var menusub_ccfid;
var getprod_go = true;

function showMenuCat(catid,ccatid){
  var url = "showMenuCategories";
  if($(menu_catholder).style.display=='none'){
    menu_ccatid=catid;
    new Ajax.Updater(menu_catcontent,url,{parameters:'js=1&catid='+catid+'&ccatid='+ccatid,onComplete:function(){Effect.SlideDown(menu_catholder,{queue:{position:'end',scope:'catmenu',limit:1},beforeStart:function(){lockGetProd();},afterFinish:function(){unlockGetProd();resizeMenu();}});} });
  }else{
    if($(menu_subcatholder).style.display != 'none'){
      hideSubCatHolder_first();
      Effect.SlideUp(menu_catholder,{queue:{position:'end',scope:'catmenu',limit:2},beforeStart:function(){lockGetProd();},afterFinish:function(){if(catid != menu_ccatid){$(menu_subcatholder).style.display='none';showMenuCat(catid,ccatid);}else{unlockGetProd();resizeMenu();}} });
    }
    else{
      Effect.SlideUp(menu_catholder,{queue:{position:'end',scope:'catmenu',limit:1},beforeStart:function(){lockGetProd();},afterFinish:function(){if(catid != menu_ccatid){$(menu_subcatholder).style.display='none';showMenuCat(catid,ccatid);}else{unlockGetProd();resizeMenu();}} });
    }
  }
}
function showMenuSubCat(obj,ccatid,cpid,catid,ccfid,cccatid,b){
  var url = "showMenuCategoryFilters";
  if(b){return b;}
  if($(menu_subcatholder).style.display=='none'){
    menusub_ccatid=ccatid;
    new Ajax.Updater(menu_subcatcontent,url,{parameters:'js=1&catid='+ccatid+'&cpid='+cpid+'&pcatid='+catid+'&ccfid='+menusub_ccfid+'&cccatid='+menusub_cccatid,onComplete:function(){showSubCatHolder(obj);} });
  }else{
    Effect.SlideUp(menu_subcatholder,{queue:{position:'end',scope:'subcatmenu',limit:1},beforeStart:function(){lockGetProd();},afterFinish:function(){ unlockGetProd();if(ccatid != menusub_ccatid){showMenuSubCat(obj,ccatid,cpid,catid,ccfid,cccatid);}  } } );
  }
  return b;
}
function hideSubCatHolder_first(){
  Effect.SlideUp(menu_subcatholder,{duration:0.5,queue:{position:'front',scope:'catmenu',limit:2},beforeStart:function(){lockGetProd();},afterFinish:function(){ $(menu_catcontent ).style.bottom='0px';  }} );
}
function hideSubCatHolder(){
  Effect.SlideUp(menu_subcatholder,{queue:{position:'end',scope:'subcatmenu',limit:1},beforeStart:function(){lockGetProd();},afterFinish:function(){ unlockGetProd();resizeMenu(); }} );
}
function showSubCatHolder(obj){
  Effect.SlideDown(menu_subcatholder,{queue:{position:'end',scope:'subcatmenu',limit:1},beforeStart:function(){lockGetProd();},afterFinish:function(){ unlockGetProd();resizeMenu();renderSub(obj); }} );
}
function lockGetProd(){
  getprod_go = false;
}
function unlockGetProd(){
  getprod_go = true;
}
function renderSub(obj){
  if(obj.href){
    window.location=obj.href;
  }
}
function toggleswitchLanguage(){
  var lang = 'language_switch_holder';
  new Effect.toggle(lang);
}
function toggleswitchCountry(){
  var country = 'country_switch_holder';
  if($('country_switch_holder').style.display == 'none'){
   var els = $$('div.countryoption');
   $('country_switch_holder').style.display = '';
   for(var i=0;i<els.length;i++){
     els[i].style.cssText='';
     els[i].style.width='';
     //var w = els[i].offsetWidth;
     var w = els[i].select("a")[0].getWidth();
     els[i].style.cssText='width:'+(w+10)+'px;float:left';
   }
   $('country_switch_holder').style.display = 'none';
   //alert(w);
  }
  new Effect.toggle(country,'appear',{beforeStart:function(){$(country).style.display='';checkCountryToggle();$(country).style.display='none';},afterFinish:function(){checkCountryToggle();}});
}
function checkCountryToggle(){
  var country = 'country_switch_holder';
  var h = $('country_holder').offsetHeight;
  if($(country).style.display == ''){
    //$('country_switch_container').style.height=h+'px';
    $('country_back').style.height=h+'px';
    $('language_switch_container').style.top = h+'px';
  }else{
    //$('country_switch_container').style.height='';
    //$('country_back').style.height='';
    $('language_switch_container').style.top = '';
  }
}
function updateCountryOptions(){
  var reset = false;
  if($('country_switch_holder').style.display == 'none'){
    reset = true;
  }
  if($('country_switch_holder')){
   var els = $$('div.countryoption');
   $('country_switch_holder').style.display = '';
   var indexes = new Array();
   for(var i=0;i<els.length;i++){
     els[i].style.cssText='';
     els[i].style.width='';
     //var w = els[i].offsetWidth;
     var w = els[i].select("a")[0].getWidth();
     indexes[i] = (w+10);
   }
   for(var i=0;i<indexes.length;i++){
     els[i].style.cssText='width:'+(indexes[i])+'px;float:left';
   }
   if(reset){
     $('country_switch_holder').style.display = 'none';
   }
  }
}