try{
  $('imgShot').addEventListener('load',function(){switchInd();new Effect.Appear('imgShot');},false);
}
catch(r){
  $('imgShot').attachEvent('onload',function(){switchInd();new Effect.Appear('imgShot');});
}
var tried=parseInt($('spLeft').innerHTML);
var _id=0;
var _timeStop,_timeStart,_loadTime=null;

function startTimer(){
  _timeStart=new Date();
}

function stopTimer(){
  _timeStop=new Date();
  _loadTime=(_timeStop-_timeStart)/1000;
}
function chkDis(){
  if(tried>=3){
    $('btnShot').disabled=true;
  }
}
function isLoaded(){
  switchInd();
  var id=_id-1;
  id="img_"+id;
  //new Effect.Appear(id);
  $(id).style.display="block";
  stopTimer();
  $('inpTxtTimer').innerHTML="This webshot took "+_loadTime+" seconds to be generated.";
  $('inpTxtTimer').style.visibility="visible";
  tried++;
  $('spLeft').innerHTML=tried;
  chkDis();
  //tried=parseInt($('spLeft').innerHTML);
}

function doWebshot(){
  var _trg=$('webshotResult');
  var _cache=1;
  if($('inpChkCache').checked==false){
    _cache=0;
  }
  startTimer();
  $('inpTxtTimer').style.visibility="hidden";
  var hash=Math.random();
  switchInd();
  if(_id>0){
    oldElem=_id-1;
    if($('img_'+oldElem)){
      //Effect.Fade('img_'+oldElem);
      $('img_'+oldElem).style.display="none";
    }
  }
  
  var im=document.createElement('img');
  im.src='/get.php?uid=1&size=320&quality=100&type=png&cache='+_cache+'&hash='+hash+'&url='+$('inpTxtUrl').value;
  im.alt=" ";
  im.id="img_"+_id;
  im.setAttribute('style',"display:none;margin-right:2px;");
  
  try{
  	im.addEventListener('load',isLoaded,true);
  }
  catch(r){
  	im.attachEvent('onload',isLoaded);
  }
  $('imgHere').appendChild(im);
  /*
  new Insertion.Bottom('imgHere', '<img src="/get.php?uid=1&amp;size=320&amp;quality=100&amp;type=png&amp;cache='+_cache+'&amp;hash='+hash+'&amp;url='+$('inpTxtUrl').value+'" ' +
  		'id="img_'+_id+'" ' +
  		'alt="" ' +
  		'style="display:none;margin-right:2px;" ' +
  		'onload="javascript:isLoaded(this.id);"/>');
  		*/
  _id++;
}

function switchInd(){
  var _trg=$('imgInd');
  if(_trg.style.visibility=='hidden'){
    _trg.style.visibility="visible";
  }
  else{
    _trg.style.visibility="hidden";
  }
  
}
function delTmp(_fname) {
  var url="/libs/xml/demo.php";
  var hash=Math.random();
  var pars="action=delTmp&amp;fname="+_fname+"&amp;hash="+hash;
  var myAjax = new Ajax.Request(
        url, 
        {
          method: 'post', 
          parameters: pars 
        });
}

chkDis();