jQuery.fn.serckNews = function(options){
	var options = jQuery.extend({
		values: [],
		delay: 10000,
		width: 220,
		colour: ''
	},options);
	
	return this.each(function(){
	
		var transitioning = false;
		var current = 0;
		var nav = jQuery('ul#home-news-options');
		var navitems = nav.children('li');
		var sections = jQuery('.home-news-section');
		
		var holder = jQuery('<div id="home-news-holder"></div>');
		
		holder.appendTo(jQuery(this));
		
		sections.each(function(u){
			if(u != 0){
				jQuery(this).remove();
			}else{
				jQuery(this).appendTo(holder);
			}
		});
		
		
		navitems.each(function(u){
			if(u == 0){
				toggleSelected(jQuery(this));			
			}
		});
		
		navitems.each(function(u){
			jQuery(this).click(function(e){
				e.preventDefault();
				if(transitioning != true){
					transition(u);				
				}
			})
		});


		function toggleSelected(target){
			if(target.children('a').hasClass('selected')){
				target.children('a').removeClass('selected');
			}else{
				target.children('a').addClass('selected');
			}
		}
		
		function transition(i){
			if(i != current){
				transitioning = true;
				holder.contents().fadeOut(500);
				setTimeout(function(){
					holder.contents().remove();
					sections.each(function(u){
						if(u == i){
							jQuery(this).appendTo(holder);
						}
					});
					navitems.each(function(u){
						if(u == i || u == current){
							toggleSelected(jQuery(this));			
						}
					});
					holder.contents().fadeIn();
					current = i;
					transitioning = false;
				},500);			
			}
		}
	})
};
