var servicesDivs = new Array();
var sectionIds = new Array();

$(document).ready(function() {
	$('#topNavPrimary a').each(function() {
		if (this.href.split("#")[0] == document.location) {
			sectionIds.push(this.href.split("#")[1]);
			$(this).click(function() {
				var target = this.href.split('#')[1];
				$.scrollTo($('#'+target),"slow");
				return false;
			});
		}
	});
	for (var i = 0 ; i < sectionIds.length ; i++) {
		var sectionId = sectionIds[i];
		var nextSectionId = sectionIds[i+1];
		var prevSectionId = i == 0 ? "#" : sectionIds[i-1];
		var anchorNext = document.createElement('a');
		anchorNext.href = "#"+nextSectionId;
		$('#'+sectionId+' .goDownBt').wrap(anchorNext);
		$('#'+sectionId+' .goDownBt').parent().click(function() {
			var target = this.href.split('#')[1];
			$.scrollTo($('#'+target),"slow");
			return false;
		});
		var anchorPrev = document.createElement('a');
		anchorPrev.href = "#"+prevSectionId;
		$('#'+sectionId+' .goUpBt').wrap(anchorPrev);
		$('#'+sectionId+' .goUpBt').parent().click(function() {
			var target = this.href.split('#')[1];
			if (target) $.scrollTo($('#'+target),"slow");
			else $.scrollTo(document.body,"slow");
			return false;
		});
	};
	$('.service').each(function(){
		var serviceId = this.id;
		var contentDiv, titleDiv;
		$('#'+this.id+' .serviceContent').each(function(){
			contentDiv = this;
			contentDiv.id = serviceId+'Content';
		});
		$('#'+this.id+' .serviceTitle').each(function(){
			titleDiv = this;
			$(this).html("<a href=\"javascript:switchService('"+contentDiv.id+"')\">"+$(this).html()+"</a>");
		});
		servicesDivs.push(new Array(contentDiv,titleDiv));
	});
});
function switchDefinition(dt,dd,stoggle) {
	dd.slideToggle();
	dt.css("backgroundColor",stoggle ? "transparent" : "#f7f5ec");
	dd.css("backgroundColor",stoggle ? "transparent" : "#f7f5ec");
	dt.animate({
		color:stoggle ? "#605f5f" : "#3c5652",
		fontSize:stoggle ? "13px" : "15px",
		paddingTop:stoggle ? "0px" : "10px",
		paddingLeft:stoggle ? "0px" : "10px",
		paddingRight:stoggle ? "0px" : "10px"
	});
	return !stoggle;
}
function switchService(divId) {
	for (var all in servicesDivs) {
		if (servicesDivs[all][0].id != divId) {
			$(servicesDivs[all][0]).parent().removeClass("selected");
			//$(servicesDivs[all][1]).html($(servicesDivs[all][1]).html().split("On.jpg").join("Off.jpg"));
			$(servicesDivs[all][1]).find('h3').css({marginLeft:'-320px'});
		} else {
			$(servicesDivs[all][0]).parent().addClass("selected");
			//$(servicesDivs[all][1]).html($(servicesDivs[all][1]).html().split("Off.jpg").join("On.jpg"));
			$(servicesDivs[all][1]).find('h3').css({marginLeft:'0px'});
		}
	}
}
