(function()
{
 function ControlError(errorIndex,controlType,elTag)
 {
  var error;
  switch(errorIndex)
  {
   case 1001:
   error=new TypeError('Control type "'+controlType+'" has not been defined for this page [ErrorID:'+errorIndex+"]");
   break;
   default:
   error=new Error("An error has occurred while instantiating "+controlType);
  }
  return error;
 }
 var events=
 {
 }
 ;
 window.Page=
 {
  startTime:new Date(),controls:
  {
  }
  ,queue:[],deferQueue:[],initControl:function(control)
  {
   parseControl(control);
  }
  ,processQueue:function()
  {
   while(Page.queue.length)
   {
    parseControl(Page.queue.shift(),false);
   }
  }
  ,parseFragment:function(node)
  {
   var scripts=YAHOO.util.Dom.getElementsBy(function(el)
   {
    return el.id&&el.id.match(/^control-/);
   }
   ,"script",node);
   for(var i=0;i<scripts.length;i++)
   {
    eval(scripts[i].innerHTML);
   }
   Page.processQueue();
   processDeferQueue();
  }
  ,subscribeToEvent:function(custom,callback)
  {
   events[custom]=events[custom]||[];
   events[custom].push(callback);
  }
  ,publishEvent:function(custom,payload)
  {
   var payload=payload||[];
   if(events&&events[custom]&&events[custom].length>0)
   {
    for(var i=0,len=events[custom].length;
    i<len;
    i++)
    {
     events[custom][i].apply(null,payload);
    }
   }
  }
 }
 ;
 function parseControl(control,isDeferQueue)
 {
  for(scriptId in control)
  {
   var scriptTag=document.getElementById(scriptId);
   var el=YAHOO.util.Dom.getPreviousSibling(scriptTag);
   var validControl=true;
   for(obj in control[scriptId])
   {
    if(window[obj]!==undefined)
    {
     validControl==false;
    }
   }
   if(isDeferQueue==false&&validControl==true)
   {
    for(obj in control[scriptId])
    {
     instantiateObject(el,obj,control[scriptId][obj]);
    }
    var scriptParent=lui.byId(scriptId).parentNode;
    scriptParent.removeChild(scriptTag);
   }
   else
   {
    if(isDeferQueue==false)
    {
     window.Page.deferQueue.push(control[scriptId]);
    }
    else
    {
     for(obj in control[scriptId])
     {
      try
      {
       if(window[obj]==undefined)
       {
        throw new ControlError(1001,controlType);
       }
       else
       {
        instantiateObject(el,obj,control[scriptId][obj]);
       }
      }
      catch(e)
      {
       log.error(e);
      }
     }
     var scriptParent=scriptTag.parentNode;
     scriptParent.removeChild(scriptTag);
    }
   }
  }
 }
 function instantiateObject(el,controlType,controlConfig)
 {
  el.controls=el.controls||
  {
  }
  ;
  log.profile(controlType);
  el.controls[controlType]=new window[controlType](el,controlConfig);
  log.profile(controlType);
  window.Page.controls[controlType]=window.Page.controls[controlType]||[];
  window.Page.controls[controlType].push(el);
 }
 function processDeferQueue()
 {
  while(Page.deferQueue.length)
  {
   parseControl(Page.deferQueue.shift(),true);
  }
 }
 YAHOO.util.Event.on(window,"load",processDeferQueue);
}
)();
window.log=
{
 toggle:function()
 {
 }
 ,move:function()
 {
 }
 ,resize:function()
 {
 }
 ,clear:function()
 {
 }
 ,debug:function()
 {
 }
 ,info:function()
 {
 }
 ,warn:function()
 {
 }
 ,error:function()
 {
 }
 ,profile:function()
 {
 }
 ,init:function()
 {
 }
}
;
window.console=window.console||
{
 log:function()
 {
 }
 ,debug:function()
 {
 }
 ,info:function()
 {
 }
 ,warn:function()
 {
 }
 ,error:function()
 {
 }
 ,assert:function()
 {
 }
 ,dir:function()
 {
 }
 ,dirxml:function()
 {
 }
 ,trace:function()
 {
 }
 ,group:function()
 {
 }
 ,groupEnd:function()
 {
 }
 ,time:function()
 {
 }
 ,timeEnd:function()
 {
 }
 ,profile:function()
 {
 }
 ,profileEnd:function()
 {
 }
 ,count:function()
 {
 }
}
;
