/*
	Copyright James Matteson 2011. All rights reserved.
*/
var dataLayer = new function(){
   var oThis = this;
   var myDB;
   var domainCloud = new Hash();
   var tagCloud = new Hash();
      
   if (!window.google || !google.gears) {
      // no gears
      //location.href = "http://gears.google.com/?action=install" +
      //                "&message=<your message>&return=<your url>";
      myDB = new jsDB();
   }else{
      myDB = new gearsDB();
   }
   
   document.observe('site:nogears', function(){
      // the user doesn't want to use gears
      myDB = new jsDB();
      oThis.init();
   });
   
   // global values
   this.getMaxStoryIDs = function(){
      return 10; // 10 is the max # stories that the digg api allows per request
   }
   this.getSQLiteDate = function() {
      var d = new Date();
      return d.getUTCFullYear()+
         "-"+d.getUTCMonth() + 1+
         "-"+d.getUTCDate()+
         "T"+d.getUTCHours()+
         ":"+d.getUTCMinutes()+
         ":"+d.getUTCSeconds()+"."+
         d.getUTCMilliseconds();
   }
   this.createDomainBlacklist = function(id, domain){
      return {
         'id': id,
         'domain': domain
      };
   }
      
   /* must override */
   
   // db functions
   this.init = function(){
      myDB.init();
   }
   this.emptyDB = function(){
      myDB.emptyDB();
   }
   
   // can do
   this.canDisplay = function(storyID, domain){
      return myDB.canDisplay(storyID, domain);
   }
  
   // story queue
   this.getQueue = function(){
      return myDB.getQueue();
   }
   this.enqueue = function(storyID){
      myDB.enqueue(storyID);
   }
   this.dequeue = function(storyID){
      myDB.dequeue(storyID);
   }
   this.getRead = function(lastRowID){
      return myDB.getRead(lastRowID);
   }
   
   // dismissed
   this.dismiss = function(storyID){
      myDB.dismiss(storyID);
   }
   this.dismissToRead = function(storyID){
      myDB.dismissToRead(storyID);
   }
   this.getDismissed = function(lastRowID){
      return myDB.getDismissed(lastRowID);
   }   
   
   // domain blacklist
   this.getDomainBlacklist = function(){
      return myDB.getDomainBlacklist();
   }
   this.addDomainBlacklist = function(domain){
      return myDB.addDomainBlacklist(domain);
   }
   this.removeDomainBlacklist = function(id){
      myDB.removeDomainBlacklist(id);
   }
   this.isDomainBlacklisted = function(domain){
      return myDB.isDomainBlacklisted(domain);
   }
   
   // cloud
   this.clearCloud = function(){
      domainCloud = new Hash();
      tagCloud = new Hash();
   }
   this.addCloud = function(story){
      // todox
      /*var count = domainCloud.get(story.domain);
      domainCloud.set(story.domain, (count == null) ? 1 : count + 1);
      
      $('domains').innerHTML = '';
      domainCloud.keys().sort().each(function(key){
         $('domains').innerHTML += "<p>" + key + " (" + domainCloud.get(key) + ")</p>";
      });*/
   }   
}
