function showTip(event, content)
{
  var eventSrc = window.event ? window.event.srcElement : event.currentTarget;

  var tipBox = document.createElement('DIV');
  tipBox.innerHTML  = content;
  tipBox.id         = 'tip-box';
  tipBox.visibility = 'hidden';

  getNode('content-left').appendChild(tipBox);

  tipBox.style.right = '0px';
  tipBox.style.bottom = (getNode('content-footer-bg').clientHeight + 2) + 'px';
  tipBox.visibility = 'visible';
} // end func showTip


function hideTip()
{
  var tipBox;

  if (tipBox = getNode('tip-box'))
    tipBox.parentNode.removeChild(tipBox);
} // end func hideTip


function showMovie(event, content)
{
  with (window.event ? window.event.srcElement : event.currentTarget) {
    blur();
  }

  var movieBox = getNode('movie-box');
  if (movieBox)
    movieBox.parentNode.removeChild(movieBox);

  movieBox = document.createElement('DIV');
  movieBox.id = 'movie-box';
  getNode('content-left').appendChild(movieBox);

  var so = new SWFObject(content, 'jab', 460, 316, 8, '#333333');
  so.addParam('menu', false);
  so.addParam('wmode', 'opaque');
  so.write('movie-box');

  return false;
} // end func showMovie

function hideMovie()
{
  var movieBox;

  if (movieBox = getNode('movie-box'))
    movieBox.parentNode.removeChild(movieBox);
} // end func hideMovie


var contentPagerItems  = new Array();
var contentPagerImages = new Array();

function registerPager()
{
  var node = getNode('content-pager');
  if (!node)
    return;

  var items = node.getElementsByTagName('A');

  contentPagerItems = new Array();
  for (var i = 0, j = items.length; i < j; ++i)
    contentPagerItems[contentPagerItems.length] = items[i];
} // end func registerPager


function loadTeaser(e, idx)
{
  var eventSrc = window.event ? window.event.srcElement : e.currentTarget;
  eventSrc.blur();

  with (window.event ? window.event.srcElement : e.currentTarget) {
    blur();
  }
  for (i = 0, j = contentPagerItems.length; i < j; ++i)
    contentPagerItems[i].className = i == idx ? 'selected' : '';
  getNode('teaser').src = contentPagerImages[idx];

  return false;
} // end func loadTeaser


function initThumbnails(thumbsWidth)
{
//  if (thumbsWidth < 208)
//    return;

  var children      = getNode('children');
  var thumbnailBox  = getNode('thumbnail-box');
  var thumbnailBar  = getNode('thumbnail-bar');
  var thumbnails    = getNode('thumbnails');

  children.className = 'js';
  getNode('content-right').className = 'js';

  with (thumbnailBox) {
    style.cssFloat   = 'left';
    style.height     = '84px';
    style.styleFloat = 'left';
    style.width      = '208px';
  }

  with (thumbnailBar) {
//    style.clip     = 'rect(0px, 30px, 40px, 0px)';
    style.overflow = 'hidden';
    style.position = 'relative';
    style.height   = '126px';
    style.width    = '208px';
  }

  with (thumbnails) {
    style.left     = '0px';
    style.position = 'absolute';
    style.top      = '0px';
    style.width    = thumbsWidth + 'px';
  }

  if (thumbsWidth < 208)
    return;

  var rightButton = document.createElement('img');
  with (rightButton) {
    alt              = '»';
    id               = 'thumbnailButtonRight';
    src              = '/' + site + '/img/arrow.right.gif'
    style.cssFloat   = 'right';
    style.cursor     = 'pointer';
    style.styleFloat = 'right';
    style.width      = '25px';
    style.height     = '126px';
  }
  children.insertBefore(rightButton, thumbnailBox);
  registerEvent(rightButton, 'mouseover', function() {ma_move('thumbnail-bar', 'thumbnails', 10, 0);});
  registerEvent(rightButton, 'mouseout', function() {ma_stop('thumbnail-bar', 'thumbnails');});

  var leftButton = document.createElement('img');
  with (leftButton) {
    alt              = '«';
    id               = 'thumbnailButtonLeft';
    src              = '/' + site + '/img/arrow.left.gif'
    style.cssFloat   = 'left';
    style.cursor     = 'pointer';
    style.styleFloat = 'left';
    style.width      = '25px';
    style.height     = '126px';
  }
  children.insertBefore(leftButton, thumbnailBox);
  registerEvent(leftButton, 'mouseover', function() {ma_move('thumbnail-bar', 'thumbnails', -10, 0);});
  registerEvent(leftButton, 'mouseout', function() {ma_stop('thumbnail-bar', 'thumbnails');});
} // end func loadTeaser

