$(function(){
  startLightBox();
  boxBorderRollover();
  linkProductHeader();
});

function startLightBox(){
  // for product slides
  if($('body.product').length > 0){
    $('#product-slides li a').lightBox();
  }
  
  // for gallery slides
  if($('body.gallery').length > 0){
    $('#gallery-index li a').lightBox();
  }
  
}




function boxBorderRollover() {
  
  // rollover on gallery slides
  $('#gallery-index li').hover(function() {
      // highlight thumbnail
   		$(this).addClass('current');
   }, function() {
  	$(this).removeClass('current');
  });
  
  
	$('#product-index li').hover(function() {
      // highlight thumbnail
   		$(this).addClass('current');
      // highlight side menu
      $("#productnav a[title='" + $(this).find('a').attr('title')+ "']")
      .addClass('current');
	 }, function() {
		$(this).removeClass('current');
    $("#productnav a[title='" + $(this).find('a').attr('title')+ "']")
    .removeClass('current');
	});
	
  // highlight thumbnails when side menu is hovered
	$('#productnav a').hover(function() {
      // highlight thumbnail
      $("#product-index li a[title='" + $(this).attr('title')+ "']")
      .closest('li')
      .addClass('current');
	 }, function() {
      $("#product-index li a[title='" + $(this).attr('title')+ "']")
      .closest('li')
      .removeClass('current');

	});


	$('#product-slides li').hover(function() {
   		$(this).addClass('current');
	 }, function() {
		$(this).removeClass('current');
	});
}

function linkProductHeader() {
  //TODO don't do this.
  $('body.product #content h1').click(function(){document.location = '/products/'});
}


