$(document).ready(function(){
	// highlight link of current page
	$("#header").find("a[href='"+window.location.href+"']").each(function(){
		$(this).css('color', 'black');
	})

  //------------------------------
  // front page
  //------------------------------
	// initialize the tweet loading
	$(".tweet").tweet();
	// initialize the rotation script
	$('#rotating-image').innerfade({
		speed: 1500,
		timeout: 5000, // in milliseconds
		type: 'random',
		containerheight: '400px'
	});

  //------------------------------
  // FAQ page
  //------------------------------
	$('#faq-text h3').each(function(i) {
		ref = $(this).text();
		$('#faq-nav').append('<li><a href="#'+ref+'">- '+ ref +'</a></li>');
		$('#faq-nav a:last').click(function(){
			$('body').animate({scrollTop: $('h3:contains("' + ref + '")').offset().top }, 300);
		});
	});

  //------------------------------
  // bike detail pages
  //------------------------------
  // for the top links click event
  $('p.geometry_links_top a').click(function(){
  	// reset the color of other anchor tags and highlight the current
  	//$(this).siblings().css('color', '#808181');
  	//$(this).css('color', '#21C49F');
    $(this).siblings().removeClass('current_size_link');
    $(this).addClass('current_size_link');
  	// determine the index of the current link...
  	num = $('p.geometry_links_top a').index(this);
  	// and fire the click event on the bottom link
  	$('p.geometry_links_bottom a:eq('+num+')').click();
  	// scroll to the bottom
  	$('body').animate({scrollTop: $('.drawings').offset().top }, 300);
  });
  // for links on the bottom
  $('p.geometry_links_bottom a').click(function(){
  	// reset colors
  	//$(this).siblings().css('color', '#808181');
  	//$(this).css('color', '#21C49F');
    $(this).siblings().removeClass('current_size_link');
    $(this).addClass('current_size_link');
  	// hide current drawing
  	$('.drawings img').hide();
  	// reveal drawing of current index
  	num = $('p.geometry_links_bottom a').index(this);
  	$('.drawings img:eq(' + num + ')').show();
  });
  // hide all drawings and then fire the click event on the first one
  $('.drawings img').hide();
  $('.geometry_links_bottom a:first').click();
  
  // enable lightbox for bike images
  $('.photos a').lightBox();
  // enable lightbox for geometry images
  $('.drawings a').lightBox();  

  // make link submit
  $('form a').click(function() {
    $('form').submit();
  });
});

