$(document).ready(function() {
  //set curtain height to document height
  $('#curtain').css('height',$(document).height());
  if($('body').hasClass('page-id-6')) {
	initialize();
  }
});


/*===============================================================*/
//home slides rotation
/*===============================================================*/	
homeQuoteActive = 1;
homeQuoteTotal = $('#homeQuoteController > li').size();
rotateQuotes = setInterval("doQuoteRotate()", 4500);
	
$('document').ready(function() {
	homeQuoteTotal = $('#homeQuoteController > li').size();	
});
$('#homeQuoteController li ').live('click', function() {
  var clickNum = parseInt(this.id.replace('hqc',''));
  moveQuotes(clickNum);
});
$('#homeQuoteController').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseout') {
	rotateQuotes = setInterval("doQuoteRotate()", 4500);
  } else {
    clearInterval(rotateQuotes);
  }
});
function moveQuotes(num) {
  var containerWidth = 320;  //it's really height, but who's lookin?  YOU!
  var posLeft = - ((num * containerWidth) - containerWidth);
  $('#homeQuoteController li').removeClass('hqcActive');
  $('#hqc'+num).addClass('hqcActive');
  $('#homeQuotes ul').animate({
    top: posLeft
  }, 800, function() {
    homeQuoteActive = num;
  });
}
function doQuoteRotate() {
  if ((homeQuoteActive + 1) > homeQuoteTotal) {
    moveQuotes(1);
  } else {
    moveQuotes((homeQuoteActive + 1));
  }
}
//================ End Home Slide Rotation ===================//

/*===============================================================*/
//home testimonials fade
/*===============================================================*/	
homeTestimonialActive = 1;
homeTestimonialTotal = $('#homeTestimonials > ol > li').size();
$('document').ready(function() {
	homeTestimonialTotal = $('#homeTestimonials > ol > li').size();
});

rotateTestimonials = setInterval("doTestimonialsRotate()", 7000);



$('#homeTestimonials ol li ').live('click', function() {
  var clickNum = parseInt(this.id.replace('htc',''));
  moveTestimonial(clickNum);
});
$('#homeTestimonials ol').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseout') {
	rotateTestimonials = setInterval("doTestimonialsRotate()", 7000);
  } else {
    clearInterval(rotateTestimonials);
  }
});

function moveTestimonial(num) {
	$('.htActive').fadeOut('slow', function() {
		$('.htActive').removeClass('htActive');
		$('.htcActive').removeClass('htcActive');
		$('#htc'+num).addClass('htcActive');
		$('#ht'+num).fadeIn('slow', function() {
			$('#ht'+num).addClass('htActive');
		});
	});
}
function doTestimonialsRotate() {
  if ((homeTestimonialActive + 1) > homeTestimonialTotal) {
    moveTestimonial(1);
	homeTestimonialActive = 1;
  } else {
    moveTestimonial((homeTestimonialActive + 1));
	homeTestimonialActive = homeTestimonialActive + 1;
  }
}

//================ Portfolio Functions ===================//

$('#portfolio li').live('mouseenter mouseleave', function(event) {
  //
  if (event.type == 'mouseleave') {
	//$(this).children('div').clearQueue();
	$(this).children('div').fadeOut('slow', function() {
		$(this).clearQueue();
	});
  } else {
	$(this).children('div').fadeIn('slow', function() {
		$(this).clearQueue();
	});
  }
});


//================ End Portfolio Functions ===============//


//================ End Home Testimonials Fade ===================//

/*===============================================================*/
//mapping and direction functions
/*===============================================================*/
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
	$('#map_directions_display').html('');
	directionsDisplay = new google.maps.DirectionsRenderer();
	var start = new google.maps.LatLng(33.947612,-83.385777);
	var myOptions = {
	  zoom:2,
	  mapTypeId: google.maps.MapTypeId.ROADMAP,
	  center: start
	}
	map = new google.maps.Map(document.getElementById("contactmap"), myOptions);

	//gmaps 
	//http://maps.google.com/maps?oe=utf-8&client=firefox-a&ie=UTF8&q=1028+canton+street&fb=1&gl=us&hnear=Athens,+GA&cid=0,0,577205010346516717&ll=34.026646,-84.361503&spn=0.008323,0.022037&z=16&layer=c&cbll=34.026731,-84.361493&panoid=nrChrgISGY5uFacR2drLeg&cbp=12,242.83,,0,-13.39

  var myLatLng = new google.maps.LatLng(33.947612,-83.385777);
  var vetMarker = new google.maps.Marker({
      position: myLatLng,
      map: map
  });

  
	directionsDisplay.setMap(map);
	directionsDisplay.setPanel(document.getElementById("map_directions_display"));
}

function calcRoute() {
	if ($('#address').val() == '') {
		alert('Please enter your address...');
	} else {
		var end = '1028 Canton Street, Roswell, GA 30075'; //table and main
		var start = $('#address').val();
		var request = {
			origin:start, 
			destination:end,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};
		directionsService.route(request, function(response, status) {
		  if (status == google.maps.DirectionsStatus.OK) {
			directionsDisplay.setDirections(response);
		  }
		});

	}
}

  function moveCenter(x,y) {
    var center = new google.maps.LatLng(x, y);
    map.setCenter(center);
  }
/* =============================================================================*/
