/**
 * ImageSlider plugin.
 * Copyright (C) Tiki Web Inteligente 2010
 */
jQuery.fn.imageslider = (function(options) {

    var $ = jQuery;

    var options = $.extend({
        step: 1,
        speed: 500,
        orientation: 'horizontal',
        enabled: true
    }, options);

    return this.each(function() {

        var $slider = $(this);

        if (options.orientation == 'horizontal') {
            if ($slider.find('li').length > 1) {
                var itemWidth = $slider.find('li:nth-child(2)').outerWidth(true);
                var itemsTotalWidth = itemWidth * $slider.find('li').length;
                var itemMargin = $slider.find('li:nth-child(2)').css('marginLeft').replace(/px/, '');
                
                $slider.find('ul').css({ 'width': (itemsTotalWidth - itemMargin)+'px' });
                
                if (options.enabled) {
                    $slider.find('.btn_left').click(function(){
                        $slider.find('.slider_wrap').scrollTo({ top: 0, left: '-=' + (itemWidth * options.step) }, options.speed);
                    });
                    
                    $slider.find('.btn_right').click(function(){
                        $slider.find('.slider_wrap').scrollTo({ top: 0, left: '+=' + (itemWidth * options.step) }, options.speed);
                    });
                }
            }
        }
        else { // vertical

            if ($slider.find('li').length > 1) {
                itemHeight = $slider.find('li:nth-child(2)').outerHeight(true);
                //itemsTotalHeight = itemHeight * $slider.find('li').length;
                //itemMargin = $slider.find('li:nth-child(2)').css('marginLeft').replace(/px/, '');
                //$slider.find('ul').css({ 'width': (itemsTotalHeight - itemMargin)+'px' });
                
                if (options.enabled) {
                    $slider.find('.slide_cima').click(function(){
                        $slider.find('.slide_crop').scrollTo({ top: '-=' + (itemHeight * options.step), left: 0 }, options.speed);
                    });
                    
                    $slider.find('.slide_baixo').click(function(){
                        $slider.find('.slide_crop').scrollTo({ top: '+=' + (itemHeight * options.step), left: 0 }, options.speed);
                    });
                }
            }
        }		
    });
});

