function configLawGuideMenu(){
	$("a.level2,a.level4","#lawguide").bind("click",function(){
		$("#lawguide-"+this.id.split("-")[1]+"-children").toggle();
	})
}

$(document).ready(function(){
	configLawGuideMenu();
})

// Cross browser font size adjustment
window.onload = function () {
	bodyFont ();

};


function bodyFont (){
if (navigator.userAgent.indexOf('MSIE') !=-1)
{
	window.document.body.style.fontSize = '1em';
}
};

/* ripped from Nelsons */

$(document).ready(function(){

	hideMenuDrops();
	personalDrop();
	businessDrop();
	servicesDrop();
	hideLawDrops();
	lawDropsTierOne();
	lawDropsTierTwo();
	serviceTemplatesShowHide();
	servicesArrowTick();
	rhsMenuOptions();
//	lawDropsTierThree();

	// Services functionality, currently functionality from base does not work as subsite pages do not add subsite class to body

	/*$("#services .content").hide();

	$("#services .head .right").bind("mouseenter",function(){

		$(this).addClass("on")

		.parents("#services").children(".content").slideDown(25)

		.parents("#services").one("mouseleave",function(){

			$(this).children(".content").slideUp(25)

			.children(".right").removeClass("on");

		})

	});*/



	// Colours the product lists on the subsite pages different colours, skipping hidden items

	var ColorArray = ["#8c66d5", "#ef0039", "#04a4dc", "#53bd43", "#75b7b6", "#e49554", "#a49d8b", "#cac9c7"];

	var $ProductList = $(".e_contentMainWrapper .e_wrap .services #collection ul");

	var $Products = $ProductList.children("li:visible");

	

	for(i = 0; i < $Products.length; i++) {

		var color = ColorArray[i % ColorArray.length];

		$ProductList.children("li:visible:eq("+i+")").css("background-color", color);

	}

	

	// Renames "Purchase & Sales Agreements" to "Commercial Agreements"

	$(".e_contentMainWrapper .e_wrap .services #collection li#li-76062 > a").html("Commercial agreements");

	
	
	// Expands/collapses services boxes
	


	// Expands/collapses services boxes
/*
	if (!$("body").hasClass("Home") && !$("body").hasClass("personal") && !$("body").hasClass("business")) {

		var servicesBox = $(".e_leftBar .e_services");

		servicesBox.children(".e_content").hide();

		

		servicesBox.mouseover(function(){

			$(this).children(".e_content").show().addClass("hover");

			$(this).mouseout(function(){

				$(this).children(".e_content").hide().removeClass("hover");

			})

		})

	}

	else {

		// hide the arrow

		$(".e_leftBar .e_services .e_head .e_right").hide();

	}
*/


	$("#lawguide .level2,.e_featuresRow .e_feature,.e_rightBar .e_box").mouseover(function(){

		$(this).addClass("hover");

		$(this).one("mouseleave",function(){

			$(this).removeClass("hover");

		})

	})

	

	var documentObjSelector = $(".ele-MyServices-MyDocuments .e_list .e_documents .e_document");

	var documentObjs = []

	

	for(i=0;i<documentObjSelector.length;i++){

		documentObjs[i] = new documentObj(documentObjSelector[i]);

		documentObjs[i].init();

	}

});



var documentObj = function(obj){

	var Obj = obj

	var init = function(){

		$(Obj).mouseover(function(){

			$(this).addClass("hover").one("mouseleave",function(){

				$(this).removeClass("hover");

			})

		})

	}

	return{

		init:init

	}

};



/* ------------------------------------------- */

/* ----- NELSONS SUBSCRIPTION CALCULATOR ----- */

/* ------------------------------------------- */

