jQuery.noConflict();

jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} })

jQuery.fn.replace_default = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

scrollPartsOffers = function ()
{
	jQuery("#model_latest_parts_offers").load(getPartsOfferUrl());	
	setTimeout('scrollPartsOffers()', 6000);	
}

getPartsOfferUrl = function()
{
	var intOffset = document.getElementById('so_offset').value;
	return "/ajax/parts_scroll_offers?offset=" + intOffset;
}

jQuery(document).ready(function($) {
  
	if($("#findPartForm").length)
	{
		$("#findPartForm").validate();
	}
	
	// setup suggest search.....
	
	$("#q").autocomplete("/ajax/parts_suggest", {
		width: 260,
		selectFirst: false,
		parse: function(data) { 
					return $.map(eval(data), function(row) 
						{	return { data: row, value: row.url, result: '' }
			});
		},
	    formatItem: function(item) { return item.text; }
	}).result(function(event, item) { $("#q").flushCache(); location.href = item.url; }
		);
	
  // sort the scrolling offers if applicable  
  if($("#model_latest_parts_offers").length > 0 && $("#so_offset").length > 0)
  {
	setTimeout('scrollPartsOffers();', 6000);	  
  }  
  
  $("#search input").replace_default()
  $(".search_or_continue input#q").replace_default()
  
  $("#parts_tabs").tabs({remote: true})
  
$(".collapse-me").css("position", "relative")
if(!jQuery.browser.msie) $(".collapse-me h3").css("min-height", "13px");
  $(".collapse-me h3").
    css("cursor", "pointer").
    append("<img src='/media/img/parts/h3_arrow_down.png' border='0' style='position:absolute;top:0;right:5px;z-index:100;height:19px;cursor:pointer;' />").
    live("click", function() {
	
		if(jQuery.browser.msie)
		{
			$(this).parent().find("ul").toggle("slow")	
		
		} else
		{
			$(this).parent().find("ul").slideToggle();	
		}
						   
      if($(this).find("img").attr("src") == '/media/img/parts/h3_arrow_side.png') {
        $(this).find("img").attr("src", "/media/img/parts/h3_arrow_down.png")
      } else {
        $(this).find("img").attr("src", "/media/img/parts/h3_arrow_side.png")
      }
      return false
    })
	
  $("#micro_sites ul").hide()
  $("#micro_sites h3 img").attr("src", "/media/img/parts/h3_arrow_side.png")
  
  $("#model_car_info ul").hide()
  $("#model_car_info h3 img").attr("src", "/media/img/parts/h3_arrow_side.png")
  
  $("#model_sitemap dl").hide()
  
  $("#model_sitemap li h3").live("click", function() {
	$(this).next().load($(this).contents().attr("href"));
    $(this).next().slideToggle()
    return false
  })

      
});
