/*
 * 	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.artfosSlider = function(options){
	  
		// default configuration properties
		var defaults = {
            items:          null,
            type:           'Galería',
			prevId: 		'prevBtn',
			prevText: 		'<img src="images/flechita_left.png" alt="Anterior" height=18/>',
			nextId: 		'nextBtn',	
			nextText: 		'<img src="images/flechita_right.png" alt="Siguiente" height=18/>',
            id:             null
		};
        
        eval("var options"+options.id+" = $.extend(defaults, options)");
        
        if (eval("options"+options.id+".items.length")>0){
        }else{
            alert ("Error: Cannot load video gallery");
            return null;
        }
		return this.each(function() {
            var opt = eval ("options"+options.id);
            var current = 0;
			var obj = $(this);
			var s = opt.items.length;
            //$(obj).before('<span style="float:left" id="count'+opt.id+'">'+opt.type+' 1/'+s.toString()+'</span>');
            //$(obj).before('<div class="moveBtns"><a class="prevBtn" id="'+ opt.prevId +'" href=\"javascript:void(0);\">'+ opt.prevText +'</a><a class="nextBtn" id="'+ opt.nextId +'" href=\"javascript:void(0);\">'+ opt.nextText +'</a></div>');
            $(obj).after('<div class="moveBtns"><a class="prevBtn" id="'+ opt.prevId +'" href=\"javascript:void(0);\">'+ opt.prevText +'</a><span id="count'+opt.id+'">'+opt.type+' 1/'+s.toString()+'</span><a class="nextBtn" id="'+ opt.nextId +'" href=\"javascript:void(0);\">'+ opt.nextText +'</a></div>');
//			$("a","#"+options.prevId).hide();
//			$("a","#"+options.nextId).hide();
			$("a#"+opt.nextId).click(function(){
				obj.html(opt.items[++current%s]);
                $("span#count"+opt.id).html(opt.type+' '+((current%s)+1).toString()+'/'+s.toString());
			});
			$("a#"+opt.prevId).click(function(){
                if (--current<0){
                    current += s;
                }
				obj.html(opt.items[current%s]);
                $("span#count"+opt.id).html(opt.type+' '+((current%s)+1).toString()+'/'+s.toString());
			});	
            obj.html(opt.items[current]);
		});
	  
	};

})(jQuery);