jQuery.fn.rotateBanners = function(config) {
	config = jQuery.extend({
		rotateTimeout : 10000,
		rotationSpeed : 1000
	}, config);
	this.each(function(i,ul) {
		jUl = jQuery(ul);
		if(!jUl.is('ul.banners')) return;
		var currentPosition = 1;
		var totalBanners = jUl.find('li.banner').length;
		var allBanners = jUl.find('li.banner embed');
		if(allBanners.length) {
			allBanners.each(function(i,b) {
				b.bannerDuration = parseFloat(b.getAttribute('banner_duration'));
			});
		} else {
			allBanners = jUl.find('li.banner object');
			var durationParams = jUl.find('param[name=banner_duration]');
			allBanners.each(function(i,b) {
				b.bannerDuration = durationParams[i].getAttribute('value');
			});
		}
		if(totalBanners <= 0) return;
		if(ul._rotateTimeout != -1) clearTimeout(ul._rotateTimeout);
		var bannerHeight = jUl.find('li.banner:first').height();
		
			
		var rotate = function () {
			if(currentPosition == totalBanners) {
				if(allBanners[0].bannerDuration) {
					allBanners[0].Rewind();
					allBanners[0].Play();
				}
			} 
			if(allBanners[currentPosition].bannerDuration) {
				allBanners[currentPosition].Rewind();
				allBanners[currentPosition].Play();
			}
			var timeout = parseFloat(allBanners[currentPosition].bannerDuration) * 1000;
			jUl.animate(
				{scrollTop: currentPosition * bannerHeight}
				,config.rotationSpeed
				,function() {
					currentPosition++;
					if(currentPosition == totalBanners) {
						currentPosition = 1;
						jUl.scrollTop(0);
					}
				}
			);

			ul._rotateTimeout = setTimeout(rotate, timeout || config.rotateTimeout)
		}
		ul._rotateTimeout = setTimeout(rotate, parseFloat(allBanners[0].bannerDuration) * 1000 || config.rotateTimeout)
		
	});
	return this;
}


/*

	----------------------------------------------------------------------------------------------------
	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( "" ) );
//		
//	}
//};