(function(){

	// Nelsons RPP calculation

	var nelsonsRPP=new ele.calculator(function(n){

		var a=0,idt=.05;

		if(n==0){

			return 'Please enter a value';

		}else if(n<=2000000){

			a=.165/100;

		}else if(n>2000000&&n<=2500000){

			a=.155/100;							

		}else if(n>2500000&&n<=3000000){

			a=.150/100;

		}else if(n>3000000&&n<=3500000){

			a=.135/100;							

		}else if(n>3500000&&n<=4000000){

			a=.125/100;							

		}else{

			return 'This product is limited to a payroll of a maximum of 4M GBP.';

		}

		return(2500+(n*a*(1+idt)));	

	});

	

	$(function(){	

		$("#SubscriptionCalculator .e_result").hide();

		$('#SubscriptionCalculator').show();

		// Calculate on click

		$('#SubscriptionCalculator-Calculate').click(function(){

			nelsonsRPP.calculate($('#SubscriptionCalculator-Input').val()*1);

		});

		// Display result

		nelsonsRPP.subscribe('result',function(n){

			$('#SubscriptionCalculator .e_error').hide();

			$('#SubscriptionCalculator .e_result').show();

			$('#SubscriptionCalculator-Result').text(n.toFixed(2));

		});

		// Display error

		nelsonsRPP.subscribe('error',function(n){

			$('#SubscriptionCalculator .e_error').show().text(n);

			$('#SubscriptionCalculator .e_result').hide();

			$('#SubscriptionCalculator-Result').text('');						

		});

	});



})();

/* -------------------------------------------------------- business and personal menus ------------------------------------------------------------------------- */


function hideMenuDrops() {
	/*
	if ($('body').hasClass("e_introPages")){
		$(".e_leftBar .e_business .e_content").hide();
		$(".e_leftBar .e_personal .e_content").hide();
		
		}
	*/
	if ($('body').hasClass("e_generalText")){
	$(".e_leftBar .e_business .e_content").hide();
	$(".e_leftBar .e_personal .e_content").hide();
	}
	



		
	/*
	if ($('body').hasClass("e_introPagesPersonal")){
	$(".e_leftBar .e_business .e_content").hide();
	$(".e_leftBar .e_personal .e_content").hide();
	}
	*/
	}
/*
function personalDrop() {
	
	
	$(".e_leftBar .e_personal .e_head").unbind("mouseover.personalDrop");
	$(".e_leftBar .e_personal .e_head").unbind("click.personalDrop");
	
	$(".e_leftBar .e_personal .e_head").bind("mouseover.personalDrop", function(){
		
		var businessDisplay = $(".e_leftBar .e_business .e_content").css("display");
		
		if( businessDisplay == "block") {
			$(".e_leftBar .e_business .e_content").slideUp('slow', function(){
				businessDrop();
			});
			
		}
		
		$(".e_leftBar .e_personal .e_content").slideDown('slow', function(){
			
			$(".e_leftBar .e_personal .e_head").unbind( "mouseover.personalDrop" );
			$(".e_leftBar .e_personal .e_head").unbind("click.personalDrop");
			$(".e_leftBar .e_personal .e_head").bind("click.personalDrop", function(){ 
				
				$(".e_leftBar .e_personal .e_content").slideUp('slow', function(){
					
							
							personalDrop();
						
							});
				
					});
			
			
		});
		
		
	});
	
	
	
}
	
	
function businessDrop(){


	$(".e_leftBar .e_business .e_head").unbind( "mouseover.businessDrop" );
	$(".e_leftBar .e_business .e_head").unbind( "click.businessDrop" );
	$(".e_leftBar .e_business .e_head").bind("mouseover.businessDrop", function(){
		
		var personalDisplay = $(".e_leftBar .e_personal .e_content").css("display");
		if( personalDisplay == "block") {
			$(".e_leftBar .e_personal .e_content").slideUp('slow', function(){
				personalDrop();
			});
			
		}
		
		$(".e_leftBar .e_business .e_content").slideDown('slow', function(){
			
			$(".e_leftBar .e_business .e_head").unbind( "mouseover.businessDrop" );
			$(".e_leftBar .e_business .e_head").unbind( "click.businessDrop" );
			$(".e_leftBar .e_business .e_head").bind("click.businessDrop", function(){ 
				
				$(".e_leftBar .e_business .e_content").slideUp('slow', function(){
					
								
								businessDrop();
						
							});
				
					});
			
			
		});
		
		
	});
	

	
}
*/
/* -------------------------------------------------------- generic services menu ------------------------------------------------------------------------- */

function servicesDrop(){


	$(".e_leftBar .e_servicesBox .e_head").unbind( "click.servicesDrop" );
	
	$(".e_leftBar .e_servicesBox .e_head").bind("click.servicesDrop", function(){
		
		var servicesDisplay = $(".e_leftBar .e_servicesBox .e_content").css("display");
		if( servicesDisplay == "block") {
			$(".e_leftBar .e_servicesBox .e_content").slideUp('slow');
			
		}else {
			$(".e_leftBar .e_servicesBox .e_content").slideDown('slow');
		
		}
		
	});
	
	
	
}

