function buttonsOff(){
	$("#pager_control").children().each(
		function() {
			var $child = $(this);
			$child.removeClass("on");
			$child.addClass("off");
		}
	);
}
	
function buttonOn(theBtn){
	buttonsOff();
	theBtn.removeClass("off");
	theBtn.addClass("on");
}

function onChange(curr,next,opts,blah) { 
	var slideIndex = opts.currSlide;
	var buttonIndex = slideIndex+1;
	buttonOn($("#pager_control div:nth-child("+buttonIndex+")"));
	
}

$(document).ready(function() {
	
	window.onload = function() {
		var totalItems = $("#image_cycle > img").length;
		for(var i=0;i<totalItems;i++){
			if(i==0){
				$("#pager_control").append('<div class="pager_button on"></div>');
			} else {
				$("#pager_control").append('<div class="pager_button off"></div>');
			}
		
		}
	}
	
	$('#image_cycle').cycle({ 
		fx:     'fade', 
		speed:   1000, 
		timeout: 5000,
		pause:1,
		cleartypeNoBg: true
	});
	
	$('#text_cycle').cycle ({
		fx:'fade',
		speed:1000,
		timeout:5000,
		cleartypeNoBg: true,
		after:onChange
		
	});
	
	$(".pager_button.off").live("click",function(){
		buttonOn($(this));
		$("#image_cycle").cycle($(this).index());
		$("#text_cycle").cycle($(this).index());
		
		$("#image_cycle").cycle("pause");
		$("#text_cycle").cycle("pause");
		
	});
	
	
});

