// JavaScript Document

	
$(document).ready(function() {

//  loan options
//	$(" .option-title:first").addClass("active");
//	$(" .option-detail").not(":first").hide();

//	$(" .option-title:first").addClass("active");
	$(" .option-detail").hide();

	$(" .option-title").click(function(){
		$(this).next(".option-detail").slideToggle("slow")
		.siblings(" .option-detail:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings(" .option-detail").removeClass("active");
	});
	
	
		//accordion two
//	$(" .question:first").addClass("active");
//	$(" .answer").not(":first").hide();

//	$(" .question:first").addClass("active");
	$(" .answer").hide();
	
	


	$(" .question").click(function(){
		$(this).next(".answer").slideToggle("slow")
		.siblings(" .answer:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings(".answer").removeClass("active");
	});
	
	
	if (window.location.hash) {
		$("a[name="+window.location.hash.replace("#","")+"]").next(".question").trigger('click');
		$("a[name="+window.location.hash.replace("#","")+"]").next(".option-title").trigger('click');
	}
	
	//$("#hp_anchors a").click(function() {
//		var anchorname = $(this).attr("href").split("#");
//		//alert(anchorname[1]);
//		$("a[name=" + anchorname[1] + "]").next(".question").trigger('click');
//		$("a[name=" + anchorname[1] + "]").next(".option-title").trigger('click');
//	});
	
	$("a").click(function() {
		var anchorname = $(this).attr("href").split("#");
		//alert(anchorname[1]);
		$("a[name=" + anchorname[1] + "]").next(".question").trigger('click');
		$("a[name=" + anchorname[1] + "]").next(".option-title").trigger('click');
	});
	
	$('#home_banners').cycle({ 
    fx:     'fade', 
    speed:  'fast', 
    timeout: 10000, 
     
    // callback fn that creates a thumbnail to use as pager anchor 
   
	});



	$("input").click(function() {
		var  initialval =  $(this).attr("default");
		if ($(this).val()==initialval)
			$(this).val("");
	});
	$("input").blur(function() {
		var initialval =  $(this).attr("default");
		if ($(this).val()=="")
			$(this).val(initialval);
	});
	
	$("#logo").click (function() { window.location = "http://www.theukloanshop.co.uk/"; });
	

	// form handling
	          
			var callback = { 
				success:   showResponse,  // post-submit callback 
				dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
			}; 
			
			var dm_application = { 
				success:   doRedirect,  // post-submit callback 
				dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
			}; 

			 var redirect = { 
				success:   doRedirect,  // post-submit callback 		 
				dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
			}; 
	
			function showResponse(responseText, statusText, xhr, $form)  { 			 
				$(responseText.div).replaceWith("<p>"+responseText.response+"</p>");		
			} 
			
			function doRedirect(responseText, statusText, xhr, $form)  { 	
				if (responseText.response.search(/unsecured/i) > 0) {
					window.open(responseText.response,'mywindow') ;
				}
				else {
				window.location=responseText.response;
				}
			} 
			
			$('#dm_appform').ajaxForm(function(dm_application) {});	
            $('#apply_online').ajaxForm(function(redirect) {});			
			$('#request_callback').ajaxForm(function(callback) {});

			$("#btn_applyonline").click(function()  { $("#apply_online").ajaxSubmit(redirect); return false;});
			$("#btn_callback").click(function() 	{ $("#request_callback").ajaxSubmit(callback); return false; });
			$('#btn_dm_confirm').click(function() 	{ if (fncValidateForm(this)) { $("#dm_appform").ajaxSubmit(redirect); return false; }});
			


});
