// Initialise plugins
$(document).ready( function()
{
    if($(".slider").length != 0) {
        $(".slider").innerfade({
            speed: 'slow', 
            timeout: 5000, 
            type: 'sequence',
            containerheight: '159px'
        });
    }

    // Add 'odd' class to dropdown menu
    $(".dropdown li.firstrow:odd").addClass("odd");

    // Get all image and add a margin left or right, depending on alignment
    $(".textItem img").each(function()
    {
        if($(this).css('float') == 'left')
        {
            $(this).css('margin-right', '10px');
        } else {
            $(this).css('margin-left', '10px');
        }
    });

    if($(".scrollable").length != 0) {
          // Get first item to show in title bar
          $('#slider-title').text( $('.scrollable div img').attr('alt').toUpperCase());
          Cufon.replace('#slider-title');

          // Initialize the Scrollable control
          jQuery(".scrollable").scrollable();

          // Get the Scrollable control
          var scrollable = jQuery(".scrollable").data("scrollable");

          // Set to the number of visible items
          var size = 3;

          // Handle the Scrollable control's onSeek event
          scrollable.onSeek(function(event, index) {

            $('#slider-title').text(this.getItems().eq(index).find('img').attr('alt').toUpperCase());
            Cufon.replace('#slider-title');

            // Check to see if we're at the end
            if (this.getIndex() >= this.getSize() - size) {

              // Disable the Next link
              jQuery("a.next").addClass("disabled");
            }

          });

          // Handle the Scrollable control's onBeforeSeek event
          scrollable.onBeforeSeek(function(event, index) {

            // Check to see if we're at the end
            if (this.getIndex() >= this.getSize() - size) {

              // Check to see if we're trying to move forward
              if (index > this.getIndex()) {

                // Cancel navigation
                return false;

              }
            }
       });
    }
});


