/**
 * ImageSlider plugin.
 * Copyright (C) Tiki Web Inteligente 2010
 */
jQuery.fn.imageslider = (function(options) {

    var $ = jQuery;

    var options = $.extend({
        step: 1,
        speed: 500
    }, options);

    return this.each(function() {

        var $slider = $(this);

        if ($slider.find('li').length > 1) {
            itemWidth = $slider.find('li:nth-child(2)').outerWidth(true);
            itemsTotalWidth = itemWidth * $slider.find('li').length;
            itemMargin = $slider.find('li:nth-child(2)').css('marginLeft').replace(/px/, '');
            
            $slider.find('ul').css({ 'width': (itemsTotalWidth - itemMargin)+'px' });
            
            $slider.find('.slide_previous').click(function(){
                $slider.find('.slide_crop').scrollTo({ top: 0, left: '-=' + (itemWidth * options.step) }, options.speed);
            });
            
            $slider.find('.slide_next').click(function(){
                $slider.find('.slide_crop').scrollTo({ top: 0, left: '+=' + (itemWidth * options.step) }, options.speed);
            });
        }
    });
});

