$(document).ready(function () {

	debug = true;

	jQuery('#headRollMenu a').each(function(){
		jQuery(this).wrapInner('<span class="state_base"></span>');
		jQuery(this).find('span').each(function(){
		 jQuery(this).clone(true).removeClass('state_base').addClass('state_over').insertAfter(jQuery(this));
		});
	});

	setActiveMenuItems();
	Cufon.replace('#headRollMenu a, h5, h1, h2, #sectionTitle');
	Cufon.replace('#sideNav a:visible, #mainMenu .dropMenu a', {
		hover: {
			color: '#7FB811'
		}
	});

	addIEclass();
	addDropTriggers();
	checkForEmpty();
	tweakSideNav();
	removeHomeLink();


	if(debug){
		jQuery('a[href=#]').addClass('noLink').attr('title','Needs link adding');
	}

});


function tweakSideNav(){
	if(jQuery('#sideNav a.rootLevel').length > 0){
		if(jQuery('#sideNav a.rootLevel').html().indexOf('&amp;') > -1 || jQuery('#sideNav a.rootLevel').html().indexOf('&') > -1 ){
			jQuery('body').addClass('bewareAmpersands');
		}
	}
}


function removeHomeLink(){
	if(jQuery('body').hasClass('home')){
		jQuery('#logo a').removeAttr('href').removeAttr('title');
	}
}


function checkForEmpty(){
	if(jQuery('#imageContainer img').length == 0){
		jQuery('#focusImage').hide();
	}
	else{
		startCycle();
	}
}


function startCycle(){
	jQuery('#imageContainer').cycle({
		fx: 'fade',
		speed:  600,
		timeout: 5000,
		random: 0
	});
}

function setActiveMenuItems(){
	var thisPage = jQuery('body').attr('class').split(' ')[0];
	var thisSection = thisPage.split('_')[0];

	// Main menu option
	jQuery('#'+tmoContainer+' #'+tmoPrefix+thisSection).removeClass(baseClass).addClass(activeClass);

	// Side Menu
	jQuery('#sideNav #sideNav_'+thisSection).show(); // Show menu section
	jQuery('#sideNav #smo_'+thisPage).addClass(activeClass); // Set active menu option
	jQuery('#sideNav a:visible:first').addClass('rootLevel').find('a').removeAttr('class'); // Add class to first menu option

}

function addIEclass(){
  if(isIE() > 0){
		jQuery('body').addClass('isIE');
		if(isIE() < 7){
			jQuery('body').addClass('isIE6');
		}
  }
	else{
		jQuery('body').addClass('isNotIE');
	}
	if(jQuery.browser.mozilla){
		jQuery('#pageBody').addClass('isMoz');
	}
}

function isIE(){
	if (jQuery.browser.msie) {
		return parseInt(jQuery.browser.version, 10);
	}
	else{
		return false;
	}
}