$(function() {
   // handeling the search form	$('#search_form select').change( function() {		// switch keywords availibility
      if ($('#manufacturer')[0].value!='' || $('#body')[0].value!='' || $('#start_price')[0].value!='0' || $('#end_price')[0].value!='0')
         $('#keywords')[0].disabled = true;
      else $('#keywords')[0].disabled = false;
      var changed_el = this;
      $('#search_form select').not('#change_currency_select').not('#'+changed_el.name).each(function (el) {
      	   this.disabled=true;
      	   $('#'+this.name).load('inc/get_search_list.php', {      	   	manufacturer: $('#manufacturer')[0].value,
      	   	body: $('#body')[0].value,
      	   	start_price: $('#start_price')[0].value,
      	   	end_price: $('#end_price')[0].value,
      	   	get_type: this.name},
      	   	function() {      	   		this.disabled=false;
      	   		//changed_el.selected

      	   	}
      	   );
		});
	});
	//if ($('#manufacturer')[0].value!='') $('#search_form select').trigger('change');


	// dealer select
	$('#dealer_select').change( function() {		/*var url;
		url = this[this.selectedIndex].text;
		url = url.replace(/([^a-zA-Z\-])/g,'-');
		url = url.replace(/\-+/g,'-'); */
		//url = url.replace('[^a-zA-Z\-]','-');
		//url = url.replace(' ','-');
		//url = url.replace(' ','-');
		//alert(this.selectedIndex);
		if (this.selectedIndex==0) window.location = '/index.html';
	   else window.location = '/dealer_' + this[this.selectedIndex].value+'.html';
	});

	$('#change_currency_select').change( function() {      $('#change_currency')[0].value = this[this.selectedIndex].value;
      $('#form_usd').submit();
	});

	// switch betwene pages (cars list)
	function switch_to_page(page) {		$('#shadow_box').show();
		$('#cars_list_inner').load('/ajax/index.php?module=cars_list' + (page!=false ? '&page='+page : ''),
			{				'aparams': window.location.hash,
				'params' : $('#page_params').attr('value')
			},
			function() {
				$('#shadow_box').hide();
			});
	}

	$('.nav_pages').live('click',function() {
		var page = $(this).attr('num');
		document.location.href = '#p=' + page;
		return false;
	});

	// update cars list if anchor changed or was inserted
	$(window).bind('hashchange', function() {
      switch_to_page(false);
	});

	if (window.location.hash != '') {
		switch_to_page(false);
	}


	// show small image on similar cars
		$('.similar_preview').mousemove(function(event) {
			$('.img_preview').css('top', event.pageY+10).css('left', event.pageX+30);
		});
		$('.similar_preview').mouseout(function(event) {
			$('.img_preview').css('display','none');
		});
		$('.similar_preview').mouseover(function(event) {
			//alert($(this).find('input').attr('value'));
			$('.img_preview').css('display','block').html($(this).find('input').attr('value'));
		});

});
