jQuery('html').addClass('js');

jQuery(function($) {
  
  $(window).bind('load', function(event) {
    if (typeof pageInit != 'undefined') {
      pageInit();
    }  
  });
  var $netData = $('#network-data tbody');
  $netData
    .find('td:first-child').addClass('colhead')
    .end()
    .find('tr:nth-child(odd)').addClass('alt');
    
    
  $('div.additional-options a:has(img)').each(function(index) {
    var $this = $(this);
    var bubbleText = $('img', this).attr('alt');
    $this.append('<span class="bubble">' + bubbleText + '</span>')
      .hover(function() {
        $this
          .find('img').attr('alt', '')
          .end()
          .find('span').fadeIn(200);
      }, function() {
        $this
          .find('img').attr('alt', bubbleText)
          .end()
          .find('span').hide();
      });
  });

  $("#expand-hidden-expandable").click(function(e){
	e.preventDefault();
	$("#hidden-expandable").slideDown();
	$(this).hide();
  });
  $("#collapse-hidden-expandable").click(function(e){
	e.preventDefault();
	$("#hidden-expandable").slideUp('normal',function(){
		$("#expand-hidden-expandable").show();
	});
  });
});


// Cycle images 

jQuery(document).ready(function($) {
  var $body = $('body');
  if ($body.hasClass('home')) {
    $('div.home-banner ul').cycle({timeout: 7000});
    // $('#comment-container').cycle();
  } else if ($body.hasClass('page') && $('#sidebar div.image-body img').length > 1) {
    
    $('div.image-body').cycle({timeout: 6000});
  }
});


//if($(".home-features .home-feature-container:eq(0)").children('a').length > 1) {
  setTimeout(function(){
    doRotating(0);
    setInterval(function(){
       doRotating(0);
    },7000);
  },2000);
//}

//if($(".home-features .home-feature-container:eq(1)").children('a').length > 1) {
  setTimeout(function(){
    doRotating(1);
    setInterval(function(){
        doRotating(1);
    },7000);
  },3000);
//}

//if($(".home-features .home-feature-container:eq(2)").children('a').length > 1) {
  setTimeout(function(){
    doRotating(2);
    setInterval(function(){
        doRotating(2);
    },7000);
  },4000);
//}

var doRotating = function(i) {
  var elem = $(".home-features .home-feature-container:eq("+i+")").children("a:eq(1)");
  if($(elem).css('display') == 'block')
    $(elem).fadeOut();
  else
    $(elem).fadeIn();
}

