$(function(){

  $("#gallery_all").addClass('active');

	// Duplicate pagetracker code that's in analytics - here also for testing
  var pageTracker = _gat._getTracker("UA-9673441-1");

	$("#gallery_all").click(function(e) {
    e.preventDefault();
		pageTracker._trackPageview("/gallery.php#all");
    $(this).addClass('active');
    $(".submenu ul li a").not($(this)).removeClass('active');
    $(".gallery").slideDown().find("h3, a").fadeIn();
  });
  $("#gallery_finearts").click(function(e) {
    e.preventDefault();
		pageTracker._trackPageview("/gallery.php#finearts");
    $(".submenu ul li a").not($(this)).removeClass('active');
    $(this).addClass('active');
    $(".gallery_finearts").slideDown().find("h3, a").fadeIn();
    $(".gallery").not(".gallery_finearts").slideUp().find("h3, a").fadeOut();
  });
  $("#gallery_webdesign").click(function(e) {
    e.preventDefault();
		pageTracker._trackPageview("/gallery.php#webdesign");
    $(".submenu ul li a").not($(this)).removeClass('active');
    $(this).addClass('active');
    $(".gallery_webdesign").slideDown().find("h3, a").fadeIn();
    $(".gallery").not(".gallery_webdesign").slideUp().find("h3, a").fadeOut();
  });
  $("#gallery_3d").click(function(e) {
    e.preventDefault();
		pageTracker._trackPageview("/gallery.php#3d");
    $(".submenu ul li a").not($(this)).removeClass('active');
    $(this).addClass('active');
    $(".gallery_3d").slideDown().find("h3, a").fadeIn();
    $(".gallery").not(".gallery_3d").slideUp().find("h3, a").fadeOut();
  })
  $("#gallery_graphicdesign").click(function(e) {
    e.preventDefault();
		pageTracker._trackPageview("/gallery.php#graphicdesign");
    $(".submenu ul li a").not($(this)).removeClass('active');
    $(this).addClass('active');
    $(".gallery_graphicdesign").slideDown().find("h3, a").fadeIn();
    $(".gallery").not(".gallery_graphicdesign").slideUp().find("h3, a").fadeOut();
  })
  $("#gallery_sketchbook").click(function(e) {
    e.preventDefault();
		pageTracker._trackPageview("/gallery.php#sketchbook");
    $(".submenu ul li a").not($(this)).removeClass('active');
    $(this).addClass('active');
    $(".gallery_sketchbook").slideDown().find("h3, a").fadeIn();
    $(".gallery").not(".gallery_sketchbook").slideUp().find("h3, a").fadeOut();
  })


  $(".description").css("display", "none");
  $(".gallery, .feature").hover(
    function () {
      $(this).find(".description").slideDown();
    }, 
    function () {
      $(this).find(".description").delay(500).slideUp();
    }
  );


  //if they have javascript enabled, create and play a slideshow of images.
    $('.slides').width(10500).html("<img src='/images/homegallery_01.jpg' width='1500' height='480' /><img src='/images/homegallery_02.jpg' width='1500' height='480' /><img src='/images/homegallery_03.jpg' width='1500' height='480' /><img src='/images/homegallery_04.jpg' width='1500' height='480' /><img src='/images/homegallery_05.jpg' width='1500' height='480' /><img src='/images/homegallery_06.jpg' width='1500' height='480' /><img src='/images/homegallery_07.jpg' width='1500' height='480' />");
    // animate the slideshow
  function start() {
    $('.slides').delay(5000).animate({left: '-=1500'}, 1000, 'linear', function(){
      // Animation complete
      $('.slides').css("left", 0);
      $('.slides img:first').appendTo($('.slides'));
      start();
    });
  }
  start();

  // set colorbox elements
  if ($("a.cboxElement").length) {
    $("a.cboxElement").colorbox({transition:"fade"});
  }
  
  

});  

