
function toggleNode( node ) {
  try {
    var pfx = node.parentNode.parentNode.id.match( /^(.*?)_/ )[0];
    var ul = document.getElementById( pfx + node.href.match( /i(\d+)\/?$/ )[1] );
    var curstyle = window.getComputedStyle ?
      window.getComputedStyle( ul, null ) :
      ( ul.currentStyle || ul.style );
    ul.style.display = "none" == curstyle.display ? "block" : "none";
    return false;
  } catch( ex ) {
    return true;
  }
}

function showCurrentBranch( current, pfx ) {
  pfx = pfx || "Tree0";
  var li = document.getElementById( pfx + "_leaf" + current );
  if ( li ) {
    while ( pfx + "_0" != li.id ) {
      li.className += " current";
      li = li.parentNode;
    }
  }
}

function toggleSubmenu( a ) {
  var smId = a.id.match( /\d+$/ )[0];
  if ( "current" == a.className ) {
    a.className = "";
    $("#SubmenuA"+smId+" > div").hide();
  } else {
    a.className = "current";
    $("#SubmenuA"+smId+" > div").toggle("normal");
  }
  return false;
}

function ItemSets( srcId, setInfo ) {
  this.setInfo = setInfo;
  this.currentSets = setInfo[0];
  this.srcId = srcId;
  this.frmName = "addCart"+srcId;
  this.currentX = this.currentSets.info[0];
  this.setInfoQ = null;
  var self = this;

  this.updateSet = function( colorN, sizeN ) {

    if( ! this.setInfoQ ) {
      this.setInfoQ = document.getElementById("SetInfoQ-"+srcId);
    }

    var frm = document.forms[self.frmName];
    var x;
    var setId;

    if( null === colorN ) { //  selected a size within a color, currentSets not changed
      x = self.currentSets.info[sizeN];
    } else { // selected a color: currentSets changed to matching color, setN set to 0
      self.currentSets = self.setInfo[colorN];

      // x: temporary value for the HTML generating loop
      x = self.currentSets.info;
      var opts = "";
      for ( var i in x ) {
        opts += "<" + "option value='" + x[i].id + "'>" + x[i].size + "</option>";
      }
      // x: final value used below
      x = self.currentSets.info[0];
      frm.size.innerHTML = opts;
      var node;
      var img = x.img;
      if( node = document.getElementById("SetInfoImg"+self.srcId) ) {
        node.src = img ? "/imag/catalog/img_m/" + img : '/images/noimage.gif';
      } else if( node = document.getElementById("SetInfoBG"+self.srcId) ) {
        node.style.backgroundImage = img ? "url(/imag/catalog/img_s/" + img + ")" : 'url(/images/noimage.gif)';
      }
    }
    // common assignments
    document.getElementById("SetInfoPrice"+self.srcId).innerHTML = x.price + " " + textCurrency;
    if( node = document.getElementById("SetInfoArt") ) {
      node.innerHTML = x.art;
    }
    if ( this.setInfoQ ) {
      this.setInfoQ.innerHTML =  0 == x.q ? textNone : ( Number.MAX_VALUE == x.q ? textMany : x.q ) ;
    }
//    document.getElementById("aBuy").innerHTML = x.none ? textNone2 : textBuy;


    frm.setId.value = x.id;
    self.currentX = x;
  } // updateSet
} // ItemSets


function showBigImage( srcsrc ) {
  window.open( srcsrc.replace("img_m","img_b"), "", "" );
  return false;
}

function showItem( href ) {
  var x = href.match(/\?(\d+),(\d+)$/);
  if( x ) {
    x[1] = parseInt(x[1]) + 20;
    x[2] = parseInt(x[2]) + 120;
  } else {
    x = [ 0, 420, 740 ];
  }
  window.open( href,'','width='+x[1]+',height='+x[2]+',toolbars=no,statusbar=no,scrollbars=yes,resizable=yes' );
  return false;
}

function checkCartForm( frmId ) {
  var x = window["itemSet"+frmId].currentX;
  if ( x.none ) {
    alert( textNotInStock );
    return false;
  }

  var frm = document.forms["addCart"+frmId];
  if ( "" == frm.q.value ) {
    alert( textNotSpecified );
    return false;
  }
  if ( x.q > 0 && x.q < parseInt(frm.q.value) ) {
    alert( textNotEnough );
    return false;
  }
  frm.submit();
  return false;
}

function FlashInterface() {
  var self = this;
  this.overIndex = 0;
  this.outIndex = 0;
//  this.flashObj = document.theFlash || window.theFlash ;
  this.flashObj = $.swfobject.getObjectById("myCom");
  FlashInterface.instance = self;
}

function getOverIndex() {
  return FlashInterface.instance.overIndex;
}
function getOutIndex() {
  return FlashInterface.instance.outIndex;
}

function mover( ev ) {
  var evt = ev || window.event;
  var item = evt.target || evt.srcElement;
  var i = item.href.match( /i(\d+)\/$/ )[1];
  var obj = FlashInterface.instance.flashObj;
  FlashInterface.instance.overIndex = i;
  try {
    obj.cover();
  } catch( ex ) {
  }
}
function mout( ev ) {
  var evt = ev || window.event;
  var item = evt.target || evt.srcElement;
  var i = item.href.match( /i(\d+)\/$/ )[1];
  var obj = FlashInterface.instance.flashObj;
  FlashInterface.instance.outIndex = i;
  try {
    obj.cout();
  } catch( ex ) {
  }
}

function setupFlashIface() {
  var items = document.getElementById( "FlashIface" ).getElementsByTagName( "A" );
  var flashIface = new FlashInterface();
  for( var i=items.length-1; i >= 0; i-- ) {
    items[i].onmouseover = mover;
    items[i].onmouseout  = mout;
  }

}



