SearchTermScanner = Class.create();
SearchTermScanner.prototype = {
    initialize: function(curr, tot, foundShotList) {
        this.curr = $(curr);
        this.tot = $(tot);
        this.foundShotList = Boolean(foundShotList);
    },

    load: function(contentId) {
        if (this.parent)
            this.parent.scrollTop = 0;

        if (contentId) {
            this.terms = new Array();
            this.addFonts(contentId);
            //            this.addFonts("parsedShotList");
            //            this.addFonts("parsedCaption");
            //            this.addFonts("rawCaption");

            var total = this.terms.length;
            this.total = total - 1;
            this.current = -1;

            this.curr.update("0");
            this.tot.update(total);
        }

        if (total == 0)
            $("pagingHeader").hide();
        else
            $("pagingHeader").show();
    },

    addFonts: function(divId) {
        var div = $(divId);
        if (div && div.visible()) {
            var terms = $$("#" + divId + " FONT");
            for (var i = 0; i < terms.length; i++) {
                var term = terms[i];
                term.removeClassName("current");
                this.terms.push(term);
            }
        }
    },

    move: function(delta) {
        this.current += delta;
        if (this.current < 0)
            this.current = this.total;
        else if (this.current > this.total)
            this.current = 0;

        if (this.prevNode)
            this.prevNode.removeClassName("current");

        this.prevNode = this.terms[this.current];
        //this.prevNode.scrollTo();
        this.prevNode.addClassName("current");
        this.curr.update(this.current + 1);

        if (!this.parent)
            this.parent = $("one-up-right");
        var max = this.parent.cumulativeOffset().top + this.parent.getHeight();
        var top = this.prevNode.cumulativeOffset().top;
        if (top > max)
            this.parent.scrollTop = (top - max + 32);
        else
            this.parent.scrollTop = 0;
    },

    next: function() { this.move(1); },
    prev: function() { this.move(-1); }
}



AP.OneUpLayout= Class.create();
AP.OneUpLayout.prototype = {
	initialize: function(cfg) {	
      Ext.onReady(function(){
      oneupLayout = new Ext.Panel(
      {
          applyTo : 'oneUpMain',
          layout:'border',
          defaults: {hideMode:'offsets'},
          autoShow:true,
          autoWidth:true,
          cls:'borderless-panel',
          items:[
          new Ext.Panel({
          region:'west',
          width:350,
          split:true,
          items:[
              {contentEl:'hitHeader', cls:'borderless-panel'},
              {contentEl:'oneUpBody', cls:'borderless-panel'}
          ]
      })
      ,
      {
          region:'center',
          split:true,
          layout:'border',
          cls:'borderless-panel',
          width:450,
          items:[
          new Ext.TabPanel({
          region:'center',
          activeTab:0,
          autoScroll:false,
          collapsible: false,
          titlebar: false,
          cls:'borderless-panel',
          items:[
              {contentEl:'videoDetails', title:'Details',layout:'fit',autoScroll:true}
              ,{contentEl:'parsedCaption', title:'Storyline',layout:'fit',autoScroll:true}
              ,{contentEl:'parsedShotList', title:'Shotlist',layout:'fit',autoScroll:true}
              ,{contentEl:'shotListBrowser',title:'Thumbnails',layout:'fit',autoShow:true,autoScroll:true}
              ,{contentEl:'rawCaption',title:'Raw',layout:'fit',autoShow:true,autoScroll:true}
          ]
      }),
      {contentEl:'pagingHeader', region:'south',height:25,cls:'borderless-panel',layout:'fit'}
      ]}
      ,{region:'south',contentEl:'footer',layout:'fit',cls:'borderless-panel'}
      ,{region:'north',contentEl:'oneUpTitle',layout:'fit',cls:'borderless-panel'}
      ],
      Resize:function(e) {
      this.setSize(0, document.viewport.getHeight());
      }
      });

      Ext.EventManager.onWindowResize(oneupLayout.Resize, oneupLayout);
      oneupLayout.Resize();
      });
	}
};
	
