$(document).ready(function () {
	
	$('#advancedSearch').click(function(){
		
		if ($('#extraSearchOptions').css('display') == 'none'){
			$('#advancedSearch img').attr('src', '/images/small-minus-ms.gif');
		} else {
			$('#advancedSearch img').attr('src', '/images/small-plus-ms.gif')
		}
		$('#extraSearchOptions').slideToggle(700, 'easeOutExpo');
	});
	

	$('.lowerRads').click(function(){
		$(this).children("input:radio").attr("checked",true);
		$("input[name='SortBy']").parent().removeClass('lowerRadSelected');
		$("input[name='SortBy']:checked").parent().addClass('lowerRadSelected');
		
	});
	
	$('#searchLink').click(function(){
		SubmitQueryForm();
	});
	
	$('#frmSearch select').change(function(){
		if($(this).attr('id') == 'ManufacturerId'){
			clearmodel();
			showCustomer(true);
		} else {
			showCustomer(true);
		}
	});
	
	$('.searchType').click(function(){
		
		checkVal = $(this).attr('id');
		var currentClasses = $(this).attr('class');
		if(currentClasses.indexOf('searchTypeSelected') > -1){
			$(this).removeClass('searchTypeSelected');
			checkVal = "None";
		} else {
			$('.searchType').removeClass('searchTypeSelected');
			$(this).addClass('searchTypeSelected')
		}
		
		if(checkVal == "New"){
			$("select[name='ConditionId']").val('2');
			$("select[name='BodyTypeId']").val('-1');
			showCustomer(true);
		}
		if(checkVal == "Used"){
			$("select[name='ConditionId']").val('1');
			$("select[name='BodyTypeId']").val('-1');
			showCustomer(true);
		}
		if(checkVal == "Vans"){
			$("select[name='BodyTypeId']").val('1');
			$("select[name='ConditionId']").val('-1');
			showCustomer(true);
		}
		if(checkVal == "None"){
			$("select[name='BodyTypeId']").val('-1');
			$("select[name='ConditionId']").val('-1');
			showCustomer(true);
		}
	});
	
	showCustomer(true,-1,138);
	
	$('#lnkPriceSearch').click(function(){
		if($(this).hasClass('selected')){
			// do nothing
		} else {
			$('#lnkBudgetSearch').removeClass('selected');
			$(this).addClass('selected');
			$('#budgetSearch').fadeOut('slow',function(){
				$('#priceSearch').fadeIn('fast');
			});
			$('#advancedSearch').fadeIn('slow');
			$("#frmSearch input[name='PaymentRangeFrom']").val('-1');
			$("#frmSearch select[name='PaymentRangeTo'] option[value=-1]").attr("selected", "selected");
		}
	});
	
	$('#lnkBudgetSearch').click(function(){
		if($(this).hasClass('selected')){
			// do nothing
		} else {
			if ($('#extraSearchOptions').css('display') == 'block'){
				$('#advancedSearch img').attr('src', '/images/small-plus-ms.gif')
				$('#extraSearchOptions').slideToggle(700, 'easeOutExpo');
			}
			$('#lnkPriceSearch').removeClass('selected');
			$(this).addClass('selected');
			$("#frmSearch input[name='PaymentRangeFrom']").val('0');
			$('#priceSearch').fadeOut('slow',function(){
				$('#budgetSearch').fadeIn('fast');
			});
			$('#advancedSearch').fadeOut('slow');
			$("#frmSearch select[name='MinPrice'] option[value=0]").attr("selected", "selected");
			$("#frmSearch select[name='MaxPrice'] option[value=10000000]").attr("selected", "selected");
			showCustomer(true,-1,138);
		}
	});
	
	
});
