/*
  Custom ready function
  This should be used to reposition elements or to define and use custom functions
*/
$(document).ready(function(){

		$('.logo').append($('.byline'));
		$('.header').append($('.list'));
		$('.header').append($('.mainnav'));
		$('.content').prepend($('h2.tagline'));
		$('h2.tagline').after($('.partners'));
		$('.partners').after($('.form-block'));
		$('.content-left-interior').prepend($('.photo-interior'));
		
        $('.home_articles ul li').eq(0).prepend($('.photo.left'));
        $('.home_articles ul li').eq(1).prepend($('.photo.right'));
		
		$('.setbox').eq(0).addClass('left');
		$('.content-right .features ul li:last-child').addClass('last');
        
	  //Mortgage type select chage function
		$('select[name="PRODUCT"]').change(function(){
		  //poperty purpose
		  if($('option:selected', this).val() != 'PP_BUY_TO_LET'){
		    $('.property_purpose').show();
			$('.property_purpose select').addClass('required');
		  }else{
		    $('.property_purpose').hide();
			$('.property_purpose select').removeClass('required').val('');
		  }
		  
		  //found a home
		  if($('option:selected', this).val() == 'PP_FIRST_TIME_BUYER' || $('option:selected', this).val() == 'PP_NEXT_TIME_BUYER'){
		    $('.found_home').show();
			$('.found_home #SPEC_HOME_YES').attr('checked', 'checked');
		  }else{
		    $('.found_home').hide();
			$('.found_home input').removeAttr('checked');
		  }
		});
		
		//property val change
		/*
		  increment property value form 25000 up to 95% of estimated value
		  and append options to select
		*/
		$('#EST_VAL').change(function(){
		  //reset select
		  $('#LOAN_VAL').html('<option value="">- Select -</option>');
		  
		  //get this val
		  var est_val = $('option:selected', this).val();
		  
		  //they chose - Select -
		  if(est_val == '') return false;
		  
		  btm = 25000; //start at min amount to get a quote
		  while(btm < est_val*.95){
		    $('#LOAN_VAL').append('<option value="'+btm+'">&pound; '+btm+' ('+Math.floor((btm/est_val)*100)+'%) </option>');
			btm += 5000;
		  }
		  //calculate 95%
		  $('#LOAN_VAL').append('<option value="'+Math.floor(est_val*.95)+'">&pound; '+Math.floor(est_val*.95)+' (95%) </option>');
		  return false;
		});



});//ready



