jQuery.fn.accessNews=function(settings)
{
	settings=jQuery.extend({newsHeadline:"",newsSpeed:"slow",total:0,nextlink:"",prevlink:""},settings);
	return this.each(function(i)
	{
		aNewsSlider.itemWidth=parseInt(jQuery(".item:eq("+i+")",".news_slider").css("width"))+parseInt(jQuery(".item:eq("+i+")",".news_slider").css("margin-right"));
		aNewsSlider.init(settings,this);
		/*jQuery(".view_all > a",this).click(function()
		{
			aNewsSlider.vAll(settings,this);
			return false
		})*/
	})
};

var aNewsSlider={itemWidth:0,init:function(s,p)
{
	var CurrentCounter=0;
	
	jQuery(".messaging",p).css("display","none");
	itemLength=jQuery(".item",p).length;
	/*if(jQuery(".view_all",p).width()==null)
	{
		jQuery(".news_items",p).prepend("")
	}*/
	newsContainerWidth=itemLength*aNewsSlider.itemWidth;
	jQuery(".container",p).css("width",newsContainerWidth+"px");
	if (s.total>1)
	{
		jQuery(".next",p).css("display","block");
	}
	else
	{
		jQuery(".next",p).css("display","none");
	}
	if (s.prevlink!="")
	{
		jQuery(".prev",p).css("display","block");
	}
	else
	{
		jQuery(".prev",p).css("display","none");
	}
	animating=false;
	
	var btnCounter;
	
	for (btnCounter=0;btnCounter<s.total;btnCounter++)
	{
		var BtnName="pindex_"+btnCounter;
		jQuery("#"+BtnName,jQuery.fn.accessList).click(function()
		{

			var ThisBtnIndex=this.id.substr(7,this.id.length-7);
			
			if (ThisBtnIndex>CurrentCounter)
			{
				var Diff = parseInt(ThisBtnIndex)-parseInt(CurrentCounter);

				//alert(CurrentCounter+"+"+ThisBtnIndex+"="+Diff);

				if(animating==false)
				{
					
					/* CHANGE LIST*/
					jQuery("#pindex_"+CurrentCounter).addClass("partnerOFF");
					jQuery("#pindex_"+CurrentCounter).removeClass("partnerON");
					CurrentCounter=ThisBtnIndex;
					
					jQuery("#pindex_"+CurrentCounter).addClass("partnerON");
					jQuery("#pindex_"+CurrentCounter).removeClass("partnerOFF");
					
					//----------------------------------------------------
					
					animating=true;
					animateLeft=parseInt(jQuery(".container",p).css("left"))-(aNewsSlider.itemWidth*Diff);
					if(animateLeft+parseInt(jQuery(".container",p).css("width"))>0)
					{
						jQuery(".prev",p).css("display","block");
						jQuery(".container",p).animate({left:animateLeft},s.newsSpeed,function()
						{
							jQuery(this).css("left",animateLeft);
							if(parseInt(jQuery(".container",p).css("left"))+parseInt(jQuery(".container",p).css("width"))<=aNewsSlider.itemWidth)
							{
								if (s.nextlink=="")
								{
									jQuery(".next",p).css("display","none");
								}
	
							}
							animating=false
						})
					}
					else
					{
						animating=false
					}
				}
				if(parseInt(jQuery(".container",p).css("left"))+parseInt(jQuery(".container",p).css("width"))<=aNewsSlider.itemWidth)
				{
					if (s.nextlink!="")
					{
						/*alert(s.nextlink);*/
						//window.location = s.nextlink;
					}
				}
			}
			else
			{

				if (CurrentCounter>ThisBtnIndex)
				{
					var Diff = parseInt(CurrentCounter)-parseInt(ThisBtnIndex);
					
					//alert(Diff);
					if(animating==false)
					{
						
						/* CHANGE LIST*/
						jQuery("#pindex_"+CurrentCounter).addClass("partnerOFF");
						jQuery("#pindex_"+CurrentCounter).removeClass("partnerON");
						CurrentCounter=ThisBtnIndex;
						
						jQuery("#pindex_"+CurrentCounter).addClass("partnerON");
						jQuery("#pindex_"+CurrentCounter).removeClass("partnerOFF");
						
						//----------------------------------------------------
						
						animating=true;
						animateLeft=parseInt(jQuery(".container",p).css("left"))+(aNewsSlider.itemWidth*Diff);
						if((animateLeft+parseInt(jQuery(".container",p).css("width")))<=parseInt(jQuery(".container",p).css("width")))
						{
							jQuery(".next",p).css("display","block");
							jQuery(".container",p).animate({left:animateLeft},s.newsSpeed,function(){jQuery(this).css("left",animateLeft);
							if(parseInt(jQuery(".container",p).css("left"))==0)
							{
								if (s.prevlink=="")
								{
									jQuery(".prev",p).css("display","none")
								}
							}
							animating=false
						})
					}
					else
					{
						animating=false
					}
					if((animateLeft+parseInt(jQuery(".container",p).css("width")))<=parseInt(jQuery(".container",p).css("width")))
					{
						if (s.prevlink!="")
						{
							/*alert(s.prevlink);*/
							//window.location = s.prevlink;
						}
					}
				}
			}}
	
		});
	}
	
	
	jQuery(".next",p).click(function()
	{

		if(animating==false)
		{
			/* CHANGE LIST*/
			jQuery("#pindex_"+CurrentCounter).addClass("partnerOFF");
			jQuery("#pindex_"+CurrentCounter).removeClass("partnerON");
			CurrentCounter++;
			jQuery("#pindex_"+CurrentCounter).addClass("partnerON");
			jQuery("#pindex_"+CurrentCounter).removeClass("partnerOFF");
			
			//----------------------------------------------------

			
			animating=true;
			animateLeft=parseInt(jQuery(".container",p).css("left"))-(aNewsSlider.itemWidth);
			if(animateLeft+parseInt(jQuery(".container",p).css("width"))>0)
			{
				jQuery(".prev",p).css("display","block");
				jQuery(".container",p).animate({left:animateLeft},s.newsSpeed,function()
				{
					jQuery(this).css("left",animateLeft);
					if(parseInt(jQuery(".container",p).css("left"))+parseInt(jQuery(".container",p).css("width"))<=aNewsSlider.itemWidth)
					{
						if (s.nextlink=="")
						{
							jQuery(".next",p).css("display","none");
						}
					}
					animating=false
				})
			}
			else
			{
				animating=false
			}
		}
		if(parseInt(jQuery(".container",p).css("left"))+parseInt(jQuery(".container",p).css("width"))<=aNewsSlider.itemWidth)
		{
			if (s.nextlink!="")
			{
				/*alert(s.nextlink);*/
				window.location = s.nextlink;
			}
		}

		return false
	});

		jQuery(".prev",p).click(function()
		{
			if(animating==false)
			{
				
				/* CHANGE LIST*/
				jQuery("#pindex_"+CurrentCounter).addClass("partnerOFF");
				jQuery("#pindex_"+CurrentCounter).removeClass("partnerON");
				CurrentCounter--;
				jQuery("#pindex_"+CurrentCounter).addClass("partnerON");
				jQuery("#pindex_"+CurrentCounter).removeClass("partnerOFF");
				//------------------------------------------------------------------
				
				animating=true;
				animateLeft=parseInt(jQuery(".container",p).css("left"))+(aNewsSlider.itemWidth);
				if((animateLeft+parseInt(jQuery(".container",p).css("width")))<=parseInt(jQuery(".container",p).css("width")))
				{
					jQuery(".next",p).css("display","block");
					jQuery(".container",p).animate({left:animateLeft},s.newsSpeed,function(){jQuery(this).css("left",animateLeft);
					if(parseInt(jQuery(".container",p).css("left"))==0)
					{
						if (s.prevlink=="")
						{
							jQuery(".prev",p).css("display","none")
						}
					}
					animating=false
				})
			}
			else
			{
				animating=false
			}
			if(parseInt(jQuery(".container",p).css("left"))==0)
			{
				if (s.prevlink!="")
				{
					/*alert(s.prevlink);*/
					window.location = s.prevlink;
				}
			}
		}
		return false
	})
},vAll:function(s,p)
{
	var o=p;while(p)
	{
		p=p.parentNode;
		if(jQuery(p).attr("class")!=undefined&&jQuery(p).attr("class").indexOf("news_slider")!=-1)
		{
			break
		}
	}
	/*if(jQuery(o).text().indexOf("View All")!=-1)
	{
		jQuery(".next",p).css("display","none");
		jQuery(".prev",p).css("display","none");
		jQuery(o).text("View Less");
		jQuery(".container",p).css("left","0px").css("width",aNewsSlider.itemWidth+"px")
	}
	else
	{
		jQuery(o).text("View All");*/
		aNewsSlider.init(s,p)
	//}
}};

