/*
 * 	Easy Slider - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			orientation:	'', //  'vertical' is optional;
			speed: 			800			
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $(this); 				
			var s = $("li", obj).length;
			var w = obj.width(); 
			var h = obj.height(); 
			var ts = s-1;

			var vertical = (options.orientation == 'vertical');
			$("ul", obj).css('width',s*w);			
			if(!vertical) $("li", obj).css('float','left');

      // display slide and description and updates controls
      $('#work-display-controls a').click(function () {
        var slide = parseInt($(this).attr('id').substring($(this).attr('id').indexOf('-')+1));
        var describe = $('.slide:eq('+slide+')').attr('describe');

        $('#work-display-controls a img').attr('src','img/square-black.gif');  // all black squares
        $('#work-display-controls a#slide-' + slide + ' img').attr('src','img/square-red.gif');  // selected - red square

        $('#work-describe p').fadeOut('slow', function () {
          $(this).html(describe).fadeIn('slow');
        });

        show_slide(slide);

        return false;
      });

			function show_slide(slide) {
				slide = (slide>=ts) ? ts : slide;	
				slide = (slide<=0) ? 0 : slide;

				if(!vertical) {
					p = (slide*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						options.speed
					);				
				} else {
					p = (slide*h*-1);
					$("ul",obj).animate(
						{ marginTop: p }, 
						options.speed
					);					
				}
			};
		});
	};

})(jQuery);