
$(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()
	});
	
	//Toggle display for iContent boxes
	$('.icontent .item .head .button').bind('click', function(){
		$(this).parents('.item').children('.text').toggle()
	});
	
	$('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');
		
	})

	//Services box Open/close functionality
	if( $('.e_sidebar .e_services').length ){
		
		//captures subsiteid from url
		var url = window.location.toString()
		var subsiteId;
		url.replace(/(subsite=([^\&]+)|node=A([^B\&]+))/ig, function(){
			subsiteId = arguments[2] || arguments[3];
		});
		
		$('#collection').find('LI#li-' + subsiteId).addClass('selected')
		
		
		$('.e_sidebar .e_services .e_head .e_right div').bind('mouseenter', function(){
			$(this).parents('.e_services')
			.addClass('e_on')
			.one('mouseleave', function(){
				$(this).removeClass('e_on')
			})
		})
		
	}
	
	
	
	//Search button hover effect
	$("#searchstringForm .submit").hover(
		function(){
			$(this).addClass("shade-s-yellow");
			$(this).removeClass("shade-r-s-yellow");
		},
		function(){
			$(this).addClass("shade-r-s-yellow");
			$(this).removeClass("shade-s-yellow");
		}
	)
	
	
	
	/*****************************************************
	 * 
	 * Where: 			View page "basketSelectFirms.cfm"
	 * What: 			Lawfirm selection and More info 
	 * 					show/hide functionality.
	 * Created:			KA 13 May 2008
	 * Last changed: 	KA 13 May 2008
	 * 
	 * 
	 * Comments:
	 * 
	 * KA 13 May 2008 - Really need to find a better and 
	 * more efficient way off doing this with jQuery.
	 *  
	 *****************************************************/

	//First hide the lawfirms that aren't checked
	$('.ele-basketSelectFirms .e_product .e_lawfirm INPUT[type=radio]').not(':checked').parent().hide()
	
	
	//Bind click event to the "Change button"
	$('.ele-basketSelectFirms .e_products .e_changeLawfirm').show()
	.find('.e_change').show().bind('click', function(){
		
		//Get Radios
		var radios = $(this).parents('.e_product').find('.e_lawfirm INPUT[type=radio]');
		
		//Show the hidden radio's
		radios.not(':checked').parent().show()
		
		//Change the "Change" button to "Ok" and bind the "Click" functionality
		$(this).hide()
	})
	
	//More info functionality
	$('.ele-basketSelectFirms .e_lawfirm .e_chunk4').show()
	.find('A.e_moreInfo').bind('click', function(){
		$(this).find('.e_less').toggle()
		$(this).find('.e_more').toggle()
		$(this).parents('.e_lawfirm').find('.e_desc').toggle()		
		
	})
	.find('.e_less').hide()
	
	$('.ele-basketSelectFirms .e_lawfirm .e_desc').hide()
	
	
	
	
	/*****************************************************
	 * 
	 * Where: 			View page "basketFirmRule2.cfm"
	 * What: 			Validation
	 * Created:			KA 13 May 2008
	 * Last changed: 	KA 13 May 2008
	 * 
	 * Comments:
	 * 
	 *****************************************************/
	
	$('.ele-basketFirmRule2 .e_nav FORM').bind('submit', function(){
		var acceptTerms = $(this).find('.e_acceptTerms');
		
		if( !acceptTerms.length || acceptTerms.find('.e_acceptCheckbox').is(':checked') ){
			return true
		}else{
			alert("You need to accept the terms & conditions");
			acceptTerms.addClass('e_validationError')
			return false;
			
		}
	})
	
	
	/*****************************************************
	 * 
	 * 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();

});

$(window).load(function(){
	$("#e_page:not(.ele-subsite) .lawguide:first .content").slideDown("slow");
	
})

function notReady(){
	alert("not ready yet..")
}
