/* <![CDATA[ */

/**
 * General config for all slider elements
 */
var tx_21torrslider = new Array();


/**
 * Helper function to get the numeric part of an ID
 */
jQuery.fn.iGetNumID = function(psPrefix) {
  var sID = this.attr('id');
  sID = sID.substr(sID.indexOf(psPrefix) + psPrefix.length, sID.length);
  return parseInt(sID);
}


/**
 * Main function
 */
jQuery(document).ready(function($) {
  $('.slider_visual_inner').each(function(piIndex, poElement) {

    // Get config
    var oPlugin     = $(this).parent().parent();
    var iID         = oPlugin.iGetNumID('tx_21torrslider_');
    var aConfig     = tx_21torrslider[iID];

    // Set new size to child elements
    $(this).children('.slider_content').css({
      'height': oPlugin.css('height'),
      'width':  oPlugin.css('width')
    });

    // Add fade in animation
    $(this).parent().parent().mouseenter(function() {
      if (aConfig['arrows'] == 'auto') {
        oPlugin.children('.browse').stop(true, true).fadeIn('slow');
      }
      if (aConfig['navi'] == 'auto') {
        oPlugin.children('.navi').stop(true, true).fadeIn('slow');
      }
    });

    // Add fade out animation
    $(this).parent().parent().mouseleave(function() {
      if (aConfig['arrows'] == 'auto') {
        oPlugin.children('.browse').stop(true, true).fadeOut('slow');
      }
      if (aConfig['navi'] == 'auto') {
        oPlugin.children('.navi').stop(true, true).fadeOut('slow');
      }
    });

    // Add sroll animation
    $(this).parent().stop(true, false).scrollable({
      clickable: true,
      circular:  true,
      speed:     aConfig['speed']
    }).stop(true, false).navigator().stop(true, false).autoscroll({
      autoplay:  aConfig['autoplay'],
      autopause: aConfig['autopause'],
      interval:  aConfig['interval']
    });
    
    // Remap titles to navi buttons
    $(this).children('.slider_content').not('.cloned').each(function(piChildIndex, poChild) {
      if (aConfig['navi'] != 'never') {
        $('#slider_navi_' + iID).children('[href=#' + piChildIndex + ']').attr('title', $(this).attr('title')).tooltip();
      }
      $(this).removeAttr('title');
    });
    
    // Show arrows if used
    if (aConfig['arrows'] == 'always') {
      oPlugin.children('.browse').show();
    }

    // Show navi if used
    if (aConfig['navi'] == 'always') {
      oPlugin.children('.navi').show();
    }

    // Finally show content
    $(this).parent().css('left', '0px');

  });
});

/* ]]> */
