/*
	script.js
	J. Ramsay - James Ramsay's vCard
	Inspired by the timvandamme.com and other websites of a similar nature.
	Copyright © James Ramsay 2011
	Last Updated 14/02/11
*/
$(function(){

  var root = $("html"),
      welcomeTitle = root.find("hgroup"),
      emptyElt = "<div/>",
      vCardReferentId = "referent",
      activeClass = "active",
      hiddenClass = "hidden",
      animAttr = "data-anim";

  root.attr("class", "j");

  welcomeTitle.remove();

  $("section")
    .wrap($(emptyElt, {
      id: vCardReferentId,
      className: hiddenClass
    }))
    .wrap($(emptyElt, {
      id: "vcard-mask"
    }));

  var vCardReferent = $("#" + vCardReferentId);

  setTimeout(function(){
    vCardReferent
      .removeClass()
      .attr(animAttr, "supersize")
      .children()
      .attr(animAttr, "slide-up");
  }, 500);

  vCardReferent
    .find("[href='http://kpmg.com.au']")
    .prepend($("<span/>"));

  vCardReferent
    .find("[href='http://themelb.org.au']")
    .prepend($("<span/>"));

  var picList = vCardReferent.find("ul:first"),
      picListItems = picList.children(),
      picLink = $("<a/>", {href: "."}).append($(emptyElt));

  picList.before(
    $("<nav/>")
      .append(picLink.clone())
      .append(picLink.clone())
      .append(picLink.clone())
  );

  picListItems
    .first()
    .addClass(activeClass);

  var picLinks = picList.prev().find("a");

  picLinks
    .click(function(){
      var activeLink = $(this);
      picLinks.removeClass();
      activeLink.addClass(activeClass);
      picListItems
        .removeClass()
        .eq(picLinks.index(activeLink))
        .addClass(activeClass);
      return false;
    })
    .first()
    .addClass(activeClass);

});
