
$(document).ready(function() {
	
	$('#banner-tabs img').hover(function() {
		
		if( !this.tab_selected ) {
			$(this).attr('src', $(this).attr('src').replace('.png', '-selected.png'));
			this.ishovering = true;
		}
		
	}, function() {
		
		if( !this.tab_selected ) {
			$(this).attr('src', $(this).attr('src').replace('-selected.png', '.png'));
			this.ishovering = false;
			$(this).attr('src', $(this).attr('src').replace('-selected.png', '.png'));
		}
		
	});
	
	$('#banners').cycle({ 
    	fx:    'fade', 
    	speed:  1000,
    	timeout: 5000,
    	after: order_tabs
 	});
 	
 	$('#before-shot, #after-shot').cycle({
 		fx:    'fade',
 		timeout: 5000,
    	speed:  1000
 	});
 	
});

var i = 0;

function order_tabs(curr, next, opts) {
	
	var current_slide_number = opts.currSlide+1;
	var current_tab_img = document.getElementById(current_slide_number).getElementsByTagName('img')[0];
	
	//Chagne all other tabs
	var i = 1;
	$('#banner-tabs img').each(function() {
	
		$(this).css('z-index', 5-i);
		this.tab_selected = false;
		this.src = this.src.replace('-selected', '');
		i++;
		
	});
	
	$(current_tab_img).css('z-index', '9999');
	current_tab_img.tab_selected = true;
	current_tab_img.src = current_tab_img.src.replace('.png', '-selected.png');
	
}

//preload images
var Images = ['images/Site/available-trucks-selected.png', 'images/Site/free-estimate-selected.png', 'nationwide-pickup-selected.png'];
for( var x = 0; x < Images.length; x++ ) {
	var img = new Image();
	img.src = Images[x];
}
