//-----------------------------------------------------------------------------
/*
  headlineSlider
  style: .whatsnew div {color:#7D7F82;padding-left:110px;height:120px;display:none}
  html :
    <td class="whatsnew" style="padding:20px">
    <div> ...  </div>
    <div> ...  </div>
    ...
    </td>
  js: $(".whatsnew").headlineSlider({interval:5000});
*/
//-----------------------------------------------------------------------------
(function($){
  $.fn.headlineSlider = function(options) {

    var defaults = {
      interval: 4000 //time in milliseconds
      , clickable: true
    };

    var options = $.extend(defaults, options);

    return this.each(function() {
      var $t = $(this);
      var h;
      $t.find("div:first-child").eq(0).attr("token", "1").css("display", "block");
      var rotate = function(){
        $n = $t.find("div[token=1] + div").eq(0);
        if ($n.size() == 0) $n = $t.find("div:first-child").eq(0);
        $t.find("div").attr("token", "0").css("display", "none");
        $n.attr("token", "1").fadeIn("slow");
      };
      h = setInterval(rotate, options.interval);
      if (options.clickable)
        $t.hover(
          function() {clearInterval(h);}
          , function() { h = setInterval(rotate, options.interval); }
        );
    });
  };
})(jQuery);

//-----------------------------------------------------------------------------
/*
  bulletRotate
*/
//-----------------------------------------------------------------------------
(function($){
  $.fn.bulletRotate = function(options) {

    var defaults = {
      interval: 4000 //time in milliseconds
      , itemsToDisplay: 4
      , clickable: false
    };

    var options = $.extend(defaults, options);

    return this.each(function() {
      var $t = $(this);
      var h;
      var $ul = $t.find("ul");
      $t.find("li:lt("+options.itemsToDisplay+")").css("display", "block");
      var rotate = function(){
        $t.find("li:lt(1)").hide().appendTo($ul);
        $t.find("li:lt("+options.itemsToDisplay+")").fadeIn("slow");
      };
      h = setInterval(rotate, options.interval);
      if (options.clickable)
        $t.hover(
          function() {clearInterval(h);}
          , function() { h = setInterval(rotate, options.interval); }
        );
    });
  };
})(jQuery);
//-----------------------------------------------------------------------------
/*
  padding
*/
//-----------------------------------------------------------------------------
$.strPadLeft = function(i,l,s) {
	var o = i.toString();
	if (!s) { s = '0'; }
	while (o.length < l) {
		o = s + o;
	}
	return o;
};
$.strPadRight = function(i,l,s) {
	var o = i.toString();
	if (!s) { s = '0'; }
	while (o.length < l) {
		o = o + s;
	}
	return o;
};
//-----------------------------------------------------------------------------
/*
  unique id within page
*/
//-----------------------------------------------------------------------------
$.sitePageUnique = function() {
  if ( typeof this.counter == 'undefined' )
  {
    this.counter = 0;
  }
  return ++this.counter;
};
//-----------------------------------------------------------------------------
/*
  Tooltip
*/
//-----------------------------------------------------------------------------
(function($){
  $.fn.siteToolTip = function(options) {

    var defaults = {
      width: 250
    };

    var options = $.extend(defaults, options);

    return this.each(function() {
      var $t = $(this);
      var tid = 'siteToolTip_' + $.sitePageUnique();
      var $div = $t.next();
      $t.attr("rel", "#"+tid);
      $div.attr("id", tid);
      $t.cluetip({
        cluetipClass:'ice'
        , width: options.width
        , local:true
        , attribute:'rel'
        , titleAttribute:'title'
        , dropShadowSteps:3
        , dropShadow:true
        , showTitle:true
        , arrows:true
      });
      $t.parents('table:first').hide().show();
    });
  };
})(jQuery);

//-----------------------------------------------------------------------------
// end of code                                             -written by Yi Liang
//-----------------------------------------------------------------------------