var hcatid = 0;

$(document).ready(function(){
  closeAll();
  if( prCat < 1 ) { openCatId(($(".cibox").attr('id')).split("_")[1]); }
    else { openCatId(prCat); }

  $(".cibox").bind("mouseenter",function(){
    if( ($(this).attr('id')).split("_")[1] != hcatid ) { setImgDown("#"+$(this).attr('id')+" img"); }
  }).bind("mouseleave",function(){
    if( ($(this).attr('id')).split("_")[1] != hcatid ) { setImgNorm("#"+$(this).attr('id')+" img"); }
  });

  $(".cpitem").bind("mouseenter",function(){
    setImgDown("#"+$(this).attr('id')+" img");
  }).bind("mouseleave",function(){
    setImgNorm("#"+$(this).attr('id')+" img");
  });

});

function closeAll() {
  $(".cibox").each(function () {
    $(this).css({
      'border-bottom':'1px solid #ffffff'
    });
    setImgNorm("#"+$(this).attr('id')+" img");
  });
  $(".cplist").each(function () {
    $(this).css({
      position:'absolute',
      visibility:'hidden' 
    });
  });
  $("#catstext").html("");
}

function openCatId(catid) {
  $("#cibox_"+catid).css({
      'border-bottom':'0px' 
  });
  $("#cplist_"+catid).css({
      position:'relative',
      visibility:'visible' 
  });
  $("#catstext").html($("#citext_"+catid).html());
  setImgDown("#cibox_"+catid+" img");
  hcatid = catid;
}

function setImgDown(src) {
  var isrc = $(src).attr('src').split("/")[1].split(".")[0].split("_");
  $(src).attr('src', "images/"+isrc[0]+"_"+isrc[1]+"_down.gif" );
}

function setImgNorm(src) {
  var isrc = $(src).attr('src').split("/")[1].split(".")[0].split("_");
  $(src).attr('src', "images/"+isrc[0]+"_"+isrc[1]+".gif" );
}

function catClick(catid) {
  closeAll();
  openCatId(catid);
}



