// JavaScript Document

var slideon = 0;
var timer = 6500;
var slide_time = 700;
var delay = 0;
var easing = 'easeInSine';
					
$(document).ready(function(){
	slide = setInterval('slideIt(slideon)', timer);
	
	jQuery("#buy-a-car a").click(function(e){
		clearInterval(slide);
		e.preventDefault();
		
		if(jQuery("#buy_tips_bg").css('top') != '0px') {
			jQuery("#buy_tips_bg").animate({
				top: '0px'
			},600);
		}
		
		jQuery(".close_tips").fadeIn();
		
		jQuery(".buy_tips").each(function(){
			if(jQuery(this).css('top') != '415px' && jQuery(this).attr('id') != 'buy_tips_bg') {
				jQuery(this).animate({
					top: '415px'
				},600);
			}
		});
				
		jQuery(jQuery(this).attr('href')).animate({
			top: '4px'
		},600);
		
				
	});
	
	jQuery("#buy_bullets").find("span:first-child").click(function(){
		jQuery("#buy_tips_back").click();
	});
	
	jQuery("#buy_bullets").find("span:last-child").click(function(){
		jQuery("#buy_tips_forward").click();	
	});
	
	jQuery(".close_tips").click(function(){
		jQuery(this).fadeOut(250);
		jQuery(".buy_tips").each(function(){
			jQuery(this).animate({
				top: '415px'
			},600);
		});
		jQuery("#buy_tips_bg").animate({
			top: '415px'
		},600);
	});
	
	jQuery(".buy_tips_link").click(function(){
	
		if(jQuery(this).attr('id') == 'buy_tips_back') {
			jQuery("#buy_dealer_tips section").find("ul").animate({
				left: '0'
			},600,'easeOutExpo');
			jQuery("#buy_bullets").css('background-position','0 0');
			jQuery("#buy_tips_back").fadeOut('slow');
			jQuery("#buy_tips_forward").fadeIn('slow');
		} else {
			jQuery("#buy_dealer_tips section").find("ul").animate({
				left: '-732px'
			},1000,'easeOutExpo');
			jQuery("#buy_bullets").css('background-position','0 15px');
			jQuery("#buy_tips_forward").fadeOut('slow');
			jQuery("#buy_tips_back").fadeIn('slow');
		}
		
	});
});	
					
function slideIt() {
	if($("#nowidget").css('left') == '0px') {
		clearInterval(slide);	
	} else {
		$("#autoslides").find('img').eq(slideon).animate({
			opacity: 0,
			right: '900px'
		
		},slide_time,easing,function(){
			$(this).css('right','-900px');	
		});
						
		$("#personslides").find('img').eq(slideon).delay(delay).animate({
			opacity: 0,
			right: '-900px'
		},slide_time,easing,function(){
			$(this).css('right','900px');	
		});
						
		if(slideon < 2) {
			slideon++;	
		} else {
			slideon = 0;	
		}
			
		if(slideon == 0) {
			set_right_to = '75px';	
		} else if(slideon == 1) {
			set_right_to = '20px';	
		} else {
			set_right_to = '0px';	
		}
						
		$("#autoslides").find('img').eq(slideon).animate({
			right: set_right_to,
			opacity: 1
		},slide_time,easing);
						
		$("#personslides").find('img').eq(slideon).delay(delay).animate({
			right: '10px',
			opacity: 1
		},slide_time,easing);	
	}
						
}
