// Easy News - jQuery plugin for News Slide by Michael Lo
// http://www.ezjquery.com
// 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.noConflict();
(function(jQuery) {
jQuery.extend({
init_plus: function(option){

 option = jQuery.extend({
    firstname:"",
	secondname:"",
	thirdname:"",
	fourthname:"",
	playingtitle:"Actuellement:",
	nexttitle:"Photo suivante:",
	prevtitle:"Photo précédente:",
	news_prev:"news_prev",
	newsspeed:6000,
	isauto:1,
	imagedir:"./images/easynews/",
	newscountname:"",
	disablenewscount:false
  }, option);
	
	var firstname=option.firstname;
	var secondname=option.secondname;
	var thirdname=option.thirdname;
	var fourthname=option.fourthname;
	var newsspeed=option.newsspeed;
	var isauto=option.isauto;
	var playingtitle=option.playingtitle;
	var nexttitle=option.nexttitle;
	var prevtitle=option.prevtitle;
	var news_prev=option.news_prev;
	var news_pause=option.news_pause;
	var news_next=option.news_next;
	var imagedir=option.imagedir;
	var newscountname=option.newscountname;
	var disablenewscount=option.disablenewscount;
	if (newscountname){var news_sp=1;}if (disablenewscount===true){var news_dis=1;}
	var myprevimg=jQuery('#'+news_prev).attr('src'); if (!myprevimg){myprevimg=imagedir+'prev.gif';}
	var mynextimg=jQuery('#'+news_next).attr('src'); if (!mynextimg){mynextimg=imagedir+'next.gif';}
	var mypauseimg=jQuery('#'+news_pause).attr('src'); if (!mypauseimg){mypauseimg=imagedir+'pause.gif';}

	var myprevimg0=jQuery('#'+news_prev+'0').attr('src'); if (!myprevimg0){myprevimg0=imagedir+'prev0.gif';}
	var mynextimg0=jQuery('#'+news_next+'0').attr('src'); if (!mynextimg0){mynextimg0=imagedir+'next0.gif';}
	var mypauseimg0=jQuery('#'+news_pause+'0').attr('src'); if (!mypauseimg0){mypauseimg0=imagedir+'pause0.gif';}


	var activechk,activechkmore,mysize,myfirst,myfirst_explain,active,timer;
			mysize=jQuery('#'+firstname+' .news_style').size();
			myfirst=jQuery('#'+firstname+' .news_style').eq(0).html();
			myfirst_explain=jQuery('#'+firstname+' .news_style').eq(1).attr('title');
			active=0;
								jQuery('#'+secondname).append('<table border=0 id=mm'+firstname+' class=news_move cellspacing="0" cellpadding="0"><tr id=insidetr'+secondname+'></tr></table>');
								jQuery('#insidetr'+secondname).append('<td class=mytable id='+secondname+active+'>'+myfirst+'</td>');
								
								if (news_sp===1 && news_dis!=1)
				{jQuery('#'+newscountname).html('1/'+mysize);}
				if (news_sp!=1 && news_dis!=1){jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+'1/'+mysize+'&nbsp;&nbsp;<br>');}
				jQuery('#'+thirdname).append(nexttitle+myfirst_explain);




								//jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+'1/'+mysize+'&nbsp;&nbsp;<br>');
									//jQuery('#'+thirdname).append(nexttitle+myfirst_explain);

/////////////////////////////////////////Next Click////////////////////////////////////////////////////////////////////////////////
								jQuery('#'+fourthname+' #'+news_next).click(function(){
									clearTimeout(timer);
									jQuery(this).attr({src:mynextimg0});
									jQuery('#'+fourthname+' #'+news_prev).attr({src:myprevimg});
									jQuery('#'+fourthname+' #'+news_pause).attr({src:mypauseimg});
									var need_to_delete='#'+secondname+active;
									active=active+1;
									if (active==mysize)
									{active=0;}
									var mynum=active+1;
									var nextnum=mynum;
								var temp=jQuery('#'+firstname+' .news_style').eq(active).html();
								if (nextnum==mysize){nextnum=0;}
								var mynow_explain=jQuery('#'+firstname+' .news_style').eq(nextnum).attr('title');
								jQuery('#insidetr'+secondname).append('<td class=mytable id='+secondname+active+'>'+temp+'</td>');
								
								//jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
								//jQuery('#'+thirdname).append(nexttitle+mynow_explain);
								if (news_sp===1 && news_dis!=1)
				{jQuery('#'+newscountname).html(mynum+'/'+mysize);jQuery('#'+thirdname).html(nexttitle+mynow_explain);}				
				if (news_sp!=1 && news_dis!=1){jQuery('#'+thirdname).empty().html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');jQuery('#'+thirdname).append(nexttitle+mynow_explain);}				
				if (news_dis===1)
				{jQuery('#'+thirdname).html(nexttitle+mynow_explain);}	
								
								var whatdist=jQuery('#'+secondname+active).css("width");
								whatdist=parseInt(whatdist,10);
								jQuery('#mm'+firstname).animate({left:-whatdist},1000,function(){
								jQuery(need_to_delete).remove();
								jQuery('#mm'+firstname).css({left:'0'});								
									
								});
								if (isauto==1)
								{
									timer=setTimeout(autonext,newsspeed,active);
								}
								

								});
/////////////////////////////////////////prev click///////////////////////////////////////////////////////////////////////////////////
								jQuery('#'+fourthname+' #'+news_prev).click(function(){
									clearTimeout(timer);
									jQuery(this).attr({src:myprevimg0});
									jQuery('#'+fourthname+' #'+news_next).attr({src:mynextimg});
									jQuery('#'+fourthname+' #'+news_pause).attr({src:mypauseimg});
									var need_to_delete='#'+secondname+active;
									active=active-1;
					if (active<0){active=mysize-1;}
						var mynum=active+1;
						var myprevnum=mynum-2;
					if (myprevnum<0){myprevnum=mysize-1;}							
									
								var temp=jQuery('#'+firstname+' .news_style').eq(active).html();
								var mynow_explain=jQuery('#'+firstname+' .news_style').eq(myprevnum).attr('title');
								jQuery('#insidetr'+secondname).prepend('<td class=mytable id='+secondname+active+'>'+temp+'</td>');
								var whatdist=jQuery('#'+secondname+active).css("width");
								whatdist=parseInt(whatdist,10);
								jQuery('#mm'+firstname).css({left:-whatdist});
								
								//jQuery('#'+thirdname).html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');
								//jQuery('#'+thirdname).append(prevtitle+mynow_explain);
								if (news_sp===1 && news_dis!=1)
				{jQuery('#'+newscountname).html(mynum+'/'+mysize);jQuery('#'+thirdname).html(prevtitle+mynow_explain);}				
				if (news_sp!=1 && news_dis!=1){jQuery('#'+thirdname).empty().html('&nbsp;&nbsp;'+playingtitle+''+mynum+'/'+mysize+'&nbsp;&nbsp;<br>');jQuery('#'+thirdname).append(prevtitle+mynow_explain);}				
				if (news_dis===1)
				{jQuery('#'+thirdname).html(prevtitle+mynow_explain);}

								jQuery('#mm'+firstname).animate({left:0},1000,function(){
								jQuery(need_to_delete).remove();
														
									
								});
								if (isauto==1)
								{
								timer=setTimeout(autoprev,newsspeed,active);
								}

								});
//////////////////////////Pause Click//////////////////////////////////////////////////////////////
					jQuery('#'+fourthname+' #'+news_pause).click(function(){
							jQuery(this).attr({src:mypauseimg0});
						jQuery('#'+fourthname+' #'+news_next).attr({src:mynextimg});
						jQuery('#'+fourthname+' #'+news_prev).attr({src:myprevimg});
							clearTimeout(timer);
						});
			//////////////////////////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=jQuery('#'+firstname+' .news_hide_style').size();
							myend=myend-1;
							if (q >= myend){q=0;}
								jQuery('#'+fourthname+' #'+news_next).eq(q).click();
								q=q+1;					
					}
//////////////////////////Auto Prev//////////////////////////////////////////////////////////////
					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;					
					}
//////////////////////////Init AutoPlay//////////////////////////////////////////////////////////////
if (isauto==1)
								{
					timer=setTimeout(autonext,newsspeed,1);
								}
								




}
});
})(jQuery);
