function updateView() {

    // console.log("Updating view...");

    // Implement image mouse-overs
    $$('img.xgmo').each(function(img) {
        var src = img.getProperty('src');
        var extension = src.substring(src.lastIndexOf('.'),src.length)
        img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'-mo' + extension)); });
        img.addEvent('mouseleave', function() { img.setProperty('src',src); });
    });

    $$('input.xgAutoFocus').each(function(el) {
        var doFocus = function() { el.focus(); };
        doFocus.delay(750);
    });

    // initXGEditable();

}

function initXGEditable () {
    // Apply editableability
    $$('[class$=xgeditable]').each(function(el){
        el.getChildren().each(function(sel) {
            sel.contentEditable = "true";
            // Bind key listeners for auto-save
            sel.addEvent('keyup', function(event){
                
                
                var key = event.key;   // returns the lowercase letter pressed.
                
                // Store in database
            });    

        });

    });
    
}

//when the dom is ready...
window.addEvent('domready', function() {
  // Init the xgeditable events
  // initXGEditable();

  //Implement fancy show / hide
  Element.implement({
    //implement show
    fancyShow: function() {
      this.fade('in');
    },
    //implement hide
    fancyHide: function() {
      this.fade('out');
    }
  });
  
  //Implement easyResizing
  Element.implement({
    increaseStyleValueBy: function(styleValue,by,factor) {
        factor = typeof(factor) == 'number' ? factor : 1;        
        var val = parseInt(this.getStyle(styleValue).replace('px',''));
        this.setStyle(styleValue,(val+(factor*by))+"px");
    },
    
    decreaseStyleValueBy: function(styleValue,by,factor) {
        factor = typeof(factor) == 'number' ? factor : 1;
        this.increaseStyleValueBy(styleValue,-1*by,factor);
    }
  });
  
  updateView();

});


function isValidEmailaddress(str) {
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);

    if (str.indexOf(at)==-1){ return false; }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false; }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false; }
    if (str.indexOf(at,(lat+1))!=-1){ return false; }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { return false; }
    if (str.indexOf(dot,(lat+2))==-1) { return false; }
    if (str.indexOf(" ")!=-1) { return false; }

    return true;
}
