function rotateSocialBookmarks (listId) {

  window.socialBookmarks = this;

  this.id = listId;
  var count = $(listId).getElementsByTagName("li").length;
  this.num = Math.floor(Math.random() * count); //Index where the rotation of social boommark icons will start. 0 will start with the first link in the list.
  this.interval = 1500; //Interval at which the icons change (1000 = 1 second).
  this.rotateBG = window.setInterval("changeSocialBookmarkingBG()", this.interval); //Start social bookmarking icon rotation.
  this.classAttribute = 'class';
  if (navigator.appName == 'Microsoft Internet Explorer'){
    this.classAttribute = 'className';
  }

  changeSocialBookmarkingBG();
}

function changeSocialBookmarkingBG () { //Changes the "share" background image.
  var shareLI = $('share-bookmarks');
  var socialBookmarks = $(window.socialBookmarks.id);
  if (shareLI) {
  	var LI = socialBookmarks.getElementsByTagName("li");

  	var bgImg = LI[num].getAttribute(window.socialBookmarks.classAttribute);
  	shareLI.style.backgroundImage = "url('/images/icon-" + bgImg + ".gif')";

  	if (window.socialBookmarks.num == LI.length - 1) //When all social bookmark icons have been cycled through, reset the index to 0
    	window.socialBookmarks.num = 0;
  	else
    	window.socialBookmarks.num++;
  }
}

function showSocialBookmarks() { //Shows or hides social bookmarks
  var socialBookmarks = $(window.socialBookmarks.id);
  var shareLI = $('share-bookmarks');

  if (socialBookmarks.style.display == "block") {
    shareLI.style.backgroundImage = "url('/images/bg-icon-expand.gif')";
    socialBookmarks.style.display = "none";
  } else {
    shareLI.style.backgroundImage = "url('/images/bg-icon-collapse.gif')";
    socialBookmarks.style.display = "block";
    clearInterval(window.socialBookmarks.rotateBG);
    window.socialBookmarks.num = 0;
  }
}

function stopChangeSocialBookmarkingBG(){ //Stops rotation of "share" background images and changes the background to the expand icon.
  var socialBookmarks = $(window.socialBookmarks.id);
  var shareLI = $('share-bookmarks');

  if (socialBookmarks.style.display != "block") { //If social bookmarks are not visible
    clearInterval(window.socialBookmarks.rotateBG);
    shareLI.style.backgroundImage = "url('/images/bg-icon-expand.gif')";
  }
}

function startChangeSocialBookmarkingBG(){  //Starts rotation of "share" background images.
  var socialBookmarks = $(window.socialBookmarks.id);
  if (socialBookmarks.style.display != "block") { //If social bookmarks are not visible
    window.socialBookmarks.rotateBG = window.setInterval("changeSocialBookmarkingBG()", window.socialBookmarks.interval);
  }
}

function doSocialBookmark (name) {
  if (window.s) {
    window.s.pageName="";
    window.s.server="";
    window.s.pageType="";
    window.s.channel="";
    window.s.prop1="";
    window.s.prop12="";
    window.s.prop13="";
    window.s.prop14="";
    window.s.prop17="";
    window.s.prop18="";
    window.s.prop19="";
    window.s.prop20="";
    window.s.prop21="";
    window.s.prop29="";
    window.s.prop30="";
    window.s.events="event12";
    window.s.hier1="";
    window.s.hier2="";

    window.s.eVar8="";
    window.s.eVar9="";
    window.s.eVar10="";
    window.s.eVar13="";
    window.s.eVar14 = name;
    window.s.eVar15="";

    window.s.t();
  }
  return true;
}
