$(document).ready(function(){
	$('.glitter').find('input').click(copyToClipboard).end().find('textarea').focus(copyToClipboard);
	$('.msg').hide();
});
function copyToClipboard(){
	var p = $(this).parent().parent();
	copy(p.find('textarea:first').eq(0)[0]);
	p.parent().find('.msg').html('Code copied succesfully!!!').addClass('hilite').fadeIn();
	setTimeout("$('.msg').html('&nbsp;').fadeOut();", 3000);
}

function copy(inElement) {
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range)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;
  }
}
