// JavaScript Document
function onChangeMake (MakeID)
{
	sendModelRequest(MakeID);
	document.quickSearch.searchMin.disabled = "";
	document.quickSearch.searchMax.disabled = "";
	document.quickSearch.quick_search_submit_button.disabled = "";
}

function onChangeKeywords()
{	
	if ( document.quickSearch.searchKeywords.value == "Enter keywords" ) {
 		document.quickSearch.searchKeywords.value = "";
	}
	document.quickSearch.quick_search_submit_button.disabled = "";
}


// Make Navigation extend down to the bottom
function extendNav( element, target, offset ) {
	height = $( element ).height();
	targetHeight = parseInt( $( target ).position().top ) - parseInt( $( element ).position().top ) + offset;
	if ( height == targetHeight ) return height;
	else return targetHeight;
}

function dropShadowInitiate ( siteAddress ) {
	// Drop Shadows	IE6 Semi Fix
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$('.dropShadow').each(function(){
			$(this).css({
						'marginTop':(parseInt($(this).css('marginTop')) - 1),
						'marginRight':(parseInt($(this).css('marginRight')) - 1),
						'marginBottom':(parseInt($(this).css('marginBottom')) - 1),
						'marginLeft':(parseInt($(this).css('marginLeft')) - 1),
						'border':'1px solid #ccc'
						});
		});
	} else {
		var i = 1;
		$('.dropShadow').each(function(){
			$(this).removeClass("dropShadow");
			$(this).addClass("dropShadow" + i);
			dropShadow(".dropShadow" + i, siteAddress + "dropShadow/normal/" );
			i++;
		});
		var j = 1;
		$('.dropShadowLite').each(function(){
			$(this).removeClass("dropShadowLite");
			$(this).addClass("dropShadowLite" + j);
			dropShadow(".dropShadowLite" + j, siteAddress + "dropShadow/lite/" );
			j++;
		});
		var k = 1;
		$('.dropShadowExtraLite').each(function(){
			$(this).removeClass("dropShadowExtraLite");
			$(this).addClass("dropShadowExtraLite" + k);
			dropShadow(".dropShadowExtraLite" + k, siteAddress + "dropShadow/extraLite/" );
			k++;
		});
		var l = 1;
		$('.dropShadowStrong').each(function(){
			$(this).removeClass("dropShadowStrong");
			$(this).addClass("dropShadowStrong" + l);
			dropShadow(".dropShadowStrong" + l, siteAddress + "dropShadow/strong/" );
			l++;
		});
	}
}

function sortMinMax ( minVar, maxVar ) {
	$('#searchPriceMin').change(function(){
		e = this;
		$('#searchPriceMax').children().each(function(){
			if ( parseInt($(e).val()) > parseInt($(this).val()) ) { $(this).css({'display':'none'}) } else { $(this).css({'display':'block'}) }
		});
	});
	$('#searchPriceMax').change(function(){
		e = this;
		$('#searchPriceMin').children().each(function(){
			if ( parseInt($(e).val()) < parseInt($(this).val()) ) { $(this).css({'display':'none'}) } else { $(this).css({'display':'block'}) }
		});
	});
}

$(document).ready(function(){
	
	autoScroller('#featuredCarsMarquee');
	
	if ( parseInt($(window).height()) >= parseInt($('.footer').position().top) )
	{
		$('#wrapper_inner').height( parseInt($(window).height()) - parseInt($('.footer').height()) - parseInt($('.footer').css('paddingTop')) - parseInt($('.footer').css('paddingBottom')) );
	}
	
	$('.featuredCarsMarqueeContainer').hover(function(){
		clicker = $(this).children('.featuredCarsMarqueeContent').children('.featuredCarsMarqueeContentClick');
		$(this).children('.featuredCarsMarqueeContent').children('.featuredCarsMarqueeContentTxt').fadeIn(0).fadeOut(100,function(){
			clicker.fadeOut(0).fadeIn(100);
		});
	}, function(){
		txt = $(this).children('.featuredCarsMarqueeContent').children('.featuredCarsMarqueeContentTxt');
		$(this).children('.featuredCarsMarqueeContent').children('.featuredCarsMarqueeContentClick').fadeIn(0).fadeOut(100,function(){
			txt.fadeOut(0).fadeIn(100);
		});
	});
	
	// Extend Nav bars down to the Footer
	fix = 0;
	if ($.browser.msie && $.browser.version.substr(0,1) <= 7) fix = -35;
	$('.right_nav').height( extendNav ( '.right_nav', '.footer', 37 + fix) );	
	$('.left_nav').height( extendNav ( '.left_nav', '.footer', 14 ) );	
	
	// Extendable Borders;
	$('.gradBg').each(function(){
		$(this).height( $(this).parent().height() + parseInt( $(this).parent().css('paddingTop') ) + parseInt( $(this).parent().css('paddingBottom') ) );
		$(this).width( $(this).parent().width() + parseInt( $(this).parent().css('paddingLeft') ) + parseInt( $(this).parent().css('paddingRight') ) );
	});
	$('.gradFg').each(function(){
		$(this).height( $(this).parent().height() );
	});
	$('.gradRight').each(function(){
		$(this).height( $(this).parent().height() );
	});
	$('.gradLeft').each(function(){
		$(this).height( $(this).parent().height() );
	});
});