$(document).ready(function() {
  $("#silver_link").click(function(){
    $(".floating_nav a").removeClass("selected");
    $(".overview_block").css("background-image","url(/images/subaru/cosworth/cos_bg1_silver.jpg)");
    $(this).addClass("selected");
    $(".overview_block h1").removeClass("red grey silver");
    $(".overview_block h1").addClass("silver");
		return false;
  });
  $("#red_link").click(function(){
    $(".floating_nav a").removeClass("selected");
    $(".overview_block").css("background-image","url(/images/subaru/cosworth/cos_bg1_red.jpg)");
    $(this).addClass("selected");
    $(".overview_block h1").removeClass("red grey silver");
    $(".overview_block h1").addClass("red");
		return false;
  });
  $("#grey_link").click(function(){
    $(".floating_nav a").removeClass("selected");
    $(".overview_block").css("background-image","url(/images/subaru/cosworth/cos_bg1.jpg)");
    $(this).addClass("selected");
    $(".overview_block h1").removeClass("red grey silver");
    $(".overview_block h1").addClass("grey");
		return false;
  });
  

    $(".base_nav a, .floating_nav .links a").bind('click', function() {
      var link = $(this).attr('href');
      if(link =="#") target = 0;
      else {
        var link = link.replace(/#/,'');
        var sel = "a[name="+link+"]";
        var target = $(sel).offset().top; // Get scroll target
      }

      $('html, body').animate({scrollTop:target}, 2000,"easeInOutQuad");      
    	return false;
    });


  $(".compare_range_filters h2").hide();
  $(".compare_range_filters .petrol_filter").hide();
  
	jQuery(".quote").hide();
	jQuery('.quote-0').show();
	var max_quotes = jQuery('.quote').length, quote_position = current_qposition = 0,
			quote_fade = function(){
				clearTimeout(timed_faded);
				current_qposition = quote_position;
				quote_position ++;
				if(quote_position+1 > max_quotes) quote_position = 0;
				jQuery('.quote-'+current_qposition).fadeOut("slow", function(){
					jQuery('.quote-'+quote_position).fadeIn("slow");
					timed_faded = setTimeout(quote_fade, 4000);
				})
			},
			timed_faded = setTimeout(quote_fade, 4000);
	jQuery('.quote').hover(function(){clearTimeout(timed_faded);}, function(){setTimeout(quote_fade, 4000);});

	jQuery(".finance_tabs .tabs").tabs();
	
});



var fn_t;
$(window).scroll(function(){
	clearTimeout(fn_t);
	fn_t = setTimeout(
		function(){
			var pos = $(window).scrollTop();
			if(pos <= 110) $(".floating_nav").animate({"top":"210px"});
			else $(".floating_nav").animate({"top":"20px"});
		},100
	);
	
})
