Drupal.behaviors.jcarousel_placeholder_0 = function (context) {
  jQuery('#sectiuni').jcarousel({
    auto: 5,
    wrap: 'circular',
    animation: 1300,
    scroll: 1,
    initCallback: jcarousel_placeholder_0_initCallback,
    itemFirstInCallback:  jcarousel_placeholder_0_itemFirstInCallback,
    buttonNextHTML: null,
    buttonPrevHTML: null
  });
};

function jcarousel_plceholder_0_itemVisibleInCallback(carousel, item, i, state, evt)
{
  var idx = carousel.index(i, Drupal.settings.placeholder_0.length);
  carousel.add(i, jcarousel_placeholde_0_get_item(Drupal.settings.placeholder_0[idx - 1]));
}

function jcarousel_plceholder_0_itemVisibleOutCallback(carousel, item, i, state, evt)
{
  carousel.remove(i);
}

function jcarousel_placeholde_0_get_item($element)
{
  return '<a href="' + $element['url'] + '"><img src="' + $element['filepath'] + '" alt="" /></a>';
}

function jcarousel_placeholder_0_initCallback(carousel)
{
  jQuery('#sectiuni123 .nr a').bind('click', function() {
      carousel.stopAuto();
      carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
      return false;
  });

  jQuery('#sectiuni123 .nr select').bind('change', function() {
      carousel.stopAuto();
      carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
      return false;
  });

  jQuery('#sectiuni').each(function () {
    $(this).bind("mouseenter", function (){
      carousel.mouseenter = 1;
      carousel.stopAuto();
    });
    $(this).bind("mouseleave", function (){
      carousel.mouseenter = null;
      carousel.startAuto();
    });
  });
}

//Aplicam class selected pe butonul curent
function jcarousel_placeholder_0_itemFirstInCallback(carousel, item, idx, state)
{
  var i;

  if (!carousel.mouseenter) carousel.startAuto(); //reset autoscrolling time
  
  //find out more link
  $('.find_more_links').attr('href', $(item).children().eq(0).attr('href'));

  var dots = jQuery('#sectiuni123 .nr a');

  //this is the real index element
  var relative = (idx - 1) % dots.length;

  //we add the next n -1 items and item 1
  if (relative == 0)
  {
    //add the next ones
    for(i = 1; i < dots.length; i++) carousel.add(idx + i , jcarousel_placeholde_0_get_item(Drupal.settings.placeholder_0[i]));
    //add the first one
    carousel.add(idx + i, jcarousel_placeholde_0_get_item(Drupal.settings.placeholder_0[0]));

    //remove the old ones
    if (idx > dots.length)
    {
      for(i = idx - 1; i > idx - dots.length - 1; i--) carousel.remove(i);
    }
  }

  dots.each(function(i){
    //if it is the first item in carousel, we rewrite the new indexes
    if (relative == 0) jQuery(this).attr('rel', idx + i);

    jQuery(this).removeClass('s');
    if (i == relative)
    {
      jQuery(this).addClass('s');
    }
  });
}



/******************************* jcarousel featured releases homepage ************************/

Drupal.behaviors.jcarousel_orchard_0 = function (context) {
  jQuery('#albums_mirroring').jcarousel({
    animation: 800,
    scroll: 4
  });
};

/******************************** jcarousel featured labels/artists *******************************/

Drupal.behaviors.jcarousel_placeholder_3 = function (context) {
  jQuery('.jcarousel-simple-small:not(.jcarousel-simple-small-processed)').jcarousel({
    animation: 800,
    scroll: 3,
    itemLoadCallback: tabs_start
  });
  jQuery('.jcarousel-simple-small:not(.jcarousel-simple-small-processed)').addClass('jcarousel-simple-small-processed');
};

/********************************* jcarousel featured movies **************************************/

Drupal.behaviors.jcarousel_placeholder_4 = function (context) {
  jQuery('.jcarousel-video:not(.jcarousel-video-processed)').jcarousel({
    animation: 800,
    scroll: 1,
    initCallback: jcarousel_placeholder_4_initCallback
  });
  jQuery('.jcarousel-video:not(.jcarousel-video-processed)').addClass('jcarousel-video-processed');
};

function jcarousel_placeholder_4_initCallback(carousel)
{
  $('.jcarousel-prev-horizontal').eq(0).click(function(){
    var player = flowplayer();
    player.unload();
  });

  $('.jcarousel-next-horizontal').eq(0).click(function(){
    var player = flowplayer();
    player.unload();
  });
}

/************************* jcarousel simple gallery **************************/
Drupal.behaviors.jcarousel_simplegallery = function (context)
{
  jQuery('.jcarousel-simple-gallery').jcarousel({
    animation: 800,
    scroll: 4
  });
}

