// Silverstripe uses Prototype
var $j = jQuery.noConflict();

$j(document).ready(function(){
	
// Homepage Image Rotation
	if($j('#cycle').length >= 1){
		$j('#cycle') 
			.after('<div id="cycle-nav">') 
			.cycle({ 
				speed: 1000, 
				timeout: 5000, 
				pager: '#cycle-nav' ,
				pagerAnchorBuilder: onBefore
			})
		;
	}
	
	function onBefore(i, el, $p, els, opts) { 
		return '<a href="#"></a>'; 
	} 

// Homepage Awards, Clients, etc Scroller
	if($j('.scrollable').length >= 1){
		$j('.scrollable').scrollable({
			size:2,
			speed:500
		}).mousewheel(250).circular().autoscroll({
			interval: 2500
		});;
		
		$j('#slider .next').click(function(){
			return false;
		});
	
		$j('#slider .prev').click(function(){
			return false;
		})
	}
	

// Homepage Feature Links Hover Effects
// IE8 doesn't support CSS opacity so there's no fading allowed
	var ie = $j.browser.msie;
	if(!ie){
		$j('#links a').each(function(){
			var bgImg = $j(this).css('background-image');
			var bgPos = $j(this).css('background-position');
			$j(this)
				.append('<span style="background-image:' + bgImg + '; background-position:' + bgPos + ';"></span>')
				.hover(function(){
					$j(this).addClass('hover').children('span').fadeOut(250);
				},function(){
					$j(this).children('span').fadeIn(250,function(){
						$j(this).parent().removeClass('hover');
					});
				})
			;
		});
	}
/*
// Smooth Scrolling for Jump Links
	$j('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $j(this.hash);
			$target = $target.length && $target || $j('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$j('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});

*/
}); // end $j(document).ready;