function personalDrop(){


	$(".e_leftBar .e_personal .e_head").unbind( "click.personalDrop" );
	
	$(".e_leftBar .e_personal .e_head").bind("click.personalDrop", function(){
		
		var personalDisplay = $(".e_leftBar .e_personal .e_content").css("display");
		if( personalDisplay == "block") {
			$(".e_leftBar .e_personal .e_content").slideUp('slow');
			
		}else {
			$(".e_leftBar .e_personal .e_content").slideDown('slow');
		
		}
		
	});
	
	
	
}

function businessDrop(){


	$(".e_leftBar .e_business .e_head").unbind( "click.businessDrop" );
	
	$(".e_leftBar .e_business .e_head").bind("click.businessDrop", function(){
		
		var businessDisplay = $(".e_leftBar .e_business .e_content").css("display");
		if( businessDisplay == "block") {
			$(".e_leftBar .e_business .e_content").slideUp('slow');
			
		}else {
			$(".e_leftBar .e_business .e_content").slideDown('slow');
		
		}
		
	});
	
	
	
}

/* -------------------------------------------------------- law guide ------------------------------------------------------------------------- */


function hideLawDrops() {
	
	$(".e_leftBar #lawguide").children('ul').children('li').children('ul').hide();
	$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('ul').hide();
//	$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('ul').children('li').children('ul').hide();

	$(".e_leftBar #lawguide").find("a.selected").parents('ul').each(function() {
		$(this).show();
		$(this).addClass('tabbed');
	});	
	
	if ($(".e_leftBar #lawguide").find("a.selected").parent('li').hasClass('level2')) {
		//alert('working');
		
		$(".e_leftBar #lawguide a.selected").css({"background-color" : "#FEF4EB"});
		$(".e_leftBar #lawguide a.selected").css({"color" : "#000000"});
		$(".e_leftBar #lawguide").find("a.selected").parent('li').children('ul').show();
		$(".e_leftBar #lawguide").find("a.selected").parent('li').children('ul').addClass('tabbed');
		//$(".e_leftBar #lawguide a.selected").parent('li').css({"display" : "block"});
		
	} 
	
	
		$(".e_leftBar #lawguide").find("a.selected").parents('ul').eq(1).parent('li').children('a').css({"background-color" : "#FEF4EB"});
		
	
	
	

	}

function lawDropsTierOne() {

	
	$(".e_leftBar #lawguide").children('ul').children('li').children('a').unbind( "mouseover.lawTierOne" );
	$(".e_leftBar #lawguide").children('ul').children('li').children('a').bind("mouseover.lawTierOne", function(){
		/*
		if( $(".e_leftBar .e_services .e_content").css("display") == "block") {
			$(".e_leftBar .e_services .e_content").slideUp('slow');
			
		}
	*/
		$(this).parent('li').children('ul').addClass("marker");

		
		
		$(".e_leftBar #lawguide").children('ul').children('li').children('ul').each(function() {
			
			if ($(this).css("display") == "block" && !$(this).hasClass("marker") && !$(this).hasClass("tabbed")) {
				
					$(this).slideUp('slow', function(){
						$(this).parent('li').children('a').css({"background-color" : "#ffffff"});
							$(this).parent('li').children('ul').children('li').children('ul').each(function() {
								$(this).hide();
							});	
									
							$(this).parent('li').children('ul').children('li').children('li').children('ul').each(function() {
								$(this).hide();
							});	
						});
				
				}
		});
		
		
		if ($(this).parent('li').children('ul').css("display") == "block") {
			
			if(!$(this).parent('li').children('ul').hasClass("tabbed")){
					$(this).parent('li').children('ul').slideUp('slow', function(){
						$(this).parent('li').children('a').css({"background-color" : "#ffffff"});
						$(this).parent('li').children('ul').children('li').children('ul').each(function() {
							$(this).hide();
						});	
								
						$(this).parent('li').children('ul').children('li').children('li').children('ul').each(function() {
							$(this).hide();
						});	
					});
			}
		} else {
			$(this).parent('li').children('ul').slideDown('slow', function(){
				
				$(this).parent('li').children('a').css({"background-color" : "#FEF4EB"});
			});
			
			
		};
		
		$(this).parent('li').children('ul').removeClass("marker");
	});
	

	}

