// Highlight Links
for(i = 0; i < document.links.length; i += 1)
{
	var a = document.links[i];

	if (a.href == window.location)
	{
		a.setAttribute("id","current")
	}
}



// HTML5 Technology Classes Popup

$(function() {
  $("#tech_class_icons").dialog({
    bgiframe: true,
    width: 910,
    height: 800,
    modal: true,
    draggable: false,
    resizable: false,
    autoOpen: false,
    position: 'center',
    title: 'The Eight Technology Classes of HTML5: Behind the Icons',
    beforeClose: function() { $('#slideshow1').cycle('resume'); }
  });
});

function showTechIconPopup()
{
  $('#tech_class_icons').dialog('open');
  $('#slideshow1').cycle('pause');
}



// Identity Grid

function display_slide(to_show)
{
  $('#slides div').fadeOut().removeClass('current');
  $($('#slides div').eq(to_show)).fadeIn().addClass('current');
}

function hide_thumbs_and_display_slide(to_show)
{
  display_slide(to_show);
  $('#controls').fadeIn();

  $('#thumbnails li').each(function(i, e){
    window.setTimeout(function() {
      $(e).animate({opacity: 0}, 600);
    }, Math.random() * 350);
  });

  window.setTimeout(function() { $('#thumbnails').addClass('hidden'); }, 1000);
}

function bring_grid_back()
{
  $('#slides div').fadeOut().removeClass('current');
  $('#controls').fadeOut();

  $('#thumbnails').removeClass('hidden');

  $('#thumbnails li').each(function(i, e){
    window.setTimeout(function() {
      $(e).animate({opacity: 1}, 300);
    }, Math.random() * 350);
  });
}

function display_next_slide(clicked_on)
{
  if(clicked_on == $('#slides').children().size() - 1)
    display_slide(0);
  else
    display_slide(clicked_on + 1);
}

function display_previous_slide(clicked_on)
{
  if(clicked_on == 0)
    display_slide($('#slides').children().size() - 1);
  else
    display_slide(clicked_on - 1);
}

$(document).ready(function(){

  // If a thumbnail block is clicked, fade out all of the thumbnails and show the correct slide (whose ID is hackily retrieved from the matching thumbnail's ID).
  $('#thumbnails li').bind('click', function(event, ui) { hide_thumbs_and_display_slide($(this).index()); });

  // If the 'back to grid' button is pressed, hide the current slide and bring the thumbnail blocks back.
  $('span#grid').bind('click', function(event, ui) { bring_grid_back(); });

  // If the 'next' button is pressed, show the next slide in the bunch (and hide the current one)
  $('span#next').bind('click', function(event, ui) { display_next_slide($('#slides div.current').index()); });

  // If the 'previous' button is pressed, show the previous slide in the bunch (and hide the current one)
  $('span#previous').bind('click', function(event, ui) { display_previous_slide($('#slides div.current').index()); });

});
