/* starfish slider ------------------------------------------ */
(function($){
	$.fn.starfishSlider = function(options) {
		
		var opt 			= $.extend($.fn.starfishSlider.defaults,options);
		var focal_holder 	= $(this);
		var focal_count 	= focal_holder.children("li").size() - 1;
		var focal_ctr 		= 0;
		var focal_timer		= 5000;
		
		/*
			if focal slider is disabled then 
			destroy the other li's
		*/
		if(opt.focal_slider) {
			focal_create_hidden();			
			focal_start();
		} else {
			focal_holder.children("li").each(function(){
				var childClass = $(this).attr("class");
				if(childClass != "active") {
					$(this).remove();
				}
			});
		}
		
		/*
			create a hidden input it will be used as a 
			counter for the text slider
		*/
		function focal_create_hidden(){
			var focal_html = "<input type='hidden' value='0' name='focal_hidden' id='focal_hidden' />";
			focal_holder.prepend(focal_html);
		};
		
		/*
			run every n seconds declared by 
			the user 1000 = 1 second
		*/
		function focal_start() {
			focal_timer = setInterval(focal_slider,opt.focal_timer);
		};
		
		function focal_slider() {
			focal_hidden_val	= $("#focal_hidden").val();
			current_list 		= focal_holder.children("li"+opt.focal_list_name+focal_hidden_val);					
			
			if(focal_hidden_val == focal_count){ next_list = $("li"+opt.focal_list_name+"0"); } 
			else { next_list = current_list.next("li"); }
			
			if(jQuery.browser.msie) { current_list.hide(); next_list.show(); } 
			else {		
				switch(opt.focal_effect) {
					case "fade":
							current_list.fadeOut(opt.focal_fade_difference);
							next_list.fadeIn(opt.focal_fade_difference);
						break;
					case "show":
							current_list.hide(opt.focal_fade_difference);
							next_list.show(opt.focal_fade_difference);
						break;
				}
			}
			
			focal_ctr++;
			if(focal_ctr > focal_count) {focal_ctr = 0;}	
			
			$("#focal_hidden").val(focal_ctr);
		};
	}
	/*
		starfish default variables
	*/
	$.fn.starfishSlider.defaults = {
		focal_timer: 2000,
		focal_list_name: "#list_",
		focal_fade_difference: 500,
		focal_effect: "fade",
		focal_slider: true
	};
	
})(jQuery);