function confirmLink(msg, link)
{
  var user_chk = confirm(msg);
  if (user_chk) {
    window.location = link;
  }
}

/* antimated preview thumbnails */
var aniThumb_c = new Array();
var aniThumb_s = new Array();

function aniThumb(thumb_id, thumb_host, range)
{
  aniThumb_c[thumb_id] = 0;
  setTimeout("aniThumbCycle('" + thumb_id + "','" + thumb_host + "', " + range + ")", 0);
  aniThumb_s[thumb_id] = setInterval("aniThumbCycle('" + thumb_id + "','" + thumb_host + "', " + range + ")", 500);
}

function aniThumbCycle(thumb_id, thumb_host, range)
{
  if (aniThumb_c[thumb_id] < range)
  {
    $("#" + thumb_id).attr('src', buildUrl(thumb_host,  aniThumb_c[thumb_id]));
    aniThumb_c[thumb_id] = aniThumb_c[thumb_id] + 1;
  } else {
    if (aniThumb_s[thumb_id]) {
      clearInterval(aniThumb_s[thumb_id]);
    }
  }
}

function stopaniThumb(thumb_id, thumbUrl)
{
  $(thumb_id).src = thumbUrl;
  if (aniThumb_s[thumb_id]) {
    clearInterval(aniThumb_s[thumb_id]);
  }
}

function buildUrl(thumb_host, thumb_id)
{
  return thumb_host + '/vtn_' + thumb_id + '.jpg';
}

/* clipboard copy - modified from http://www.jeffothy.com/weblog/clipboard-copy/ */
function copy_cb(inElement)
{
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range && BodyLoaded==1)
      range.execCommand('Copy');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="/swf/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

jQuery.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

$(window).ready(function() {
    $('.site_sort_menu2').mouseover(function() {
        $('.site_sort_menu2 ul').show();
    });

    $('.site_sort_menu2 ul').mouseout(function() {
        $('.site_sort_menu2 ul').hide();
    });
    
    $('#top_tag_list').load('/ajax/tag_list');
});
