jQuery.extend({
init_news: function(option){

 option = jQuery.extend({
    firstname:"",
	secondname:"",
	thirdname:"",
	fourthname:"",
	playingtitle:"Now Playing:",
	nexttitle:"Next News:",
	prevtitle:"Prev News:",
	newsspeed:6000,
	effectis:0	
  }, option);
		var firstname=option.firstname;
		var secondname=option.secondname;
		var thirdname=option.thirdname;
		var fourthname=option.fourthname;
		var newsspeed=option.newsspeed;
		var effectis=option.effectis;
		var playingtitle=option.playingtitle;
		var nexttitle=option.nexttitle;
		var prevtitle=option.prevtitle;
		effectis=parseInt(effectis,10);
	
		var activechk;
		var activechkmore;
		var mysize;
		var myfirst;
		var myfirst_explain;
		var active;
		var timer;

	
			mysize=jQuery('#'+firstname+' .news_style').size();
			myfirst=jQuery('#'+firstname+' .news_style').eq(0).html();
			
			myfirst_explain=jQuery('#'+firstname+' .news_style').eq(1).attr('rel');
				
			active=0;
				jQuery('#'+secondname).append(myfirst);
				jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+'1/'+mysize+'&nbsp;&nbsp;<br>');
				jQuery('#'+thirdname).append(nexttitle+myfirst_explain);

			jQuery('#'+fourthname+' #news_next').click(function(){
					clearTimeout(timer);
						jQuery(this).attr({src:'/theme/ttbih/images/next0.gif'});
					jQuery('#'+fourthname+' #news_prev').attr({src:'/theme/ttbih/images/prev.gif'});
					jQuery('#'+fourthname+' #news_pause').attr({src:'/theme/ttbih/images/pause.gif'});
						active=active+1;
				if (active==mysize){active=0;}
					var mynum=active+1;
					var mynow=jQuery('#'+firstname+' .news_style').eq(active).html();
					var nextnum=mynum;
							if (nextnum==mysize){nextnum=0;}
				var mynow_explain=jQuery('#'+firstname+' .news_style').eq(nextnum).attr('rel');
				
				if(firstname == 'static_pages'){
					jQuery('#static_pages').css("display","block");
					content_height = jQuery('#'+firstname+' .news_style').eq(active).height();
					jQuery('#static_pages').css("display","none");

				}
								
				switch (effectis)
				{
					
				case 0:
				jQuery('#'+secondname).fadeOut("slow",function(){
					jQuery('#'+secondname).empty();
					jQuery('#'+secondname).html(mynow);
					jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					jQuery('#'+thirdname).append(nexttitle+mynow_explain);
					jQuery('#'+secondname).fadeIn("slow");
						
				});
				break;
				case 1:
				jQuery('#'+secondname).slideUp("slow",function(){
					jQuery('#'+secondname).empty();
					jQuery('#'+secondname).html(mynow);
					jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					jQuery('#'+thirdname).append(nexttitle+mynow_explain);
					jQuery('#'+secondname).slideDown("slow");
						
				});
				break;
				case 2:
					jQuery('#'+secondname).animate({width:"0px",opacity: 0.33},1000,function(){
					jQuery('#'+secondname).empty();
					jQuery('#'+secondname).html(mynow);
					jQuery('#'+secondname).animate({width:"100%",opacity: 1},600,function(){
					
					jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					jQuery('#'+thirdname).append(nexttitle+mynow_explain);	

					});
									
					});
					
					
					break;
					
				case 3:
					jQuery('#'+secondname).html(mynow);
					jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					jQuery('#'+thirdname).append(nexttitle+mynow_explain);
					
						
				
				break;
					default:
					jQuery('#'+secondname).fadeOut("slow",function(){
					jQuery('#'+secondname).empty();
					jQuery('#'+secondname).html(mynow);
					jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					jQuery('#'+thirdname).append(nexttitle+mynow_explain);
					jQuery('#'+secondname).fadeIn("slow");
						
				});
				break;
				}
				
				
					
					timer=setTimeout(autonext,newsspeed,active);
		});
					jQuery('#'+fourthname+' #news_prev').click(function(){
						clearTimeout(timer);
							jQuery(this).attr({src:'prev0.gif'});
						jQuery('#'+fourthname+' #news_next').attr({src:'/theme/ttbih/images/next.gif'});
						jQuery('#'+fourthname+' #news_pause').attr({src:'/theme/ttbih/images/pause.gif'});
							active=active-1;
					if (active<0){active=mysize-1;}
						var mynum=active+1;
						var myprevnum=mynum-2;
					if (myprevnum<0){myprevnum=mysize-1;}
							var mynow=jQuery('#'+firstname+' .news_style').eq(active).html();
							var mynow_explain=jQuery('#'+firstname+' .news_style').eq(myprevnum).attr('rel');
							switch (effectis)
				{
						case 0:
								jQuery('#'+secondname).fadeOut("slow",function(){
						jQuery('#'+secondname).empty();
						jQuery('#'+secondname).html(mynow);
						jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						jQuery('#'+thirdname).append(prevtitle+mynow_explain);
						jQuery('#'+secondname).fadeIn("slow");
						});
							break;
							case 1:
								jQuery('#'+secondname).slideUp("slow",function(){
						jQuery('#'+secondname).empty();
						jQuery('#'+secondname).html(mynow);
						jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						jQuery('#'+thirdname).append(prevtitle+mynow_explain);
						jQuery('#'+secondname).slideDown("slow");
						});
							break;
							case 2:
								jQuery('#'+secondname).animate({width:"0px",opacity: 0.33},1000,function(){
					jQuery('#'+secondname).empty();
					jQuery('#'+secondname).html(mynow);
					jQuery('#'+secondname).animate({width:"100%",opacity: 1},600,function(){
					
					jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					jQuery('#'+thirdname).append(prevtitle+mynow_explain);	

					});
									
					});
							break;
						case 3:
								
						jQuery('#'+secondname).html(mynow);
						jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						jQuery('#'+thirdname).append(prevtitle+mynow_explain);
						
							break;
				
							default:
						jQuery('#'+secondname).fadeOut("slow",function(){
						jQuery('#'+secondname).empty();
						jQuery('#'+secondname).html(mynow);
						jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						jQuery('#'+thirdname).append(prevtitle+mynow_explain);
						jQuery('#'+secondname).fadeIn("slow");
						});
							break;
							}

					
							timer=setTimeout(autoprev,newsspeed,active);
					});

					jQuery('#'+fourthname+' #news_pause').click(function(){
							jQuery(this).attr({src:'/theme/ttbih/images/pause0.gif'});
						jQuery('#'+fourthname+' #news_next').attr({src:'/theme/ttbih/images/next.gif'});
						jQuery('#'+fourthname+' #news_prev').attr({src:'/theme/ttbih/images/prev.gif'});
							clearTimeout(timer);
						});
					/*jQuery('#'+secondname).hover(function(){
						clearTimeout(timer);
						activechk=jQuery('#'+fourthname+' #news_next').attr('src');
						activechkmore=jQuery('#'+fourthname+' #news_prev').attr('src');	
						jQuery('#'+fourthname+' #news_pause').attr({src:'/theme/ttbih/images/pause0.gif'});
						jQuery('#'+fourthname+' #news_next').attr({src:'/theme/ttbih/images/next.gif'});
						jQuery('#'+fourthname+' #news_prev').attr({src:'/theme/ttbih/images/prev.gif'});
							},function(){
						jQuery('#'+fourthname+' #news_pause').attr({src:'/theme/ttbih/images/pause.gif'});
						if (activechk=='next.gif' && activechkmore=='/theme/ttbih/images/prev.gif'){
						timer=setTimeout(autonext,100,active);
							}
						if (activechk=='next0.gif'){timer=setTimeout(autonext,100,active);}
						if (activechk=='next.gif' && activechkmore=='prev0.gif'){timer=setTimeout(autoprev,100,active);}
					});*/
					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); 
						}; 

					function autonext(q){
						if (!q){q=0;}
							myend=jQuery('#'+firstname+' .news_hide_style').size();
							myend=myend-1;
							if (q >= myend){q=0;}
								jQuery('#'+fourthname+' #news_next').eq(q).click();
								q=q+1;
	
					}
					function autoprev(q){
						if (!q){q=0;}
							myend=jQuery(".news_hide_style").size();
							myend=myend-1;
							if (q >= myend){q=0;}
								jQuery('#'+fourthname+' #news_prev').eq(q).click();
								q=q+1;
								
									
					}
					timer=setTimeout(autonext,newsspeed,1);


}
});