
Components.utils.import("resource://yoono/yoonoPrefs.js");

window.addEventListener("load",function () {
  var state = YOONO_PREFS.get("application.debug.enabled");
  var menu = document.getElementById("debug-menu");
  menu.hidden = !state;
}, false);

function toggleDebug() {
  var state = !YOONO_PREFS.get("application.debug.enabled");
  YOONO_PREFS.set("application.debug.enabled",state)
  var menu = document.getElementById("debug-menu");
  menu.hidden=!state;
}

function test() {
  var iframe = document.getElementById("main-iframe");
  var iframeWin = iframe.contentWindow;
  if (iframeWin.wrappedJSObject)
    iframeWin = iframeWin.wrappedJSObject;
  var sidebar = iframeWin.ynSidebar;
  sidebar.showConfig("signIn");
  var friends = YOONO_CMPT.getYServices().yoodgetInstances.getRegisteredYoodgetWrapper("{friends@yoono.com}",-1);
  friends.friendsSetup.signIn();//showConfig('signin');
return;
  //yoonoGlob.openUrlWithHeaders("http://www.theonion.com/content/news_briefs/report_babe_ruth_was?utm_source=twitterfeed&utm_medium=twitter",[]);
  yoonoGlob.openUrlWithHeaders("http://www.c-est-simple.com/cgi-bin/webdistrib.cgi",[]);
}

function openDOMi() {
  // Load the Window DataSource so that browser windows opened subsequent to DOM
  // Inspector show up in the DOM Inspector's window list.
  var windowDS = Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"]
                                   .getService(Components.interfaces.nsIWindowDataSource);
  var tmpNameSpace = {};                         
  var sl = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
    .createInstance(Components.interfaces.mozIJSSubScriptLoader);
  sl.loadSubScript("chrome://inspector/content/hooks.js", tmpNameSpace);
  tmpNameSpace.inspectDOMDocument(document);
}
function inspect(o) {
  // Load the Window DataSource so that browser windows opened subsequent to DOM
  // Inspector show up in the DOM Inspector's window list.
  var windowDS = Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"]
                                   .getService(Components.interfaces.nsIWindowDataSource);
  var tmpNameSpace = {};                         
  var sl = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
    .createInstance(Components.interfaces.mozIJSSubScriptLoader);
  sl.loadSubScript("chrome://inspector/content/hooks.js", tmpNameSpace);
  tmpNameSpace.inspectObject(o);
}
function inspectObject(o) {
  return inspect(o);
}
function aboutConfig() {
  window.open("chrome://global/content/config.xul", "", "chrome,resizable=yes");
}
function aboutYoono() {
  window.open("chrome://yoono/content/aboutyoono.xul", "", "chrome,resizable=yes");
}
function aboutPlugins() {
  window.open("about:plugins", "", "chrome,resizable=yes");
}
function openConsole() {
  window.open('chrome://global/content/console.xul', '_blank',
			'chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar');
}
function openDebugWidget() {
  var w=YOONO_PREFS.get("application.debug.width") || 300;
  var h=YOONO_PREFS.get("application.debug.height") || 600;
  var x=YOONO_PREFS.get("application.debug.x") || 0;
  var y=YOONO_PREFS.get("application.debug.y") || 0;
  
  var win = window.open('chrome://yoonosb/content/_debug/index.html', '_blank',
        'chrome,resizable,width='+w+',height='+h+",left="+x+",top="+y);

  win.addEventListener("load",function () {
    win.removeEventListener("load",arguments.callee,false);
    
    var script = win.document.createElement("script");
    script.src="../js/yoodget.js";
    win.document.documentElement.appendChild(script);
    
    var script = win.document.createElement("script");
    script.src="js/yoodget.js";
    win.document.documentElement.appendChild(script);
    
    var script = win.document.createElement("script");
    script.src="../js/yloader.js";
    win.document.documentElement.appendChild(script);
    script.onload = function () {
      win.ynWrapper = {};
      win.ynWrapper.loadAPI = function(win, doc, scriptaculousOptions, initMethodName, optionalScripts, optionalCSS) {
        
        win.ynWrapper = {
          isFirstLoad : function () {return false;},
          registerYoodget : function () {
            var iframe = document.getElementById("main-iframe");
            var iframeWin = iframe.contentWindow;
            win.yoodget.YEXTIF = iframeWin.YEXTIF;
            win.yoodget.setHeight(win.innerHeight);
          },
          getKeyValue : function (a) {return YOONO_PREFS.get("debug."+a);},
          setKeyValue : function (a,b) {YOONO_PREFS.set("debug."+a,b);},
          setTitle : function (t) {win.document.title=t;}
        };
        
        win.YoonoLoader.load('../js/yloader.js', win.document.documentElement, scriptaculousOptions, initMethodName, optionalScripts, optionalCSS);
        win.addEventListener("resize",function(){
            win.yoodget.setHeight(win.innerHeight);
        }, false);
      }
      YOONO_CMPT.getYServices().core.initSubDocument(win,"loadYoonoApi",[]);
    };
  }, false);
  win.addEventListener("unload",function (e) {
    if (!e.originalTarget.baseURI.match(/index/)) return;
    win.removeEventListener("unload",arguments.callee,true);
    YOONO_PREFS.set("application.debug.width",win.innerWidth);
    YOONO_PREFS.set("application.debug.height",win.innerHeight);
    YOONO_PREFS.set("application.debug.x",win.screenX);
    YOONO_PREFS.set("application.debug.y",win.screenY);
  }, true);
}
function enableDebugPrefs() {
  var PREFSSERVICE = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  var PREFS = PREFSSERVICE.getBranch(null);
  PREFS.setBoolPref("nglayout.debug.disable_xul_cache", true);
  PREFS.setBoolPref("nglayout.debug.disable_xul_fastload", true);
  PREFS.setBoolPref("extensions.logging.enabled", true);
  PREFS.setBoolPref("dom.report_all_js_exceptions", true);
  PREFS.setBoolPref("browser.dom.window.dump.enabled", true);
  PREFS.setBoolPref("javascript.options.showInConsole", true);
}