ma_speed = 100;


function productLoader(event, nodeId, languageId)
{
  if (AjaxRequest.getXmlHttpRequest() == null)
    return true;

  var eventSrc = window.event ? window.event.srcElement.parentNode : event.currentTarget;
  eventSrc.blur();

  var siblings = getNode('thumbnails').getElementsByTagName('A');
  for (var i = 0, j = siblings.length; i < j; ++i)
    siblings[i].className = '';
  eventSrc.className = 'selected';

  AjaxRequest.get(
    {
      'url':        '/productLoader.php?nodeId=' + nodeId + '&lang=' + languageId,
      'onSuccess':  processLoaderResult
    }
  );

  return false;
} // end func productLoader


function processLoaderResult(request)
{
  try {
    eval('var result = ' + request.xmlHttpRequest.responseText);
  } catch (e) {
    alert(e);
    return false;
  }

  hideMovie();

  // background
  if (result.background != null) {
    document.body.style.backgroundImage = 'url(' + result.background + ')';
  }

  // pager
  contentPagerImages = result.images;
  var cntPager = getNode('content-pager');

  // rebuild pager
  if (cntPager) {
    if (contentPagerImages.length < contentPagerItems.length) {
      for (i = contentPagerImages.length, j = contentPagerItems.length; i < j; ++i) {
        var p = contentPagerItems[i].parentNode;
        p.removeChild(contentPagerItems[i]);
        cntPager.removeChild(p);
      }
    } else if (contentPagerImages.length > contentPagerItems.length) {
      for (i = contentPagerItems.length, j = contentPagerImages.length; i < j; ++i) {
        var li = document.createElement('LI');
        cntPager.appendChild(li);
        var a  = document.createElement('A');
        a.onclick = new Function('event', 'loadTeaser(event, ' + i + ')');
        a.innerHTML = i + 1;
        li.appendChild(a);
      }
    }
  }
  registerPager();

  // teaser
  var teaser;
  if (teaser = getNode('teaser')) {
    teaser.src = contentPagerImages[0];
    for (i = 1, j = contentPagerItems.length; i < j; ++i)
      contentPagerItems[i].className = '';
    contentPagerItems[0].className = 'selected';
  }

  // title
  document.title = document.title.replace(/» [^»]+?$/, '» ' + result.title);

  // contents
  getNode('content-right').innerHTML = '<h2>' + result.heading + '</h2>' + result.body.replace(/(?:\\r|\\n)+/g, '\n');

  // tip
  if (result.tip) {
    getNode('content-right').innerHTML += sprintf(
      "<div class='print' id='infoBox'><h3>» %s</h3><p>%s</p></div>",
      result.tipLabel,
      result.tip.replace(/\r\n|\r|\n|\\r\\n|\\r|\\n/g, '<br/>')
    );

    var tipLink = getNode('tip-link');
    if (tipLink == null) {
      tipLink = document.createElement('A');
      tipLink.className  = 'tip-link';
      tipLink.id         = 'tip-link';
      tipLink.onmouseout = hideTip;
      tipLink.innerHTML  = '» ' + result.tipLabel;
      getNode('content-footer').appendChild(tipLink);
    }

    tipLink.style.visibility = 'visible';
    tipLink.onmouseover = new Function('event', 'showTip(event, "' + result.tip.replace(/\r\n|\r|\n|\\r\\n|\\r|\\n/g, '<br/>') + '")');
  } else if (getNode('tip-link')) {
    getNode('tip-link').style.visibility = 'hidden';
  }

  // movie link
  var movieLink = getNode('movieLink');
  if (result.movie != null) {
    if (movieLink == null) {
      movieLink = document.createElement('A');
      movieLink.id         = 'movieLink';
      movieLink.innerHTML  = '» ' + result.movieLabel;
      var listItem = document.createElement('LI');
      listItem.appendChild(movieLink);
      getNode('featureItems').appendChild(listItem);
    }

    movieLink.parentNode.style.visibility = 'visible';
    movieLink.onclick = new Function('event', 'return showMovie(event, "' + result.movie + '");');
  } else if (movieLink) {
    movieLink.parentNode.style.visibility = 'hidden';
  }

  setTargets(getNode('content-right'));
} // end func productLoader

function preloadImages()
{
  for (var i = 0, j = preloads.length; i < j; ++i) {
    var img = new Image();
    img.src = preloads[i];
  }
} // end func preloadImages

