$(document).ready(function () {

  /* init nav */
  $("#top_level_nav #nav").superfish();

  /*widgets*/
  $("div.live_module_set div.toggle > a").click(function (e) {
    e.preventDefault();
    var c = $(this).parent().parent();
    if (c.hasClass("deselected")) {
      c.children(".content").slideDown(300, function() {c.removeClass("deselected").addClass("selected");});
    } else if (c.hasClass("selected")) {
      c.children(".content").slideUp(300, function() {c.removeClass("selected").addClass("deselected");});
    }
  });

  /* accordian mainly used on speaker resources */
  $(".accordion .module h2").accordion({clickTitle: 'h2', slideTime: '30'});
  
  /* make links with class=external open up external */
  $("a.external").click(function (e) {
    e.preventDefault();
    window.open($(this).attr("href"));
  });


});




/* FUNCTIONS */

//Random Images

function randomImg(n, prefix) {
	//Generate a random number from 1 to n
	var ranNum = Math.floor(Math.random() * n) + 1;
	
	//Create the random id by concatenating the prefix and the random number
	var id = prefix + ranNum;
	
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'inline';
	}
}


// -----------------------------------------------------------------------------
//Random Quotes

function randomQuote(n, prefix) {
  var ranNum1 = Math.floor(Math.random() * n) + 1;
  var id1 = prefix + ranNum1;
  if ($('div#widgets p.' + id1)) { 
    $('div#widgets p.' + id1).css({ "display":"block" }); 
  }
}



(function($) {
  $.preload = function() {
    //var preload = [];
    for (var i=arguments.length; i--;) {
      var img = document.createElement('img').src = arguments[i];
      //img.src = arguments[i];
      //preload.push(img);
    }
  }
})(jQuery);


