$(document).ready(function(){
	// menu
	$("ul.sf-menu").superfish();
	
	// slide | easeOutBounce | easeOutQuad | 
	$("#accordion").accordion({ header: "h3", animated:"slide",fillSpace:true,change:onAccordionChange});
	
	// news
	try {
		$('#news-scroller').wslide({
			width: 270,
			height: 90,
			duration: 400
		});
	} catch (e) {
		// do nothing
	}
	
	// billboards
	loadBillboards();
});

function loadBillboards(id){
	// default billboard
	var billboardId = "billboards-healthcare";
	var children = [];	
	
	// if a billboard id was passed
	if(id){
		billboardId = id;
	}
	
	// the children of this billboard
	children = $("#" + billboardId + "> div");
	
	// create the cycle plugin
	$("#" + billboardId).cycle({
		fx: "fade",
		speed: 2000,
		timeout:6000,
		pager: "#bbnav-pages",
		next: "#bbnav-next",
		prev: "#bbnav-previous"
	});	

	/*
	 * We have the id of the billboard we need to load
	 * make sure we have more than 1 image, if not there is no reason to show the paging toolbar
	 */	 
	if(children.length > 1){
		$("#bbnav-container").show();
	} else {
		$("#bbnav-container").hide();
	}
	
	// event listeners for our other buttons
	$("#bbnav-previous").click(previous);
	$("#bbnav-pause").click(pause);
	$("#bbnav-play").click(play);		
	$("#bbnav-next").click(next);		
}
function pause(){
	$(".billboards").cycle('pause');
	$("#bbnav-pause").toggle();
	$("#bbnav-play").toggle();
}
function play(){
	$(".billboards").cycle('resume');
	$("#bbnav-play").toggle();	
	$("#bbnav-pause").toggle();
}	
function next(){
	$(".billboards").cycle('pause');
}
function previous(){
	$(".billboards").cycle('pause');
}

function onAccordionChange(event,ui){
	var solutionsId = ui.newHeader[0].id;
	var id = solutionsId.split("-")[1];
	swapBillboards(id);
}

/*
 * 
 * this function will run when a new navigation item is selected from the accordion menu
 * the purpose to hide the non active billboard sets and show this one
 */
function swapBillboards(billboard){
	var id = billboard;
	// hide all of the billboards
	$(".billboards").hide();
	// show the current billboard set
	$("#billboards-" + id).show();
	// remove the page numbers so when it reloads it can recalcuate it
	$("#bbnav-pages").empty();
	//reload billboards
	loadBillboards("billboards-" + id);
}


