$(document).ready(function($) {

  if ($("a[href$='.flv']").length > 0) {
    $("a[href$='.flv']").attr('rel','shadowbox;width=720;height=640;player=flv');
  // $("a[href$='.flv']").attr('style','display:none;');
  };
  
  if ($('.second').length > 0) {
    $('ul.second').attr('style', 'display:none');
    $('ul.second').slideDown('2000');
  };

  if ($('.tx-powermail-pi1').length > 0) {
    $('#uid1, #uid2, label').addClass('text');
  };

  //Setup variables
  var element = $('#list li'); // all the list elements
  var offset = 0;             // angle offset for animation
  var stepping = 0.03;        // how fast the list rotates
  var list = $('#list');      // the list wrapper
  var $list = $(list);

  /* Handles mouse movement, the closer to the center
  the faster the list will rotate */
  // $list.mousemove(function(e){
  // 
  //     var topOfList = $list.eq(0).offset().top
  //     var listHeight = $list.height()
  // 
  //     // Sets variable that controls the speed of rotation.
  //     stepping = (e.clientY - topOfList) /  listHeight * 0.2 - 0.1;
  // 
  // });


  /* Disperse elements evenly around the circle */
  for (var i = element.length - 1; i >= 0; i--)
  {
      element[i].elemAngle = i * Math.PI * 2 / element.length;
  }

  // call render function over and over
  // setInterval(render, 20);
  setInterval(render, 40);


  // Handles how and where each element will be rendered.
  function render(){

      //Steps through each element...
      for (var i = element.length - 1; i >= 0; i--){

          // offset adds degrees to where the element 
          // is currently on the circle
          var angle = element[i].elemAngle + offset;

          // Trig to figure out the size and where the
          // text should go
          x = 120 - Math.sin(angle) * 30;
          y = 45 - Math.cos(angle) * 40;
          size = Math.round(40 - Math.sin(angle) * 40);

          // Centers the text, instead of being left aligned.
          var elementCenter = $(element[i]).width() / 2;

          // Figure out the x value of the element.
          var leftValue = (($list.width()/2) * x / 100 - elementCenter) + "px"


          // Apply the values to the text
          $(element[i]).css("fontSize", size/3 + "pt");
          $(element[i]).css("opacity",size/100);
          $(element[i]).css("zIndex" ,size);
          $(element[i]).css("left" ,leftValue);
          $(element[i]).css("top", y + "%");
      }

      // Rotate the circle
      offset -= stepping;
  }


});

