/*
 * 	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
 *
 */
 
/*
 *	markup example for $("#images").easySlider();
 *	
 * 	<div id="images">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			orientation:	'', //  'vertical' is optional;
			speed: 			800			
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $(this); 				

            // s is the length of the object
            var s = $("img", obj).length;

            //var s = 5;
			var t = 1;


            $("#arrow_col_left").prepend('<span style=\"padding-top:360px; display:block;\" id="'+ options.prevId +'"><a href=\"javascript:void(0);\"><img src=\"images/arrow_left.gif\" alt=\"Left Arrow\"/></a></span> ');
            $("#arrow_col_right").prepend('<span style=\"padding-top:360px; display:block;\" id="'+ options.nextId +'"><a href=\"javascript:void(0);\"><img src=\"images/arrow_right.gif\" alt=\"Left Arrow\"/></a></span>');

            $("a","#"+options.prevId).hide();
			$("a","#"+options.nextId).hide();
			$("a","#"+options.nextId).click(function(){		
                monkeyShine("next");
				$("a","#"+options.prevId).fadeIn();
                if (t==1) $("a","#"+options.prevId).fadeOut();

			});
			$("a","#"+options.prevId).click(function(){		
				monkeyShine("prev");
				if (t==1) $(this).fadeOut();
				$("a","#"+options.nextId).fadeIn();
			});	
			

            function monkeyShine(dir)  {

                //$("#image_leader").fadeOut("slow");
                //$("#01").replaceAll("#02");

                //switch identification method
                $me = $(".image_leader").attr('title');
                $old_me = $("img[title="+ $me +"]");
                parseInt($me);

                if (dir == "next") {if (t==s){$me = 1;} else {++$me;}} else {$me = $me-1;}
                
                t=$me;

                $me = $("img[title="+ $me +"]");
                $old_me.fadeOut(1000, function () {$me.fadeIn(1000);});
                $old_me.removeClass("image_leader");
                $me.addClass("image_leader");

                //alert($my_buddy);
                //$("#image_leader").attr("src","images/arrow_left.gif");


            }// end monkey shine


			if(s>1) $("a","#"+options.nextId).fadeIn();	
		});
	  
	};

})(jQuery);