// cufon

Cufon.replace('h1, .gateway h2, h3, h4, #header-nav a, #vehicle-nav a');

$(document).ready(function() {

  // position #footer at bottom of viewport

  $(window).bind("load resize", function() {
                
    var v = $(window).height(); // v = viewport height
	var f = $("#footer").height(); // f = footer height
	
	if ($("#footer").css("position", "relative")) {
    	b = $("body").height() - 31; // 31 is height of #footer, b = body height
	}
	else {
		var b = $("body").height();
	}
	
    if (b + f > v) {
      $("#footer").css("position", "relative");
    } else {
      $("#footer").css("position", "fixed");
    }
  });
  
  // display vehicle list & overlay when hovering vehicle navigation
  
  $("#vehicles").hover(
  	function() {
		$("#vehicle-nav").slideDown("fast");
		$("#overlay").css("display", "block");
    },
	function(){
		$("#overlay").css("display", "none");
		$("#vehicle-nav").slideUp("fast");
	}
  );
  
  // set #bucket_list heights
  
  if ($("#bucket_list").length > 0) {
	
	var tallest = 0;
	
	$('#bucket_list > li').each(function(i) {
		var currentHeight = ($(this).height());
		if (currentHeight > tallest) {
			tallest = currentHeight;
		}
	});
	
	$('#bucket_list > li').css('height', tallest);
	  
  };
  
  // Landing page image rotator
  
  if ($("#image_rotator").length > 0) {
  
  	$('#image_rotator img:not(:first)').hide();
	
	function rotateImages() {
		$('#image_rotator img')
			.first()
			.hide()
			.appendTo($('#image_rotator'));
		$('#image_rotator img')
			.first()
			.fadeIn(1800);
	}
	
	var rotate = setInterval(rotateImages, 7000);
	
  }
  
  // Video controls
  
  $("#video_links a").click(function(i) {									 
		i.preventDefault();	
		var r = $(this).data("youtube");
		var iframeSrc = '<iframe src="http://www.youtube.com/embed/' + r + '?wmode=transparent&fs=1&autoplay=1&modestbranding=1&iv_load_policy=3&rel=0&showinfo=0" frameborder="0" width="600" height="365"></iframe>';
		if(!($(this).parent('dd').hasClass('current'))) {
			$("#video_links dd.current").removeClass("current");
			$(this).parent("dd").addClass("current");
			$("#video")
				.empty()
				.html(iframeSrc);
		}
	
  });
  
});

