// Easy News - jQuery plugin for News Slide by Michael Lo
// http://jquery.000webhost.info
// Copyright (c) 2007 Michael Lo
// Dual licensed under the MIT and GPL licenses.
// http://www.opensource.org/licenses/mit-license.php
// http://www.gnu.org/licenses/gpl.html
// free for anyone like Jquery. Enjoy!

jQuery.extend({
init_news: function(firstname,secondname,thirdname,fourthname,newsspeed,effectis,nowpage,nextpage,prevpage){
	effectis=parseInt(effectis);
	if (!newsspeed){newsspeed=6000;}if (!effectis){effectis=0;}
	var activechk,activechkmore,myblock,mysize,myfirst,myfirst_explain,active,timer;
			myblock='<div class=myblock id=news_block></div>';
			mysize=$('#'+firstname+' .news_style').size();
			myfirst=$('#'+firstname+' .news_style').eq(0).html();
			myfirst_explain=$('#'+firstname+' .news_style').eq(1).attr('rel');
			active=0;
				$('#'+secondname).append(myfirst);
				$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': 1/'+mysize+'&nbsp;&nbsp;<br>');
				$('#'+thirdname).append(nextpage+': '+myfirst_explain);

//////////////////////////Next Click//////////////////////////////////////////////////////////////
			$('#'+fourthname+' img:eq(2)').click(function(){
					clearTimeout(timer);
						$(this).attr({src:'js/easynews/next0.gif'});
					$('#'+fourthname+' img:eq(0)').attr({src:'js/easynews/prev.gif'});
					$('#'+fourthname+' img:eq(1)').attr({src:'js/easynews/pause.gif'});
						active=active+1;
				if (active==mysize){active=0;}
					var mynum=active+1;
					var mynow=$('#'+firstname+' .news_style').eq(active).html();
					var nextnum=mynum;
							if (nextnum==mysize){nextnum=0;}
				var mynow_explain=$('#'+firstname+' .news_style').eq(nextnum).attr('rel');
				
				switch (effectis)
				{
					
				case 0:
				$('#'+secondname).fadeOut("slow",function(){
					$('#'+secondname).empty();
					$('#'+secondname).html(mynow);
					$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					$('#'+thirdname).append(nextpage+': '+mynow_explain);
					$('#'+secondname).fadeIn("slow");
						
				});
				break
				case 1:
				$('#'+secondname).slideUp("slow",function(){
					$('#'+secondname).empty();
					$('#'+secondname).html(mynow);
					$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					$('#'+thirdname).append(nextpage+': '+mynow_explain);
					$('#'+secondname).slideDown("slow");
						
				});
				break
				case 2:
					$('#'+secondname).animate({width:"0px",opacity: 0.33},1000,function(){
					$('#'+secondname).empty();
					$('#'+secondname).html(mynow);
					$('#'+secondname).animate({width:"100%",opacity: 1},600,function(){
					
					$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					$('#'+thirdname).append(nextpage+': '+mynow_explain);	

					});
									
					});
					
					
					break
					
				case 3:
					$('#'+secondname).html(mynow);
					$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					$('#'+thirdname).append(nextpage+': '+mynow_explain);
					
						
				
				break
					default:
					$('#'+secondname).fadeOut("slow",function(){
					$('#'+secondname).empty();
					$('#'+secondname).html(mynow);
					$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					$('#'+thirdname).append(nextpage+': '+mynow_explain);
					$('#'+secondname).fadeIn("slow");
						
				});
				break
				}
					
					timer=setTimeout(autonext,newsspeed,active);
		});
//////////////////////////Prev Click//////////////////////////////////////////////////////////////
					$('#'+fourthname+' img:eq(0)').click(function(){
						clearTimeout(timer);
							$(this).attr({src:'js/easynews/prev0.gif'});
						$('#'+fourthname+' img:eq(2)').attr({src:'js/easynews/next.gif'});
						$('#'+fourthname+' img:eq(1)').attr({src:'js/easynews/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=$('#'+firstname+' .news_style').eq(active).html();
							var mynow_explain=$('#'+firstname+' .news_style').eq(myprevnum).attr('rel');
							switch (effectis)
				{
						case 0:
								$('#'+secondname).fadeOut("slow",function(){
						$('#'+secondname).empty();
						$('#'+secondname).html(mynow);
						$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						$('#'+thirdname).append(prevpage+': '+mynow_explain);
						$('#'+secondname).fadeIn("slow");
						});
							break
							case 1:
								$('#'+secondname).slideUp("slow",function(){
						$('#'+secondname).empty();
						$('#'+secondname).html(mynow);
						$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						$('#'+thirdname).append(prevpage+': '+mynow_explain);
						$('#'+secondname).slideDown("slow");
						});
							break
							case 2:
								$('#'+secondname).animate({width:"0px",opacity: 0.33},1000,function(){
					$('#'+secondname).empty();
					$('#'+secondname).html(mynow);
					$('#'+secondname).animate({width:"100%",opacity: 1},600,function(){
					
					$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
					$('#'+thirdname).append(prevpage+': '+mynow_explain);	

					});
									
					});
							break
						case 3:
								
						$('#'+secondname).html(mynow);
						$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						$('#'+thirdname).append(prevpage+': '+mynow_explain);
						
							break
				
							default:
						$('#'+secondname).fadeOut("slow",function(){
						$('#'+secondname).empty();
						$('#'+secondname).html(mynow);
						$('#'+thirdname).html('&nbsp;&nbsp;'+nowpage+': '+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
						$('#'+thirdname).append(prevpage+': '+mynow_explain);
						$('#'+secondname).fadeIn("slow");
						});
							break
							}

					
							timer=setTimeout(autoprev,newsspeed,active);
					});

//////////////////////////Pause Click//////////////////////////////////////////////////////////////
					$('#'+fourthname+' img:eq(1)').click(function(){
							$(this).attr({src:'js/easynews/pause0.gif'});
						$('#'+fourthname+' img:eq(2)').attr({src:'js/easynews/next.gif'});
						$('#'+fourthname+' img:eq(0)').attr({src:'js/easynews/prev.gif'});
							clearTimeout(timer);
						});
//////////////////////////Hover (Pause)//////////////////////////////////////////////////////////////
					$('#'+secondname).hover(function(){
						clearTimeout(timer);
						activechk=$('#'+fourthname+' img:eq(2)').attr('src');
						activechkmore=$('#'+fourthname+' img:eq(0)').attr('src');	
						$('#'+fourthname+' img:eq(1)').attr({src:'js/easynews/pause0.gif'});
						$('#'+fourthname+' img:eq(2)').attr({src:'js/easynews/next.gif'});
						$('#'+fourthname+' img:eq(0)').attr({src:'js/easynews/prev.gif'});
							},function(){
						$('#'+fourthname+' img:eq(1)').attr({src:'js/easynews/pause.gif'});
						if (activechk=='next.gif' && activechkmore=='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);}
					});
//////////////////////////Addtion Function//////////////////////////////////////////////////////////////
					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); 
						} 

//////////////////////////Auto Next//////////////////////////////////////////////////////////////
					function autonext(q){
						if (!q){q=0;}
							myend=$('#'+firstname+' .news_hide_style').size();
							myend=myend-1;
							if (q = myend){q=0;}
								$('#'+fourthname+' img:eq(2)').eq(q).click();
								q=q+1;					
					}
//////////////////////////Auto Prev//////////////////////////////////////////////////////////////
					function autoprev(q){
						if (!q){q=0;}
							myend=$(".news_hide_style").size();
							myend=myend-1;
							if (q = myend){q=0;}
								$('#'+fourthname+' img:eq(0)').eq(q).click();
								q=q+1;					
					}
//////////////////////////Init AutoPlay//////////////////////////////////////////////////////////////
					timer=setTimeout(autonext,newsspeed,1);


}
});