/*******************************************************************************
	TITLE: 			List Browser Plugin
	
	AUTHOR:			Shaun Crittenden
	
	VERSION:		1.0
	
	REQUIRES:		jQuery v1.3.2
	
	EXPECTS:		Selector to element that contains an unordered list(ul) and list items(li)
	                selector > ul > li

	DESCRIPTION:	Simple plugin that allows you to show one list item at a time along with the ability to navigate through all items.
	
*******************************************************************************/

(function($) {
    $.fn.extend({
        listbrowser: function() {

            return this.each(function() {


                // VARIABLES
				var $shell = $(this);
				var $items = $("ul li", $shell);
				var $next = $(".forward", $shell);
				var $prev = $(".back", $shell);
				var total = $items.length;
				var current = 0;
				var controls;

			    
			    // FUNCTIONS
                init = function(){
                    initialHide();
                    buildControl();
                };
                
                initialHide = function(){
                    $items.each(function(i){
                        if(i > 0) {
                            $(this).hide();
                        }
                    });
                };
                
                next = function(){
                    if(current == (total - 1) ) {
                        current = 0;
                    } else {
                        current = current + 1;
                    }
                    show(current);
                };
                
                prev = function(){
                    if(current == 0) {
                        current = total - 1;
                    } else {
                        current = current - 1;
                    }
                    show(current);
                };
                
                show = function(index){
                    $items.each(function(i){
                        if(i != index) {
                            $(this).hide();
                        } else {
                            $(this).show();
                        }
                    });
                };
                
                buildControl = function(){
                    //raises issue of applying png fix after page load
                    //controls = "controls here...";
                    //$shell.append(controls);
                }


                // EVENT LISTENERS
                
                $next.click(function(){
                    next();
                });
                
                $prev.click(function(){
                    prev();
                });
			    
			    
			    // TRIGGERED ON PLUGIN LOAD
                
                init();
            });
        }
    });
})(jQuery);