/**
 * ImageSlider plugin.
 * Copyright (C) Tiki Web Inteligente 2010 - http://www.tiki.com.br
 */
jQuery.fn.imageslider = (function(options) {

    var $ = jQuery;

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

    return this.each(function() {

        var $slider = $(this);
        
        if (options.orientation == 'horizontal') { // 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' });
                
                $slider.find('.slider_previous a').click(function(){
                    $slider.find('.slider_crop').scrollTo({ top: 0, left: '-=' + (itemWidth * options.step) }, options.speed);
                });
                
                $slider.find('.slider_next a').click(function(){
                    $slider.find('.slider_crop').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);
				
				$slider.find('.slider_previous a').click(function(){
                    
					$slider.find('.slider_crop').scrollTo({ top: '-=' + (itemHeight * options.step), left: 0 }, options.speed);
				});
				
				$slider.find('.slider_next a').click(function(){
                    
					$slider.find('.slider_crop').scrollTo({ top: '+=' + (itemHeight * options.step), left: 0 }, options.speed);
				});
			}
		}	
    });
});

