//$Id: details.js,v 1.4 2011/10/02 06:23:12 evg@atom.krasnet.ru Exp $

var picture_offset = 0;
var picture_current= '';

function detailSwitchImg(el)
{
 var img = $('ZoomImage');
 var name= el.id.replace('ScrollImage','');
 var elem = $$('#ImgScroollList a');
 elem.each(function(value,key)
 {
   value.className = 'Preload';
 }); 
 el.className='Current';
 picture_current = name;
 img.src=imgPath+'/img/'+img_src[name].detail;
 if (!img.complete)
 {
  img.style.display='none';
  img.onload = detailImgLoaded;
  $('ZoomImageLoading').style.display='block';
 }
 if (img_src[name].zoom=='#')
 {
  $('ZoomTool').update('<span><img src="/assets/images/icons/ic_details_zoom-none.gif" alt="Zoom None" /></span>');
 } else
 {
  var html = '<a id="idAZoomTool" target="_blank" rel="lightbox" href="'+imgPath+'/img/'+img_src[name].zoom+'" title="'+el.childNodes[0].alt+'"><img src="/assets/images/icons/ic_details_zoom.gif" alt="Zoom"/></a>';
  $('ZoomTool').update(html);
 }
 return false;
}

function detailImgLoaded()
{
 $('ZoomImage').style.display='block';
 $('ZoomImageLoading').style.display='none';;
}

function detailImgScroll(mode)
{
 var imgCount = imgBigKey.length / 2;
 var elem = $$('#ImgScroollList a'); 
 var imgCountLimit = elem.length;

 if (mode == 'down') picture_offset = picture_offset+1;
 else picture_offset = picture_offset-1;
 picture_offset = (picture_offset+imgCount) % imgCount;
 var keys = imgBigKey.slice(picture_offset,picture_offset+imgCountLimit);
 if (picture_current == '') elem.each(function(value,key)
 {
   if (value.className == 'Current') picture_current=value.id.replace('ScrollImage','');
 }); 

 keys.each(function(value,key)
 {
   if (value==picture_current)
  elem[key].className = 'Current';
 else
  elem[key].className = 'Preload';
   elem[key].id = 'ScrollImage'+value;
   elem[key].childNodes[0].src = imgPath+'/img/'+img_src[keys[key]].preview;   
 });
 return false;
}

function detailSpreadSelect(text,active_id)
{
 var block_list = new Array("Related","Featured","Latest","Recently");
 var a = document.getElementById('SpreadOptionSelectedRef');
 a.innerHTML = text;
 document.getElementById('PageOptionsRelatedSwitch').className="";
 for(var i=0;i<4;i++)
 {
  var id= 'PageOptions'+block_list[i]+'ID';
  var el= document.getElementById(id);
  if(el == null) continue;
  if(id == active_id) el.style.display='block';
  else el.style.display='none';
 }
 return false;
}

function dvChangeQty(article_id, qty, maxqty, q, r, p, start)
{
 qty = parseInt(qty);
 maxqty = parseInt(maxqty);
 if (qty > maxqty)
 {
  qty = maxqty;
  $('qty').value = qty;
  $('ResQuant').innerHTML = qty;
  return;
 }
 if (qty == $('qty').value && !start)
 {
  return;
 }
 $('qty').value = qty;
 $('ResQuant').innerHTML = qty;
 var value = new Array();
 value['start'] = start;
 value['id'] = 'detail-qty';
 value['qty'] = qty;
 value['q'] = q;
 value['r'] = r;
 value['p'] = p;
 value['article_id'] = article_id;
 value['size'] = $('size').value;
 value['dlv'] = $('dlv').value;
 var req=new j2httpRequest_js;
 req.onreadystatechange = function()
 {
  if (req.readyState == 4)
  {
   var result=req.responseJS;
   if (result['html'])
   {
    $('Delivery').innerHTML = result['html'];
    $('Status').innerHTML = result['status'];
   }
  }
 }
 req.open('GET', '/assets/templ/include_globals/options.php', true);
 req.send({'mode':'uri','value':value});
}

function relatedNavSet(jkid, nt, ntp, q, r, p)
{
 var value = new Array();
 value['id'] = 'navigation';
 value['jkid'] = jkid;
 value['nt'] = nt;
 value['ntp'] = ntp;
 value['q'] = q;
 value['r'] = r;
 value['p'] = p;
 var req=new j2httpRequest_js;
 req.onreadystatechange = function()
 {
  if (req.readyState == 4)
  {
   var result=req.responseJS;
   if (result['html'])
   {
    $('relatedAndMore').innerHTML = result['html'];
   }
  }
 }
 req.open('GET', '/assets/templ/include_globals/options.php', true);
 req.send({'mode':'uri','value':value});
 $('ContentLandingRelatedID').style.display = 'none';
 $('ContentLandingRelatedLoading').style.display = 'block';
 return false;
}

