/* Effects file for nice car company website */

$(document).ready(function(){
	// first lets bind the bkg img to turn on on mouse enter
	$('.top_hoover').bind("mouseenter",function(){
		$(this).children("img").css("display","inline");
		$(this).children("a").css("color","#fff");
	// then lets turn it off
	}).bind("mouseleave",function(){
		$(this).children("img").css("display","none");
		$(this).children("a").css("color","#555");
	});
	
	// next lets bind the bottom nav img to the navigation hoover
	$('.bottom_hoover').bind("mouseenter",function(){
		$(this).children("img").css("display","inline");
		$(this).children("a").css("color","#722b27");
	}).bind("mouseleave",function(){
		$(this).children("img").css("display","none");
		$(this).children("a").css("color","#555");
	});

	$('.left_hoover').bind("mouseenter",function(){
		$(this).children("img").css("display","inline");
		$(this).children("a").css("color","#fff");
	// then lets turn it off
	}).bind("mouseleave",function(){
		$(this).children("img").css("display","none");
		$(this).children("a").css("color","#555");
	});
	
	// this gives the LI the same navigation as its link
	$('li').click(function(){
		if( $(this).children("a").index() >= 1 ){
			if( $(this).children("a").attr("href") != "https://creditapp.autotrader.com/consumer/creditapp/controller.jsp?action=nav_creditapp&dealer_id=568023&origin_page=DEALERS_DDA_INDEX_APPLY_CREDIT" ){
				window.location = $(this).children("a").attr("href");
			}
		}
	});
	
	$('.autoclear').focus(function(){
		var cur = $(this).attr("value");
		var def = $(this).attr("default");
		if( cur == def ){
			$(this).attr("value","");
			$(this).css("color","#555");
		}
	});
	
	$('#refine_search').click(function(){
		$('#searchbox').load('/forms/search-page.php');
		$('#searchbox').toggle();
	});
	
	$('.sort_button').click(function(){
		sort_val = $(this).attr("id").replace("sort_","");
		$('#h_sort').attr("value",sort_val);
		$('#paginationForm').submit();
	});
	
	$('.ncc').bind("mouseenter",function(){
		var posnow = $(this).position();
		newtop = posnow.top;
		newleft = posnow.left;
		$('#warranty_bubble').css("top",newtop);
		$('#warranty_bubble').css("left",newleft);
		$('#warranty_bubble').show("fast");
	});
	
});



