// JavaScript Document

var navTime = 3500;
var rotateTime = 7000;
var timer = null;
var rotation = null;
var imgNum = 0;
var totalImgs = 8;

function hideExtras() {
	$("#extras").stop().animate({
		right: -515
	}, 300, "easeOutSine", function() { 
		//showExtrasTab(); 
	});
}
function hideNav() {
	setTimeout (hideExtras, 150);
	$("#nav").stop().animate({
		right: -515
	}, 600, "easeOutSine", function() { showNavTab(); });
}

function showExtrasTab() {
	$("#extrasTab").stop().animate({
		right: 0
	}, 300);
}
function showNavTab() {
	$("#navTab").stop().animate({
		right: 0
	}, 300);
}

function hideExtrasTab() {
	$("#extrasTab").stop().animate({
		right: -113
	}, 300);
}
function hideNavTab() {
	$("#navTab").stop().animate({
		right: -113
	}, 300);
}

function showNav() {
	setTimeout (showExtras, 200);
	$("#nav").stop().animate({
		right: 0
	}, 500, "easeOutQuad");
}
function showExtras() {
	$("#extras").stop().animate({
		right: 0
	}, 350, "easeOutQuad");
}

function rotator() {
	
	oldImg = 'img'+imgNum;

	if (imgNum == totalImgs) {
		imgNum = 0;
	} else {
		imgNum += 1;
	}
	
	var myImg = bgs[imgNum];

	newImg = 'img'+imgNum; 

	var winWidth=$(window).width();
	if (winWidth < 960) {
		winWidth = 960;
	}
	$("#"+oldImg).removeClass('bgimg');
	$("#"+oldImg).css("z-index","2");
	$("#"+oldImg).css("position","absolute");
	
	startX = -(winWidth);
		
	var html = '<img src="/images/backgrounds/'+myImg+'.jpg" class="bgimg" style="z-index: 1;" id="img'+imgNum+'" />';
	
	$("#bg").append(html);
		
	$('.bgimg').onImagesLoaded(function(_this){
				
		FullScreenBackground('.bgimg');
		
		$("#"+newImg).css("position","absolute");
		$("#"+newImg).css("right",winWidth+"px");
						
		$("#"+oldImg).stop().animate({
			left: winWidth
		}, 2000, function() { $("#"+oldImg).remove();});			
		
		
		$("#"+newImg).stop().animate({
			right: 0
		}, 2000, function() { rotation = setTimeout(rotator, rotateTime); });

	});

}

// home page testimonial hover
$(function() {
	$(".readmore a img").css("opacity",".2");
	// ON MOUSE OVER
	$(".readmore a img").hover(function () {
	
		// SET OPACITY TO 80%
		$(this).stop().animate({
			opacity: .8
			}, 300);
		},
	
		// ON MOUSE OUT
		function () {
		
			// SET OPACITY BACK TO 50%
			$(this).stop().animate({
			opacity: .2
			}, 300);
			
	});
	
	$(".testimonialGraphic").hover(function() {
		$(".readmore a img").stop().animate({
			opacity: .8
			}, 300);
		},
	
		// ON MOUSE OUT
		function () {
		
			// SET OPACITY BACK TO 50%
			$(".readmore a img").stop().animate({
			opacity: .2
			}, 300);
	});
	
});

/*
$(document).ready(function() {

	var showroom = 'default';
	
	if(google.loader.ClientLocation)
	{	
		var visitor_lat = google.loader.ClientLocation.latitude;
		var visitor_lon = google.loader.ClientLocation.longitude;
		
		var mem_lat = 35.139466;
		var mem_lon = -90.051730;
	
		var nash_lat = 36.167010;
		var nash_lon = -86.774115;
			
		var GeoCodeCalc = {};
		GeoCodeCalc.EarthRadiusInMiles = 3956.0;
		GeoCodeCalc.EarthRadiusInKilometers = 6367.0;
		GeoCodeCalc.ToRadian = function(v) { return v * (Math.PI / 180);};
		GeoCodeCalc.DiffRadian = function(v1, v2) { 
		return GeoCodeCalc.ToRadian(v2) - GeoCodeCalc.ToRadian(v1);
		};
		GeoCodeCalc.CalcDistance = function(lat1, lng1, lat2, lng2, radius) { 
		return radius * 2 * Math.asin( Math.min(1, Math.sqrt( ( Math.pow(Math.sin((GeoCodeCalc.DiffRadian(lat1, lat2)) / 2.0), 2.0) + Math.cos(GeoCodeCalc.ToRadian(lat1)) * Math.cos(GeoCodeCalc.ToRadian(lat2)) * Math.pow(Math.sin((GeoCodeCalc.DiffRadian(lng1, lng2)) / 2.0), 2.0) ) ) ) );
		};
		
		d = GeoCodeCalc.CalcDistance(visitor_lat, visitor_lon, mem_lat, mem_lon, GeoCodeCalc.EarthRadiusInMiles);
		
		if (d < 50) {
			
			showroom = 'memphis';
	
		} else {
			
			d = GeoCodeCalc.CalcDistance(visitor_lat, visitor_lon, nash_lat, nash_lon, GeoCodeCalc.EarthRadiusInMiles);
			if (d < 50) {
				
				showroom='nashville';
			}
			
		}
	
	}
	switch (showroom) {
		case 'default':
			document.getElementById('showroomImg').innerHTML = '<img src="/images/showroom.png" />';
			break;
		case 'memphis':
			document.getElementById('showroomImg').innerHTML = '<img src="/images/geo-badge_memphis.png" style="position: relative; bottom: 40px;" />';
			break;
		case 'nashville':
			document.getElementById('showroomImg').innerHTML = '<img src="/images/geo-badge_nashville.png" style="position: relative; bottom: 40px;" />';
			break;
	}
	
});
*/
