$(function() {
	// Headline Slider
	var h_increment = $("#headlines .group:first").width(),
		h_index = 0,
		h_next_slot = 1,
		h_speed = 1500;
	
	$.fn.cycle.transitions.scrollLeftCustom = function($cont, $slides, opts) {
		$cont.css('overflow','visible');
		opts.before.push($.fn.cycle.commonReset);
		var w = $slides.width();
		opts.cssFirst = { left: 0, display: 'block' };
		opts.cssBefore= { left: w, top: 0, display: 'block' };
		opts.animIn	  = { left: 0 };
		opts.animOut  = { left: 0-w };
	};
	
	function moveBG() {
		if (h_index > 0) {
			$("#headline-bg").animate({
				width:	(h_increment*2*h_next_slot) + $(window).width(),
				marginLeft:	-(h_increment*h_next_slot)
			}, h_speed, "easeInOutExpo");
		}
	}
	
	function checkForReset() {
		if ((h_index)%3 == 0) {
			$("#headline-bg").css({
				width: "100%",
				marginLeft: 0
			});
			h_next_slot = 1;
		} else {
			h_next_slot++;
		}
		h_index++;
	}
	
	var $pager = $('<div class="pager"></div>').insertAfter("#headlines");
	
	$("#headlines").cycle({
		fx:     'scrollLeftCustom',
		timeout:	5000,
		sync:		1,
		speed:		h_speed,
		before:		moveBG,
		after:		checkForReset,
		easing:		"easeInOutExpo",
		cleartype:	false, // White bg built into graphics instead
		cleartypeNoBg: true,
		pager:		$pager,
		pagerAnchorBuilder: function(index, slide) {
			return '<span>' + index + '</span>';
    	}
	});

/* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
**********************************************************************/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});

/*
 * TERMS OF USE - EASING EQUATIONS
 * Open source under the BSD License. 
 * Copyright å© 2001 Robert Penner
 * All rights reserved.
 */
});
