/* 
  Copyright 2007 hkrn <hikarin@users.sourceforge.jp>
   */var Img0ch;if(typeof Img0ch=="undefined")Img0ch={};if(typeof Img0ch.App=="undefined")Img0ch.App={};(function(){var app_=Img0ch.App;var bbs_=app_.getBBS();var bbsURI_=app_.getBBSURI();var frequency_=16;var removed_=bbsURI_+"/img/removed.json";var localServer_;app_.require([{"google.gears":app_.getStaticURI()+"/js/gears_init.js"}],function(){try{localServer_=google.gears.factory.create("beta.localserver","1.0");}catch(e){}
Img0ch.App.GoogleGears={"sync":function(callback){if(!localServer_)return;var filesToCapture=[];var ns=location.host+".img0ch."+bbs_;var resourceStore=localServer_.openStore(ns);if(!resourceStore)
resourceStore=localServer_.createStore(ns);if(Math.floor(Math.random()*frequency_)==0){jQuery.getJSON(removed_,function(removed){var extensions=["jpg","gif","png"];for(var i in removed){var res=removed[i];var base=bbsURI_+"/img/"+res[0]+"/";var fileUriBase=base+res[1]+".";var thumbUriBase=base+"t"+res[1]+".";for(var e in extensions){var ext=extensions[e];var fileUri=fileUriBase+ext;var thumbUri=thumbUriBase+ext;if(resourceStore.isCaptured(fileUri)){resourceStore.remove(fileUri);}
if(resourceStore.isCaptured(thumbUri)){resourceStore.remove(thumbUri);}}}});}
jQuery("img.image").each(function(){filesToCapture.push(this.src)});jQuery("a.i0_file,a.i0_image,a.i0_thumbnail").click(function(event){var fileUri=this.href;if(!resourceStore.isCaptured(fileUri)){resourceStore.capture(fileUri,function(url,success,captureId){if(success){window.open(url);event.preventDefault();}});return false;}
else{window.open(fileUri);event.preventDefault();}});for(var i in filesToCapture){var file=filesToCapture[i];if(!file||resourceStore.isCaptured(file))continue;resourceStore.capture(file,function(){});}
if(callback)callback();}};});})();