﻿$(document).ready(function(){
  
  // hide portfolio item content
  $("ul#portfolio div.portfolio-content").each(function(){
    $(this).hide();
  });
  
  // assign accordian behaviour to portfolio items
  $("ul#portfolio h2 a").click(function(){
    var itemContent = $(this).parent().parent().find("div.portfolio-content");
    // if item is already displayed, close it and exit the function
    if (itemContent.get(0).style.display != "none")
    {
      itemContent.slideToggle("1000");
      return false;
    } // if
    // close all open items
    $("ul#portfolio div.portfolio-content").each(function(){
      if (this.style.display != "none") $(this).slideToggle("1000");
    });
    itemContent.slideToggle("1000"); // display clicked item
    return false;
  });
  
  // open relevant portfolio item if there is an anchor in the URL
  var anchor = window.location.toString().split("#")[1];
  if (anchor != undefined) $("li#" + anchor + " div.portfolio-content").show();
  
});