jQuery.extend(jQuery.roundabout_shape,
{
  conleosShape: function(r, a, t) {
    var d = r * 180.0 / Math.PI;
    var nr = r > Math.PI ? 2*Math.PI - r : r;
    return {
      x: Math.sin(r + a),
      y: (Math.sin(r + 3*Math.PI/2 + a) / 8) * t,
      z: (Math.cos(r + a) + 1) / 2,
      scale: (Math.sin(r + Math.PI/2 + a) / 2) + 0.5,
      fade: Math.sin(nr / 2),
      hideText: d > 80 && d < 280
    };
  }
});

var createCarousel = function(entries)
{
  var childNodes = [];

  $('.home-reference .cards').hide();

  for(var entryIndex = 0; entryIndex < entries.length; entryIndex++)
  {
    childNodes.push({
      tagName: 'div',
      className: 'carousel-entry',
      childNodes: [{
        tagName: 'div',
        className: 'carousel-entry-image',
        childNodes: [{
          tagName: 'img',
          src: getResourceUrl(entries[entryIndex].imageSrc),
          alt: ''
        }]
      },{
        tagName: 'div',
        className: 'carousel-entry-fader',
        innerHTML: '&nbsp;'
      },{
        tagName: 'div',
        className: 'carousel-entry-content',
        childNodes: [{
          tagName: 'div',
          className: 'title',
          innerHTML: entries[entryIndex].title,
          childNodes: entries[entryIndex].editUrl != null ? [{
            tagName: 'a',
            href: entries[entryIndex].editUrl,
            target: 'cms',
            childNodes: [{
              tagName: 'img',
              src: getResourceUrl('/images/conleos/symbol/edit.gif'),
              alt: '',
              border: '0'
            }]
          }] : []
        },{
          tagName: 'div',
          className: 'headline',
          innerHTML: entries[entryIndex].headline,
          childNodes: entries[entryIndex].editUrl != null ? [{
            tagName: 'a',
            href: entries[entryIndex].editUrl,
            target: 'cms',
            childNodes: [{
              tagName: 'img',
              src: getResourceUrl('/images/conleos/symbol/edit.gif'),
              alt: '',
              border: '0'
            }]
          }] : []
        },{
          tagName: 'div',
          className: 'text',
          innerHTML: entries[entryIndex].text,
          childNodes: entries[entryIndex].editUrl != null ? [{
            tagName: 'a',
            href: entries[entryIndex].editUrl,
            target: 'cms',
            childNodes: [{
              tagName: 'img',
              src: getResourceUrl('/images/conleos/symbol/edit.gif'),
              alt: '',
              border: '0'
            }]
          }] : []
        },{
          tagName: 'div',
          className: 'link',
          childNodes: [{
            tagName: 'div',
            className: 'link-a',
            childNodes: [{
              tagName: 'a',
              href: entries[entryIndex].href,
              innerHTML: entries[entryIndex].link
            }]
          },{
            tagName: 'div',
            className: 'link-img',
            childNodes: [{
              tagName: 'a',
              href: entries[entryIndex].href,
              childNodes: [{
                tagName: 'img',
                src: isRunningIE6 ? getResourceUrl('/images/conleos/symbol/link.gif')
                                  : getResourceUrl('/images/conleos/symbol/link.png'),
                alt: ''
              }]
            }]
          }]
        },{
          tagName: 'div',
          className: 'edit-link',
          childNodes: entries[entryIndex].editUrl != null ? [{
            tagName: 'a',
            href: entries[entryIndex].editUrl,
            target: 'cms',
            childNodes: [{
              tagName: 'img',
              src: getResourceUrl('/images/conleos/symbol/edit.gif'),
              alt: '',
              border: '0'
            }]
          }] : []
        }]
      }]
    });
  }

  $('.home-reference').appendDom([{
    tagName: 'div',
    className: 'carousel',
    childNodes: childNodes
  }]);

  $('.carousel').roundabout({
    childSelector: 'div',
    minOpacity: 1.0,
    minScale: 0.4,
    maxScale: 1.0,
    tilt: 0,
    shape: 'conleosShape'
  });

  setTimeout(function() {

    $('.carousel').roundabout_animateToNextChild();

    var animateCarouselHandle = setInterval(function() {
      $('.carousel').roundabout_animateToNextChild();
    }, 10000);

    $('.carousel .carousel-entry').bind('click', function() {
      clearInterval(animateCarouselHandle);
    })

  }, 1000);
};

