var currentSub = null;
var futureSub = null;
var pageTitle = "";
window.addEvent('domready', function(){
	var accordion = new Accordion('h3.atStart', 'div.atStart', {
		opacity: false,
		display: null,
		onActive: function(toggler, element){
			toggler.setStyle('backgroundColor', '#f5f7f8');
			toggler.setStyle('color', '#4a4b4c');
		},
		
		onBackground: function(toggler, element){
			toggler.setStyle('backgroundColor', '#fff');
			toggler.setStyle('color', '#808181');
		}
	}, $('accordion'));	
	
	var tTip = new Tips($$('.tTip'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});	
});

function setCurrentSub(sub)
{
	currentSub = sub;
	setOnFocus(currentSub);
	// trigger flash
	if(currentSub == "ajCounselling") {
		writeCounsellingRotation();
	} else if (currentSub == "ajCoaching") {
		writeCoachingRotation();
	} else if (currentSub == "ajProfessionals") {
		writeProfessionalsRotation();
	} else if (currentSub == "ajOrganisations") {
		writeOrganisationsRotation();
	}
}

function setPageTitle(pg)
{
	pageTitle = pg;
}

function redoTTips()
{
	var tTip = new Tips($$('.tTip'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
}

function doAjax(e, future, url, blurb1, blurb2)
{
	//futureSub = e.target.id;
	futureSub = future;
	setOnFocus(futureSub);
	setLoseFocus(currentSub);
	currentSub = futureSub;
	
	// trigger flash
	if(future == "ajCounselling") {
		writeCounsellingRotation();
	} else if (future == "ajCoaching") {
		writeCoachingRotation();
	} else if (future == "ajProfessionals") {
		writeProfessionalsRotation();
	} else if (future == "ajOrganisations") {
		writeOrganisationsRotation();
	}
	
	
	
	document.getElementById("sectionBlurbLineOne").innerHTML = blurb1;
	document.getElementById("sectionBlurbLineTwo").innerHTML = blurb2;
	
	e = new Event(e).stop();
	var url = url;
	new Ajax(url, {	method: 'get', update: $('leftColumn'), onComplete: redoTTips }).request();	
	//document.location.href = "http://localhost/freelance/garrathford/services/?s=Professionals";
}

function setOnFocus(domElement)
{
	document.title = pageTitle;
	var style = document.getElementById(domElement).style;
	style.color = "#ffffff";
	style.backgroundImage = "url(../images/subFocus.gif)";
	document.title = pageTitle + " " + document.getElementById(domElement).innerHTML;
}

function setLoseFocus(domElement)
{
	var style2 = document.getElementById(domElement).style;
	style2.color = "#b0ab9b";
	style2.backgroundImage = "none";
}