jQuery.extend({
init_news: function(option){

 option = $.extend({
    firstname:"",
	secondname:"",
	thirdname:"",
	fourthname:"",
	nexttitle:"Next News:",
	newsspeed:6000,
	mouseover:true,
	clickable:true,
	effectspeed:300,
	imagedir:"",
	mynewscontent:'news_content',
	mynewstitle:'news_title',
	mytotaltitles:3,
	mytotitleitem:""
  }, option);
  
	var firstname=option.firstname;
	var secondname=option.secondname;
	var thirdname=option.thirdname;
	var fourthname=option.fourthname;
	var newsspeed=option.newsspeed;
	var nexttitle=option.nexttitle;
	var mouseover=option.mouseover;
	var clickable=option.clickable;
	var effectspeed=option.effectspeed;
	var imagedir=option.imagedir;
		
	var mynewscontent=option.mynewscontent;
	var mynewstitle=option.mynewstitle;
	var mytotaltitles=option.mytotaltitles;
	var mytitleitem=option.mytitleitem;
		
	effectspeed=parseInt(effectspeed,10);
	var mynextimg=$('#news_next').attr('value'); if (!mynextimg){mynextimg=imagedir+'next';}
	var mypauseimg=$('#news_pause').attr('value'); if (!mypauseimg){mypauseimg=imagedir+'pause';}
	var mynextimg0=$('#news_next0').attr('value'); if (!mynextimg0){mynextimg0=imagedir+'next0';}
	var mypauseimg0=$('#news_pause0').attr('value'); if (!mypauseimg0){mypauseimg0=imagedir+'pause0';}

	var activechk,mysize,myfirst,myfirst_explain,active,timer;
			mysize=$('#'+firstname+' .'+mytitleitem).size();
			
			/**
			 * Initiate new (Start from first one)
			 */
			active=mysize-1;
			timer=setTimeout(autonext,1,1);
			
			/**
			 * Show
			 */
			$('#'+fourthname+' #news_next').click(function(){
			
				clearTimeout(timer);
				$(this).attr({value:mynextimg0});
				$('#'+fourthname+' #news_pause').attr({value:mypauseimg});
				
				active=active+1;
				if (active==mysize){active=0;}
				
				var mynow=$('#'+firstname+' .'+mytitleitem).eq(active).children('div.'+mynewscontent).html();
				
				/**
				 * Next titles
				 */
				var nextnum=active; // Set nextnum to active
				var next_title = [mytotaltitles];// Set titles array
				
				for (var i=0;i<mytotaltitles;i++) {
					nextnum=nextnum+1; // Increase to the next one.
					nextnum=nextnum%mysize;
					next_title[i]=$('#'+firstname+' .'+mytitleitem).eq(nextnum).children('div.'+mynewstitle).html();
				}

				
				$('#'+secondname).fadeOut(effectspeed,function(){
					$('#'+secondname).empty();
					$('#'+secondname).html(mynow);
					
					$('#'+thirdname).empty();
					for (var i=0;i<mytotaltitles;i++) {
						$('#'+thirdname).append('<div class="'+mynewstitle+'_block bg'+(i%2)+'">'+next_title[i]+'</div>');
					}
					
					$('#'+secondname).fadeIn(effectspeed);
					
					/**
					 * Select other news item from short info.
					 */
					if (clickable===true)
					{		
						$('#'+thirdname+' .'+mynewstitle+'_block').click(function(){
							clearTimeout(timer);
							var index = ($('#'+thirdname+' .'+mynewstitle+'_block').index(this) + active) % mysize;
							timer=setTimeout(autonext,1,index);
							active=index;
							autonext();
						});
					}
						
				});
					
				timer=setTimeout(autonext,newsspeed,active);
			});

			
			/**
			 * Stop on mouse over
			 */
			if (mouseover===true)
			{					
				$('#'+secondname).hover(function(){
					clearTimeout(timer);
					activechk=$('#'+fourthname+' #news_next').attr('value');
					$('#'+fourthname+' #news_pause').attr({value:mypauseimg0});
					$('#'+fourthname+' #news_next').attr({value:mynextimg});
				},function(){
					$('#'+fourthname+' #news_pause').attr({value:mypauseimg});
						if (activechk==mynextimg0){timer=setTimeout(autonext,100,active);}
				});
				
			}
			
			/**
			 * Time out
			 */
			var _st = window.setTimeout; 
			window.setTimeout = function(fRef, mDelay) { 
				if(typeof fRef == 'function'){ 
					var argu = Array.prototype.slice.call(arguments,2); 
					var f = (function(){ fRef.apply(null, argu); }); 
					return _st(f, mDelay); 
				} 
				return _st(fRef,mDelay); 
			}; 

			/**
			 * Display next automatically
			 */
			function autonext(){
				$('#'+fourthname+' #news_next').eq(0).click();
			}

			timer=setTimeout(autonext,newsspeed,1);


}
});