/**
 * Browser detection
 */
var browser = {
 
  isIE : false,
  isNS : false,
  isFF : false,
  isOP : false,
  
  // Set the browser variables
  init : function(){
    agt = navigator.userAgent.toLowerCase();
    
    this.isIE  = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.isIE6 = (this.isIE && (agt.indexOf("msie 6") != -1));
    this.isNS  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('firefox')==-1) && (agt.indexOf('hotjava')==-1));
    this.isFF  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('firefox')!=-1) && (agt.indexOf('hotjava')==-1));
    this.isOP  = window.opera;
    
    // Stop background image flicker in IE
    if(this.isIE){
      try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}  
    }
  } 
};
browser.init(); 


/**
 * Page functions
 */
var page = {

  onload : function(){
    
    // Position cursor in search field
    // var sf = document.getElementById("fieldSearch");
    // if(sf) sf.focus();
    
    // Fix netscape bug if center column isn't the longest page element
    if(browser.isNS) {
      var center = document.getElementById("center");  
      var left = document.getElementById("left");  
      var right = document.getElementById("right");  
      
      // Need at least a center element to proceed
      if(center && center.style) {
      
        var cHeight = center.offsetHeight;
        var lHeight = left ? left.offsetHeight : 0;
        var rHeight = right ? right.offsetHeight : 0;
        
        // Adjust center's bottom padding to make it same height as longest column
        if(cHeight < lHeight || cHeight < rHeight) {
          var pad = ((lHeight < rHeight) ? rHeight - cHeight : lHeight - cHeight) + 30;
          center.style.marginBottom = pad + "px";        
        }     
      }
    }
  },
  
  
  // Hovers an element - must have a CSS class with suffix "Hover"
  hover : function(elem){
  
    // Only IE6 and NS need this, everyone else does just fine the :hover pseudoclass
    if(!browser.isIE6 && !browser.isNS) return;  

    if(elem && elem.className){
      var idx = elem.className.indexOf("Hover");
      elem.className = (idx > -1) ? elem.className.substring(0, idx) : elem.className + "Hover";
    }
  }
};



/*
 * Handles Share popup links
 */
var share = {

  digg : function(){  
    document.location = 'http://digg.com/submit?phase=2&url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title); 
    return false;
    
  },
  
  delicious : function(){
    document.location = 'http://del.icio.us/post?v=2&url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title);
    return false;
  }  
  

}

/*
 * Handles Subscription links
 */
var subscribe = {

  rssUrl : "http://www.berlindude.com/berlin.xml",

  rss : function(){
    document.location = this.rssUrl;
    return false;
  },

  google : function(){
    document.location = 'http://www.google.com/reader/preview/*/feed/'+this.rssUrl;
    return false;
  },

  yahoo : function(){
    document.location = 'http://add.my.yahoo.com/rss?url='+this.rssUrl;
    return false;
  },
  
  msn : function(){
    document.location = 'http://my.msn.com/addtomymsn.armx?id=rss&ut='+this.rssUrl;
    return false;
  }



}