

//Print functionality
function printContent(){
	if( $('body').hasClass('e_modalEnabled') ){
		ele.print.elem( $('.jqmWindow:visible .mdlTarget') )
	}else{
		ele.print.elem( $('.e_contentMainWrapper') )
	}
}

$(document).ready(function(){
	//Event Delegationg
	$(document).click(function(e){
		var target = $(e.target);
		
		
	})
	
	//Toggle display for Product description
	$('.products .product .info A').bind('click', function(){
		var pid = $(this).parents('.product').attr('pid');
		$('.products .desc[pid='+ pid +']').toggle()
	});
	
	//Login page error slide down
	if( $('.ele-login').length > 0 ){
		$('.ele-login .e_loginFailed').slideDown()
		$('.ele-login .e_desc').slideDown()
	}
	//Change all the href="#" to href="javascript:void(0)"
	$('a[href="#"], a[href=""]').attr('href', 'javascript:void(0)')

	//LawGuide Open/close functionality
	$("a.level3","#lawguide").bind("click",function(){
		$(".open-reminder").removeClass("open open-reminder");
		$("#lawguide-"+this.id.split("-")[1]+"-children").addClass("open-reminder").toggleClass("open")
		.parent().find("a.level3").addClass("open-reminder").toggleClass("open");
	})
	
	
	//LawGuide sub levels Open/close functionality
	$('.lawguide .l3 A.expander').bind('click', function(){
		$('.lawguide .l3 *').removeClass('on');
		$(this).siblings('.on').removeClass('on');
		$(this).parent().addClass('on');
		$(this).addClass('on').next().addClass('on');
		
	})
	
	//Some Contact form stuff
	$("#ele-customerMessageForm DIV.e_accountDetails UL LI.e_messageTextItem TEXTAREA").focus(function() { 
		if ( $(this).val().indexOf("Please enter your message here.") >= 0) { $(this).val(""); }
		$(this).addClass('e_on');
	});
	$("#ele-customerMessageForm DIV.e_accountDetails UL LI.e_messageTextItem TEXTAREA").blur(function() { 
		if ( $(this).val() == "") { $(this).val("Please enter your message here.\n\nTo submit a legal question to one of our law firms, please use the 'Find me a lawyer' feature above."); }		
		if ( $(this).val().indexOf("Please enter your message here.") >= 0) { $(this).removeClass('e_on'); }
	});
	
	$("#ele-customerMessageForm DIV.e_accountDetails UL LI.e_submit INPUT").bind("click",function(){
		var thisTextarea = $("#ele-customerMessageForm DIV.e_accountDetails UL LI.e_messageTextItem TEXTAREA");
		if ( $(thisTextarea).val().indexOf("Please enter your message here.") >= 0) { $(thisTextarea).val(""); }
	});

	//Services box Open/close functionality
	if( $('.e_sidebar .e_services').length ){
		
		//Add '.selected' class to selected L1 LI (gets subsiteId from the URL)
		var url = window.location.toString()
		//must allow format of subsite= and node=A(followed by subsiteid)
		var subsiteIndex = url.lastIndexOf('subsite=') + 8;
		if(subsiteIndex==7)
			var subsiteIndex = url.lastIndexOf('node=A') + 6;
		var subsiteId = url.substr(subsiteIndex, 5);
		$('#collection').find('LI#li-' + subsiteId).addClass('selected')
		
		
		$('.e_sidebar .e_box.e_services.e_closed').bind('mouseenter', function(){
			
			//Add 'e_on' class and a mouseLeave event (to remove the 'e_on' class) to DIV.e_right
			$(this).find('.top_content .e_right')
			.addClass('e_on')
			
			//Add 'e_on' class and a mouseLeave event (to remove the 'e_on' class) to Root element of the box

			$(this)
			.addClass('e_on')
			.one('mouseleave', function(){
				$(this).removeClass('e_on')
				$(this).find('.top_content .e_right').removeClass('e_on');
			})

		})
		
		
		//Hack: Move HIPs & conveyancing LI to inside the L1 so that the list is alphabetically correct.
		$('.e_sidebar .e_services .e_extra1').insertAfter('#collection li:eq(3)');
		$('.e_sidebar .e_services .e_extra2').insertBefore('#collection li:first');
		
	}
	
	
	/*****************************************************
	 * 
	 * Where: 			View page "basketSelectPaymentSchemes.cfm"
	 * What: 			Validation
	 * Created:			KA 14 May 2008
	 * Last changed: 	KA 14 May 2008
	 * 
	 * Comments:
	 * 
	 * KA 14 May 2008 - Need to find a consistant way to
	 * validate these basket step.
	 *****************************************************/
	 
/*
	$('.ele-basketSelectPaymentSchemes .e_paymentOptions FORM').bind('submit', function(){
		
		//var inputs = $(this).find('INPUT[name^=PaymentMethodKeySelection]');
		
		var paymentMethods = $(this).find('.e_paymentMethods');
		var errors = [];
		
		$.each(paymentMethods, function(i,e){
			
			if( $(this).find('INPUT:checked').length < 1 ){
				errors.push([ $(this), "Not selected" ])
			}
			
		})
		
		if(errors.length){
			$.each(errors, function(i,e){
				
				e[0].addClass('validationError');
				
			})
		}
		return false;
	})
*/

	/*****************************************************
	 * 
	 * Where: 			Product page (product.cfm)
	 * What: 			Show/hide Rapidocs description
	 * Created:			KA 29 May 2008
	 * Last changed: 	KA 29 May 2008
	 * 
	 * Comments:
	 * 
	 *****************************************************/
	$('.ele-product').find('.e_productObjects .e_object .e_name').bind('click', function(){
		$(this).siblings('.e_desc').toggle()
	});

	/*****************************************************
	 * 
	 * Where: 			Anywhere
	 * What: 			jqModal functionality
	 * Created:			KA 27 May 2008
	 * Last changed: 	KA 27 May 2008
	 * 
	 * Comments:
	 * Example HTML
		<div class="jqmWindow" id="dialog">
			<a href="#" class="jqmClose">Close</a>
			<hr>
			<p>Hello testing here jqModal..</p>
		</div>
	 *****************************************************/
	//Initial Dialog setup
	//$('.jqmWindow').jqm({modal:true, overlay: 75});
	
	//$('.jqmWindow').jqm({modal:true, overlay: 75}).jqmShow();
	
	//Smooth scrolling. 
	//Source: http://www.learningjquery.com/2007/09/animated-scrolling-with-jquery-12
	$('#ele-faq a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
		  var $target = $(this.hash);
		  $target = $target.length && $target
		  || $('[name=' + this.hash.slice(1) +']');
		  if ($target.length) {
			var targetOffset = $target.offset().top;
			$('html')
			.animate({scrollTop: targetOffset}, 700, 'swing', function(){  } );
		   return false;
		  }
		}
	});

});
