var mainLayout = null ;

(function () {
	var loader = new YAHOO.util.YUILoader({
      base: "http://yui.yahooapis.com/2.6.0/build/",
      require: [
        "button", "connection", "container", "cookie", "fonts", "grids",
        "layout", "reset", "resize", "treeview"
      ],
      rollup: true,
      loadOptional: true,
      onSuccess: function() {
        var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event,
            Get = YAHOO.util.Get;
        mainLayout = new YAHOO.widget.Layout({
            units: [
                { position: 'top', height: 64, body: 'top1'},
                { position: 'bottom', header: 'Disclaimer', height: 120, body: 'bottom1', collapse: true, collapseSize: 20, scroll: true },
                { position: 'left', header: 'Categories', scroll: true, width: 200, minWidth: 200, resize: true, body: 'left1', gutter: '5px', collapse: true, collapseSize: 28, animate: true },
                { position: 'center', body: 'center1', gutter: '5px 0px 5px 0px', scroll: true }
            ]
        });
        mainLayout.on('resize', function() {
          var l = this.getUnitByPosition('left');   
          var th = l.get('height') - Dom.get('classTop').offsetHeight;   
          var h = th - 4; //Borders around the 2 areas   
          h = h - 9; //Padding between the 2 parts   
          Dom.setStyle('classTree', 'height', h + 'px');   
        });
        mainLayout.on('render', function() {
            window.setTimeout(function() {
              Get.css('/styles/pictures.css');
              Get.script('/scripts/environment.js', { onSuccess: checkGroup });
              Get.script('/scripts/classtree.js', { onSuccess: checkGroup });
              Get.script('/scripts/bannerad.js');
              Get.script('/scripts/buttons.js');
              Get.script('/scripts/robot.js', { onSuccess: showDisclaimer });
              Get.script('/scripts/loader.js', { onSuccess: loadUSC2257 });
              Get.script('/scripts/group.js', { onSuccess: checkGroup });
              Get.script('/scripts/session.js', { onSuccess: startSession });
            }, 0);
        });
        mainLayout.render();
      }
    });
    loader.insert();
    
    startSession = function() {
      new Session() ;
    };
    loaderAvailable = function() {
      new Loader('disclaimer', '/XHR/disclaimer.html.pl') ;
    };
    loadUSC2257 = function() {
      new Loader('preview', '/usc2257.htm') ;
    };
    loadPrivacy = function() {
      new Loader('preview', '/privacy.htm') ;
    };
    loadGuidelines = function() {
      new Loader('preview', '/guidelines.htm') ;
    };
    loadDisclaimer = function() {
      new Loader('preview', '/disclaimer.htm') ;
    };
    loadDMCA = function(){
      new Loader('preview', '/copyright.htm') ;
    };
    showDisclaimer = function() {
      var Cookie = YAHOO.util.Cookie;
      if (!BrowserDetect || !BrowserDetect.robot)
      {
	var disclaimer = Cookie.get("disclaimer") ;
	if (disclaimer === null || Cookie.get("Session") === null)
	{
	  this.disclaimer = new YAHOO.widget.SimpleDialog("popup", {
	    visible: true,
	    close: false,
	    modal: true,
	    fixedcenter: true,
	    constraintoviewport: true,
	    buttons:
	      [
		{
		  text:"I AGREE",
		  handler:function () {
		    Cookie.set("disclaimer", "shown") ;
		    this.hide();
		  },
		  isDefault:true
		}
	      ]
	    });
	  var iframe = document.createElement("iframe") ;
	  iframe.src = "/XHR/disclaimer.html.pl" ;
	  iframe.setAttribute("width", "480px");
	  iframe.setAttribute("height", "320px");
	  this.disclaimer.setHeader("Disclaimer");
	  this.disclaimer.setBody(iframe);
	  this.disclaimer.render(document.body);
	}
      }
    } ;

    this.checkGroupCounter = 0 ;
    checkGroup = function(){
      this.checkGroupCounter ++ ;
      if (this.checkGroupCounter === 3)
      {
	if (gup("group"))
	{
	  new groupLoader(mainLayout, gup("group")) ;
	}
      }
    };
})();

