jQuery(function ($) {

	var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
	$('form.contact_us input[type="text"]').each(function () {
		var f = $(this),
		    lbl = $(this).parent().find('label[for="'+f.attr('id')+'"]');
		    title = lbl.text();
		lbl.remove();
		f.addClass('fresh')
		 .val(title)
		 .data('title', title)
		 .focus(function () { 
			if ($(this).val() != $(this).data('title')) return; 
			$(this).val('').addClass('focused').removeClass('fresh'); 
		  })
		 .blur(function () {
			if ($(this).val() == '') {
				$(this).val($(this).data('title')).addClass('fresh').removeClass('focused'); 
			}
		 });
	});
	
	$('form.contact_us').submit(function () {
		$(this).find('input[type="text"]').each(function () {
			if ($(this).data('title') == $(this).val()) $(this).val('');	
		});
		return true;
	});

	$('#apply-now, .apply-now').click(function () {

		if (mobile) { window.location = "http://attorneylending.com/apply-now/"; }
		var x = .80 * $(window).height();
		x = (x > 1100)? 1100 : x; 
		$.modal('<iframe class="aniframe" src="/apply-now/" height="'+x+'" width="600" style="border:0" scrolling="yes" horizontalscrolling="no" verticalscrolling="yes">', {
		closeHTML: '<a class="modalCloseImg"></a>',
		overlayClose:true
		});
	});
	$('#contact-us, .contact-us').click(function () {
		if (mobile) { window.location = "http://attorneylending.com/contact-us/"; }
		var x = .80 * $(window).height(); 
		x = (x > 700)? 700 : x;
		$.modal('<iframe src="/contact-us/" height="'+x+'" width="600" style="border:0" scrolling="yes" horizontalscrolling="no" verticalscrolling="yes">', {
		closeHTML: '<a class="modalCloseImg"></a>',
		overlayClose:true
		});
	});

	$('#preferred-method').change(function() {
		$(".opt1").hide();
		$("#"+ $(this).val() ).show();
	});
	
	$('#newsletter-btn').click(function() {
		$.modal('<iframe src="/newsletter/" height="420" width="595" style="border:0" scrolling="yes" horizontalscrolling="no" verticalscrolling="yes">', {
                closeHTML: '<a class="modalCloseImg"></a>',
                overlayClose:true
                });
	});

	$(document).ready( function() {
		var n = Math.floor(Math.random()*5) +1;
            	$('.advanced-recent-posts li:nth-child('+n+')').show();
	});

});

