/*

	----------------------------------------------------------------------------------------------------
	Accessible News Slider
	----------------------------------------------------------------------------------------------------
	
	Author:
	Brian Reindel
	
	Author URL:
	http://blog.reindel.com

	License:
	Unrestricted. This script is free for both personal and commercial use.

*/
function autoRotate(nTimeInterval)
{
	jQuery("#banners_container .next a").click();
	setTimeout("autoRotate("+nTimeInterval+");",nTimeInterval);
}
function OnResizeDocument () {
				
				obj = document.getElementById("test"); 
				obj.style.left = (document.getElementsByTagName('body')[0].clientWidth)/2 - 370;
				viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
				var obj = document.getElementById("test"); 
				obj.style.left = viewportwidth/2 - 370;
			}


jQuery.fn.accessNews = function( settings ) {
	settings = jQuery.extend({
        headline : "Top Stories",
        speed : "normal",
		slideBy : 1
    }, settings);
    return this.each(function() {
		jQuery.fn.accessNews.run( jQuery( this ), settings );
    });
};
jQuery.fn.accessNews.run = function( jQuerythis, settings ) {
	settings.slideBy = 1;
	//jQuery( ".javascript_css", jQuerythis ).css( "display", "none" );
	var ul = jQuery( "ul:eq(0)", jQuerythis );
	var li = ul.children();
	var liWidth = jQuery( li[0] ).width();
	var active = Math.floor(li.length / 2);
	var baseLeft = parseInt( ul.css( "left" ));
	ul.css('left', baseLeft - liWidth * active);
	var currentLi = jQuery( "ul li:eq("+active+")",jQuerythis);
	
	currentLi.addClass('current');
	if ( li.length > settings.slideBy ) {
		var jQuerynext = jQuery( ".next > a", jQuerythis );
		var jQueryback = jQuery( ".back > a", jQuerythis );
		var animating = false;
		ul.css( "width", ( li.length * liWidth ) );
		jQuerynext.click(function() {
			if ( !animating ) {
				animating = true;
				offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
				if ( offsetLeft + ul.width() > 0 ) {
					// Angel Current Banner
					active = active == li.length-1 ? 0 : active + 1;
					var currentLi = jQuery( "ul li:eq("+ active +")" ,jQuerythis);
					li.removeClass('current');
					currentLi.addClass('current');
					// end
					//jQueryback.css( "display", "block" );
					ul.animate(
						{
							left: offsetLeft
						},
						settings.speed, 
						function() {
							if ( parseInt( ul.css( "left" ) ) - baseLeft + ul.width() <= liWidth * 2 ) {
								ul.css( "left" , baseLeft - liWidth * 2 );
								jQuery('ul li:eq('+ 2 +')', jQuerythis).addClass('current');
								currentLi.removeClass('current');
								active = 2;
							}
							animating = false;
						}
					);
				} else {
					animating = false;
				}
			}
			return false;
		});
		jQueryback.click(function() {
			if ( !animating ) {
				animating = true;
				offsetRight = parseInt( ul.css( "left" ) ) + ( liWidth * settings.slideBy );
				if ( offsetRight + ul.width() <= ul.width() ) {
					
					// Angel Current Banner
					active = active == 0 ? li.length-1 : active - 1;
					var currentLi = jQuery( "ul li:eq("+ active +")",jQuerythis);
					li.removeClass('current');
					currentLi.addClass('current');
					// end

					//jQuerynext.css( "display", "block" );
					ul.animate(
						{
							left: offsetRight
						}, 
						settings.speed, 
						function() {
							if ( parseInt( ul.css( "left" ) ) >= baseLeft - liWidth * 1 ) {
								ul.css( "left" , baseLeft - liWidth * ( li.length- 1 - 2 ) );
								jQuery('ul li:eq('+( li.length - 1 - 2 )+')',jQuerythis).addClass('current');
								currentLi.removeClass('current');
								active = li.length - 1 - 2;
							}
							animating = false;
						}
					);
				} else {
					animating = false;
				}
			}
			return false;
		});
		jQueryback.css( "display", "block" )
		jQuerynext.css( "display", "block" )
			.parent().after( [ ].join( "" ) );
//		jQuery( ".view_all > a, .skip_to_news > a", jQuerythis ).click(function() {
//			var skip_to_news = ( jQuery( this ).html() == "Skip to News" );
//			if ( jQuery( this ).html() == "view all" || skip_to_news ) {
//				ul.css( "width", "auto" ).css( "left", "0" );
//				jQuerynext.css( "display", "none" );
//				jQueryback.css( "display", "none" );
//				if ( !skip_to_news ) {
//					jQuery( this ).html( "view less" );
//				}
//			} else {
//				if ( !skip_to_news ) {
//					jQuery( this ).html( "view all" );
//				}
//				ul.css( "width", ( li.length * liWidth ) );
//				jQuerynext.css( "display", "block" );
//			}
//			return false;
//		});
		
	}
};