function lawDropsTierTwo() {

	
	$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('a').unbind( "click.lawTierTwo" );
	$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('a').bind("click.lawTierTwo", function(){
	
		$(this).parent('li').children('ul').addClass("marker");

		
		
		$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('ul').each(function() {
			
			if ($(this).css("display") == "block" && !$(this).hasClass("marker") && !$(this).hasClass("tabbed")) {
				
					$(this).slideUp('slow');
				
				}
		});
		
		
		if ($(this).parent('li').children('ul').css("display") == "block") {
			
			if(!$(this).parent('li').children('ul').hasClass("tabbed")){
				$(this).parent('li').children('ul').slideUp('slow');
			}
			
		} else {
			$(this).parent('li').children('ul').slideDown('slow');
			
		};
		
		$(this).parent('li').children('ul').removeClass("marker");
	});
	

	}
/*
function lawDropsTierThree() {

	
	$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('ul').children('li').children('a').unbind( "mouseover.lawTierThree" );
	$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('ul').children('li').children('a').bind("mouseover.lawTierThree", function(){
	
		$(this).parent('li').children('ul').addClass("marker");

		
		
		$(".e_leftBar #lawguide").children('ul').children('li').children('ul').children('li').children('ul').children('li').children('ul').each(function() {
			
			if ($(this).css("display") == "block" && !$(this).hasClass("marker")) {
				
					$(this).slideUp('slow');
				
				}
		});
		
		
		if ($(this).parent('li').children('ul').css("display") == "block") {
			$(this).parent('li').children('ul').slideUp('slow');
		} else {
			$(this).parent('li').children('ul').slideDown('slow');
			
		};
		
		$(this).parent('li').children('ul').removeClass("marker");
	});
	

	}

*/

/* -------------------------------------------------------- Services templates ------------------------------------------------------------------------- */

function serviceTemplatesShowHide(){
	
	$(".myServices_templates .e_list .e_templates .e_productDetails").hide();
	
	$(".myServices_templates .e_list .e_templates .e_productHead .e_detailsToggle .e_hideLabel").hide();
	
	$(".myServices_templates .e_list .e_templates .e_detailsToggle").each(function() {
			$(this).unbind( "click.templatesOpenClose" );
			$(this).bind("click.templatesOpenClose", function(){
				//$(this).parent('ul').parent('li').children('div.e_productDetails').css({"background-color" : "#FEF4EB"});
				
				if($(this).parent('ul').parent('li').children('div.e_productDetails').css("display") == "block") {
					$(this).parent('ul').parent('li').children('.e_productDetails').hide();
					$(this).children('a').children('.e_showLabel').show();
					$(this).children('a').children('.e_hideLabel').hide();
				} else {
					
					$(this).parent('ul').parent('li').children('.e_productDetails').show();
					$(this).children('a').children('.e_showLabel').hide();
					$(this).children('a').children('.e_hideLabel').show();
				}
				
			});	
		});	
	
}

/* -------------------------------------------------------- Services arrow tick ------------------------------------------------------------------------- */


function servicesArrowTick() {
	$(".myServices_summary .e_columns .e_row2").children('td').eq(3).css({"background-image" : "url('images/icon_servicesFlowTick.gif')"});
	
}

/* -------------------------------------------------------- rhs menu ------------------------------------------------------------------------- */

function rhsMenuOptions() {
	
	$(".e_rightBar .e_menuBox .content").hide();
	
	
	
	$(".e_rightBar .e_menuBox h2").each(function() {
			$(this).unbind( "mouseover.rhsMenuHoverDown" );
			$(this).bind("mouseover.rhsMenuHoverDown", function(){
				$(this).parent('div.e_menuBox').children('div.content').addClass('rhsMenuOpen');
				setTimeout(function() {$('.e_rightBar .e_menuBox .rhsMenuOpen').show();}, 500); 
				
				
				
				
			});	
			$(this).unbind( "mouseout.rhsMenuHoverUp" );
			$(this).bind("mouseout.rhsMenuHoverUp", function(){
				$(this).parent('div.e_menuBox').children('div.content').removeClass('rhsMenuOpen');
				$(this).parent('div.e_menuBox').children('div.content').hide();
				
				
			});	
		});	
}

/* -------------------------------------------------------- temp newsletter ------------------------------------------------------------------------- */

function tempNewsletter() {
	alert('Our Newsletter service is not yet available.\n\nPlease return on your next visit to subscribe / unsubscribe.');
	
}
