
if(typeof wxVideo == "undefined")wxVideo = {};
wxVideo.n = "wxVideo";
if(typeof wxVideo.actionTrack == "undefined")wxVideo.actionTrack = {};
wxVideo.actionTrack.playlists = false;
wxVideo.actionTrack.pagination = false;
if(typeof wxVideo.currentTopics == "undefined")wxVideo.currentTopics = {};
wxVideo.currentTopics.display = false;
wxVideo.titleLoadedServerSide = false;  //Keeps track of when title and description are loaded serverside
wxVideo.whichBtn = 0; //Keeps track of which Btn is displayed (i.e. Related Videos=0 or Collection=1);
wxVideo.activeCollection = null; // Keeps track of whether currentTopicsObj or collectionObj is active;
wxVideo.DS2Key = "e88d2366-a740-102c-bafd-001321203584"; // Key for accessing DS2 services for intrapage json calls
playClipID = "";

wxVideo.putScript = function(url,fragment){
  if(!wxVideo.headObj)wxVideo.headObj = document.getElementsByTagName('head')[0];
  var script = document.getElementById(fragment + '_targetReq');
  if (script) {
    wxVideo.headObj.removeChild(script);
    delete script;
  }
  script = document.createElement('script');
  script.id = [fragment,'_targetReq'].join('');
  script.type = 'text/javascript';
  script.src = [url];
  wxVideo.headObj.appendChild(script);
};

wxVideo.loadedJS = {};//Keeps track of externally loaded js files
wxVideo.loadJS = function(fileName,mcbs){
  if(!wxVideo.loadedJS[fileName]){
    wxVideo.putScript(["http://j.imwx.com/",mcbs,"/videos/javascript/",fileName,".js"].join(""),fileName);
  }
}

wxVideo.setClipDate = function(lastmodifieddate){
  if(typeof lastmodifieddate == "undefined")return "";
  var months = [null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
  var dateStr = "";
  var ampm = "am ET";
  if(lastmodifieddate != "" && lastmodifieddate.indexOf("-")>0){
    var dateTime = lastmodifieddate.split(" ");
    var date = dateTime[0].split("-");
    var time = dateTime[1].split(":");
    time[0] = parseInt(time[0],10);
    if(time[0] > 12){ time[0] -= 12;ampm = "pm ET"};
    if(time[0] == 12)ampm = "pm ET";
    time[1] = (time[1].length < 2)?["0",time[1]].join(""):time[1];
    var monthInt = date[1];
    if(monthInt.substr(0,1) == "0")monthInt = monthInt.substr(1);
    dateStr = [months[parseInt(monthInt,10)]," ",date[2],", ",date[0],", ",time[0],":",time[1],ampm].join("");
  }else if(parseInt(lastmodifieddate)>0){
     //Have to insert DST check from Java.
     var d = parseInt(lastmodifieddate,10);
     var dd = new Date(d);
     var m = dd.getMonth() + 1;
     var y = dd.getFullYear();
     var day = dd.getDate();
     var h = dd.getHours();
     if(h > 12){h -= 12;ampm = "pm ET"};
     if(h == 12)ampm = "pm ET";
     var min = dd.getMinutes();
     min += "";
     min = (min.length <2)?["0",min].join(""):min;
     dateStr = [months[m]," ",day,", ",y,", ",h,":",min,ampm].join("");
  }
  return dateStr;
}

wxVideo.generateURL = function(title,clipid){
  var url=title.toLowerCase();
  url=url.replace(/[^ \\-_a-z0-9]/g,"");
  url=url.replace(/[\s]+/g,"-");
  if(url.lastIndexOf("-") == url.length-1){
    url=[url,clipid].join("");
  }else{
    url=[url,clipid].join("-");
  }
  return url;
}

wxVideo.setBtn = function(vmObj){
  if(vmObj == "collectionObj"){
    wxVideo.Buttons.toggleBtn(1);
    wxVideo.currentTopics.display = false;
  }else if(vmObj == "currentTopicsObj"){
    wxVideo.Buttons.toggleBtn(1)
    wxVideo.currentTopics.display = true;
  }else{
    wxVideo.Buttons.toggleBtn(0);
    wxVideo.currentTopics.display = false;
  }
}

YAHOO.util.Event.onDOMReady(function(){
  if(typeof wxVideo.omniture_acct == "undefined")wxVideo.omniture_acct = s_account;  //set to production account unless it's already set by pageProps.
  YAHOO.util.Event.on(document.body,"click",function(e){
      var g = YAHOO.util.Event.getTarget(e);
      var errorPage = (typeof wxVideo.videoObj == "undefined")?true:false;
      while((!g.getAttribute("clipid") && !g.getAttribute("subcatid")) && g.parentNode != document.body && g.parentNode != document){
        g = g.parentNode;
      }
      var nn = g.nodeName;
      var clipid = "";
      var subcatid = "";
      if(g.getAttribute("clipid")){
        clipid = g.getAttribute("clipid");
        playClipID = clipid;
      }else{
        subcatid = g.getAttribute("subcatid");
      }
      var vmobj = g.getAttribute("vmobj");
      wxVideo.overrideCollection = true;
      if(vmobj != null && vmobj != "" && vmobj != "popularObj" &&
         vmobj != "recentObj" && vmobj != "collectionObj" && vmobj != "searchObj" &&
         vmobj != "relatedObj" && vmobj != "currentTopicsObj"){
          wxVideo.overrideCollection = false;
      }
      if((nn == "DIV" || nn == "LI") && clipid && vmobj){
        var trak = vmobj.match(/[a-zA-Z]+(?=Obj)/)[0];
        if(errorPage === true){
          try{
            var vm = wxVideo[vmobj];
            var clipObj = null;
            for (var a=0;a<vm.clipArray.length;a++) {
              if (vm.clipArray[a].id == clipid) {
                clipObj = vm.clipArray[a];
                break;
              }
            }
            window.location.href=["/outlook/videos/",clipObj.URL].join("");
          }catch(e){
            // clipObj not found
            //alert("Error finding clipObj to redirect");
            window.location.href="/outlook/videos/0";
          }
        }else{
          wxVideo.activeCollection = wxVideo[vmobj];
          if (vmobj == "popularObj")
	  {
          wxVideo.putScript(["http://wxdata.weather.com/wxdata/video/get.js?fn=getVideoCollection&subcatid=169","&key=",wxVideo.DS2Key,"&cb=",wxVideo.n,".loadCollection"].join(""),"loadCollection");
	  }

          wxVideo[vmobj].playClip(clipid);
        }
      }else if((nn == "DIV" || nn == "LI") && subcatid && vmobj){
        if(wxVideo.actionTrack.playlists){
          vmobj = vmobj.replace(" ","_");
        }
        if(errorPage === true){
          // This should never happen, since there is no playlist module on the error page
          window.location.href = ["/outlook/videos/?subcatid=",subcatid].join("");
        }else{
          wxVideo.putScript(['http://wxdata.weather.com/wxdata/video/get.js?fn=getVideoCollection&subcatid=',subcatid,'&key=',wxVideo.DS2Key,'&cb=wxVideo.playCollection'].join(''),'collection');
        }
      }
    }
  );
});

var videoObj=function(n){this.videoNamespace=n;this.experienceID="";this.currentClipObj="";this.currentMediaID=null;this.playerStopped=false;this.bc={};this.vm={};this.em={};this.cm={};this.me={};if(typeof this.videoNamespace.events=="undefined")this.videoNamespace.events={};var E=this.videoNamespace.events;if(typeof E.onPlayerLoaded=="undefined"){E.onPlayerLoaded=new YAHOO.util.CustomEvent("onPlayerLoaded");}
if(typeof E.onStartOfPlay=="undefined"){E.onStartOfPlay=new YAHOO.util.CustomEvent("onStartOfPlay");}
if(typeof E.onEndOfPlay=="undefined"){E.onEndOfPlay=new YAHOO.util.CustomEvent("onEndOfPlay");}
if(typeof E.onPlayFromBCMenu=="undefined"){E.onPlayFromBCMenu=new YAHOO.util.CustomEvent("onPlayFromBCMenu");}
if(typeof E.onAdStart=="undefined"){E.onAdStart=new YAHOO.util.CustomEvent("onAdStart");}
this.loadBC=function(obj){obj.vm=obj.bc.getModule(APIModules.VIDEO_PLAYER);obj.cm=obj.bc.getModule(APIModules.CONTENT);obj.so=obj.bc.getModule(APIModules.SOCIAL);obj.me=obj.bc.getModule(APIModules.MENU);obj.ad=obj.bc.getModule(APIModules.ADVERTISING);var t=obj;E.onPlayerLoaded.fire(t.currentClipObj);obj.cm.addEventListener(BCContentEvent.MEDIA_LOAD,function(evt){t.playerStopped=false;if(evt.media!==null){t.currentMediaID=evt.media.id;t.me.closeMenuPage();t.vm.setVisible(1);t.vm.loadVideo(evt.media.id);}else{t.playerStopped=true;t.vm.stop();t.vm.setVisible(0);document.title="Video Not Available";var dt=new Date().toString().split(" ");var tm=dt[4].split(":");var ampm="";if(tm[0]>12){tm[0]-=12;ampm="pm ET"};if(tm[0]==12)ampm="pm ET";document.getElementById("title").innerHTML="Video Not Available";document.getElementById("metaTime").innerHTML=[dt[1]," ",dt[2],", ",dt[3],", ",tm.join(":")," ",ampm].join("");document.getElementById("metaDescription").innerHTML="The video your trying to view is unavailable.";document.getElementById("metaClipLink").innerHTML="";}});obj.vm.addEventListener(BCMediaEvent.CHANGE,function(evt){if(t.currentMediaID!=evt.media.id){var url=["http://wxdata.weather.com/wxdata/video/get.js?fn=getVideoClip&clipid=",evt.media.referenceId,"&key=",wxVideo.DS2Key,"&cb=",t.videoNamespace.n,".videoObj.gotClipObj"].join("");t.currentMediaID=evt.media.id;t.currentClipObj=t.convertDtoToVideoObj(evt.media);t.videoNamespace.putScript(url,"currentClip");}
E.onStartOfPlay.fire(t.currentClipObj);});obj.vm.addEventListener(BCMediaEvent.COMPLETE,function(evt){E.onEndOfPlay.fire(t.currentClipObj);});obj.ad.addEventListener(BCAdvertisingEvent.AD_COMPLETE,function(evt){if(t.playerStopped==true){setTimeout(function(){t.vm.stop();t.vm.setVisible(0);},50);}});obj.ad.addEventListener(BCAdvertisingEvent.AD_START,function(evt){E.onAdStart.fire(t.currentClipObj);});};};videoObj.prototype={play:function(c){if(wxVideo.overrideCollection==true){if((c.subcatid>220&&c.subcatid<226)||c.subcatid==165||c.subcatid==166||c.subcatid==261){this.videoNamespace.putScript(["http://wxdata.weather.com/wxdata/video/get.js?fn=getVideoCollection&subcatid=169","&key=",wxVideo.DS2Key,"&cb=",this.videoNamespace.n,".loadCollection"].join(""),"loadCollection");}else if(this.videoNamespace.collectionObj&&c.subcatid!=this.videoNamespace.collectionObj.id){this.videoNamespace.putScript(["http://wxdata.weather.com/wxdata/video/get.js?fn=getVideoCollection&clipid=",c.id,"&key=",wxVideo.DS2Key,"&cb=",this.videoNamespace.n,".loadCollection"].join(""),"loadCollection");}else if(!this.videoNamespace.collectionObj){this.videoNamespace.putScript(["http://wxdata.weather.com/wxdata/video/get.js?fn=getVideoCollection&clipid=",c.id,"&key=",wxVideo.DS2Key,"&cb=",this.videoNamespace.n,".loadCollection"].join(""),"loadCollection");}}
this.currentClipObj=c;this.so.setLink(["http://www.weather.com/outlook/videos/",c.URL,"?from=video_email"].join(""));if(c.subcatid==""){this.videoNamespace.putScript(["http://wxdata.weather.com/wxdata/video/get.js?fn=getVideoClip&clipid=",c.id,"&key=",wxVideo.DS2Key,"&cb=",this.videoNamespace.n,".videoObj.setAdPolicy"].join(""),"loadCollection");}else{this.setAdPolicy(null);}},setAdPolicy:function(json){var lnID="";var c=this.currentClipObj
if(json!=null&&json["class"]!="error"){c.subcatid=json.subcatid;}
var adPolicy=this.videoNamespace.videoObj.ad.getAdPolicy();if(typeof adPolicy!="undefined"&&adPolicy!=null&&adPolicy!=""){if(adPolicy.playerAdKeys.match(/lnID=[0-9]+/)){adPolicy.playerAdKeys=adPolicy.playerAdKeys.replace(/lnID=[0-9]+/,"lnID="+c.subcatid);}else if(adPolicy.playerAdKeys.match(/lnID=/)){adPolicy.playerAdKeys=adPolicy.playerAdKeys.replace(/lnID=/,"lnID="+c.subcatid);}else{adPolicy.playerAdKeys+=[";lnID=",c.subcatid].join("");}
this.videoNamespace.videoObj.ad.setAdPolicy(adPolicy);}
this.cm.getMediaAsynch(c.id,"referenceId");},gotClipObj:function(json){if(json["class"]!="error"){var clip=json;this.currentClipObj=new clipObj(this,clip.clipid,clip.subcatid,clip.URL,clip.title,clip.largethumb,clip.thumb,clip.description,clip.duration,clip.lastmodifieddate,clip.keywords,clip.context,clip.linkTxt,clip.linkURL,clip.shortURL);E.onPlayFromBCMenu.fire(this.currentClipObj);}},convertDtoToVideoObj:function(m){var v=this.videoNamespace.videoObj;var subcatid=m.customFields!=null?m.customFields.subcatid:"";var clipurl=wxVideo.generateURL(m.displayName,m.referenceId);return new clipObj(v,m.referenceId,subcatid,clipurl,m.displayName,m.thumbnailURL,m.thumbnailURL,m.longDescription,m.length,m.lastModifiedDate,m.tags.join(','),m.context,m.linkTxt,m.linkURL,m.shortURL);}};var clipObj=function(v,i,cid,url,t,lt,st,d,du,lmd,k,ctt,ct,cu,su){this.videoObj=v;this.id=i;this.subcatid=cid;this.URL=url;this.title=t||"";this.largeThumb=lt||"http://i.imwx.com/web/blank.gif";this.smallThumb=st||"http://i.imwx.com/web/blank.gif";this.description=d||"";this.duration=du||15000;this.lastmodifieddate=lmd;this.keywords=k;this.context=ctt;this.linkTxt=ct;this.linkURL=cu;this.shortURL=su;};


var metadataObj=function(ns,v,to,d){this.namespace=ns;this.titleObj=document.getElementById(to);this.descriptionObj=document.getElementById(d);this.videoObj=v;var t=this;if(typeof t.namespace.events=="undefined")t.namespace.events={};var E=t.namespace.events;if(typeof E.onStartOfPlay=="undefined")E.onStartOfPLay=new YAHOO.util.CustomEvent("onStartOfPlay");if(typeof E.onPlayFromBCMenu=="undefined")E.onPlayFromBCMenu=new YAHOO.util.CustomEvent("onPlayFromBCMenu");E.onStartOfPlay.subscribe(function(type,args){t.showData(args[0])});E.onPlayFromBCMenu.subscribe(function(type,args){t.showData(args[0])});};metadataObj.prototype={showData:function(co){if(this.namespace.titleLoadedServerSide==false){this.titleObj.innerHTML=co.title;document.title=co.title;YAHOO.util.Dom.get("metaTime").innerHTML=co.context;this.descriptionObj.innerHTML=co.description;window.location.hash=co.id;}else{this.namespace.titleLoadedServerSide=false;}}};

var vmObj = function(n,v,d,w,c,a,cmd,subcatid,ref,trk,vtg,chunkAmount) {
  this.chunkingDiv = (typeof c === "string") ? document.getElementById(c) : c; // vmPaginator div
  this.videoObj = v;
  this.divObj = (typeof d=== "string") ? document.getElementById(d) : d; // container div
  this.divWidth = w;
  this.clipArray = a || [];
  this.command = cmd; //(e.g. find_all_videos&sort_by=MODIFIED_DATE&sort_order=DESC)
  this.id = subcatid; // subcatid of collection if it exists
  this.ref = ref; // (e.g. "recentObj","popularObj","featuredObj")
  this.act_trk = trk;
  var t = this;
  this.name = n;
  this.cwo = {};
  this.url = "";
  this.lastIndxPlayed = -1;
  this.firstIndxPlayed = -1;
  this.collectionComplete = false;
  this.numberOfVideosToGet = vtg || 48;
  this.chunkAmount = chunkAmount;
  this.url1 = "";
  this.url2 = ['http://api.brightcove.com/services/library?command=',this.command,'&page_size=',this.numberOfVideosToGet,'&page_number=0&video_fields=&token=RN-hky_2vRCPyeOOGfOuRYVDuJpl8Xfd13-MFBcU9DI.&callback=',t.name,'.gotVM'].join('');
  
  if(t.clipArray.length == 0){
    this.divObj.innerHTML = "";
    var videoGallery = this.divObj.parentNode;
    YAHOO.util.Dom.addClass(videoGallery,"videoLoading"); // Turn on spinning "loading" icon
    t.getData(t.url2,"related");
  }else{
    t.loadData(t.clipArray);
  }
};
vmObj.prototype = {
  h: document.getElementsByTagName('head')[0],
  getData: function(u,i) {
    var id = [i,'_targetReq'].join('');
    var s = document.getElementById(id);
    if (s) {
      this.h.removeChild(s);
      delete s;
    }
    s = document.createElement('script');
    s.id = id;
    s.type = 'text/javascript';
    s.src = [u];
    this.h.appendChild(s);
  },
  loadData: function(){
    var clips = this.clipArray;
    var parent = this.divObj;
    while(!parent.id.match(/container/)){
      parent = parent.parentNode;
    }
    YAHOO.util.Dom.removeClass(parent,"displayNone");
    var e = this.chunkingDiv;
    e.innerHTML = "";
    this.cwo = new chunkingWidgetObj(this,e,this.divObj,this.clipArray,this.numberOfVideosToGet,"drawClip",this.chunkAmount,this.ref,"initClip")
    this.cwo.init();
  },
  gotVM: function(json) {
    // This json is coming from Brightcove and does not have a json.class property like DS2
    this.clipArray = [];
    this.divObj.innerHTML = "";
    var videoGallery = this.divObj.parentNode;
    YAHOO.util.Dom.removeClass(videoGallery,"videoLoading"); // Turn off spinning icon
    if (json.items && json.items.length && json.items.length > 0 && !json.error) {
      for (var a=0,b=json.items.length;a<b;a++) {
        var c = json.items[a];
        var url = this.videoObj.videoNamespace.generateURL(c.name,c.referenceId);
        var d = new clipObj(this.videoObj,c.referenceId,"",url,c.name,c.thumbnailURL,c.thumbnailURL,c.shortDescription,c.length,c.lastModifiedDate,c.tags,c.context,c.linkText,c.linkURL,c.shortURL);
        this.addClip(d);
      }
    }else{
      this.divObj.innerHTML = ["<div class=\"nocollectionresults\">No related videos were found.</div>"].join("");
      return;
    }
    var e = this.chunkingDiv;
    e.innerHTML = "";
    this.cwo = new chunkingWidgetObj(this,e,this.divObj,this.clipArray,this.numberOfVideosToGet,"drawClip",this.chunkAmount,this.ref,"initClip");
    this.cwo.init();
  },
  addClip: function(c) {
    this.clipArray.push(c);
  },
  playClip: function(clipId) {
    for (var a=0,b=this.clipArray.length;a<b;a++) {
      if (this.clipArray[a].id == clipId) {
        scroll(0,240);
        this.videoObj.play(this.clipArray[a]);
        break;
      }
    }
  }
};
clipObj.prototype.drawClip = function(parentDiv,objName) {
  if(this.imgLoaded === false){
    var a = document.getElementById(["vcid",objName,this.id].join(""));
    a.style.backgroundImage  = "url(" + this.largeThumb + ")";
    this.imgLoaded = true;
  }
};

clipObj.prototype.initClip = function(vmObj,parentDiv,objName,indx){
  var e = indx;
  var t = this;
  var vm = vmObj;
  var startingObjNum = vm.cwo.currentChunk * vm.cwo.chunkAmount;
  var endingObjNum = (vm.cwo.currentChunk === vm.cwo.numberOfChunks - 1)? vm.cwo.dataArray.length - 1 : startingObjNum + vm.cwo.chunkAmount - 1;
  var videoGalleryContent = document.createElement("div");
  YAHOO.util.Dom.addClass(videoGalleryContent,"videoGalleryContent wxClickable");
  videoGalleryContent.setAttribute("vmobj",objName);
  videoGalleryContent.setAttribute("clipid",t.id);
  var videoContent = document.createElement("div");
  YAHOO.util.Dom.addClass(videoContent,"video-block");
  var videoImage = document.createElement("div");
  YAHOO.util.Dom.addClass(videoImage,"video-image");
  videoImage.setAttribute("id",["vcid",objName,this.id].join(""));
  var videoDesc = document.createElement("div");
  YAHOO.util.Dom.addClass(videoDesc,"videoDesc");
  var videoDescLink = document.createElement("div");
  YAHOO.util.Dom.addClass(videoDescLink,"wxClickable");
  videoDescLink.appendChild(document.createTextNode(this.title));
  videoDesc.appendChild(videoDescLink);
  videoContent.appendChild(videoImage);
  videoContent.appendChild(videoDesc);
  videoGalleryContent.appendChild(videoContent);
  parentDiv.appendChild(videoGalleryContent);
};

var chunkingWidgetObj = function(vm,d,t,e,s,m,a,i,n) {
  var YUD = YAHOO.util.Dom;
  this.vmObj = vm;
  this.containerObj = (typeof d === "string") ? YUD.get(d) : d;
  this.targetObj = (typeof t === "string") ? YUD.get(t) : t;
  this.targetMethodName = m;
  this.targetInitMethodName = n || function(){};
  this.dataArray = e;
  this.numberToDisplay = s;
  this.chunkAmount = (typeof a === "string") ? parseInt(a) : a;
  this.imageBase = "http://i.imwx.com/web/video/th-loading-140x79.gif";
  this.imageExt = ".png";
  this.LarrowSelected = "videoPArrowL wxClickable";
  this.LarrowNotSelected = "videoPArrowLN";
  this.RarrowSelected = "videoPArrowR wxClickable";
  this.RarrowNotSelected = "videoPArrowRN";
  this.chunkSelected = "videoPDotSelect";
  this.chunkNotSelected = "videoPDot";
  this.widgetId = i;
  var arrayLength = this.dataArray.length > this.numberToDisplay ? this.numberToDisplay : this.dataArray.length;
  this.numberOfChunks = (parseInt(arrayLength / this.chunkAmount)) + ((arrayLength % this.chunkAmount > 0) ? 1 : 0);
  this.currentChunk = 0;
  this.chunkChunkObjArray = [];
  this.leftArrowObj = null;
  this.rightArrowObj = null;
  this.widgetWidth = this.vmObj.divWidth;
  this.currentWidgetWidth = "";
  this.slot = this.containerObj.id.match(/[0-9]+/)[0];
  this.smol = YUD.get(['showMoreOrLess',this.slot].join(''));
  this.pg = YUD.get(['vmPaginator',this.slot].join(''));
  this.anm = null; //animation object for module
  this.clicked = false; // used to prevent double-click on pagination
};

chunkingWidgetObj.prototype = {
  init: function(){
    var t = this;
    YAHOO.util.Event.on(this.smol,"click",this.showMoreOrLess,null,this);

    var dotContainer = document.createElement("DIV");
    YAHOO.util.Dom.addClass(dotContainer,"dotContainerClass");

    for (var a=0;a<this.numberOfChunks;a++) {
      var dot = document.createElement("DIV");
      dot.setAttribute("id",[this.widgetId,"_chunk",a].join(''));
      var state = (a===0)? this.chunkSelected:this.chunkNotSelected;
      YAHOO.util.Dom.addClass(dot,state);
      this.chunkChunkObjArray.push(dot);
      dotContainer.appendChild(dot);
      dot.onclick=function(){
        if(t.clicked == false){
          t.clicked = true;
          if(t.vmObj.videoObj.videoNamespace.actionTrack.pagination){
            sc_trackAction(this,"video_pagination_click",wxVideo.omniture_acct); 
          }
          var e = this.id.match(/chunk(\d+)/);
          var f = parseInt(e[1]);
          t.gotoChunk(f);
        }
      };
      dot.onmouseover=function(){
        YAHOO.util.Dom.replaceClass(this.id,"videoPDot","videoPDotMo");
      };
      dot.onmouseout=function(){
        YAHOO.util.Dom.replaceClass(this.id,"videoPDotMo","videoPDot");
      }
    }

    var arrowsContainer = document.createElement("DIV");
    YAHOO.util.Dom.addClass(arrowsContainer,"arrowsContainerClass");

    var Larrow = document.createElement("DIV");
    YAHOO.util.Dom.addClass(Larrow,"videoPArrowLN");
    Larrow.setAttribute("id",[this.widgetId,"_left"].join(''));
    arrowsContainer.appendChild(Larrow);
    this.leftArrowObj = Larrow;
    Larrow.onclick = function(){
      if(t.clicked == false){
        t.clicked = true;
        if(t.vmObj.videoObj.videoNamespace.actionTrack.pagination){
          sc_trackAction(this,"video_pagination_click",wxVideo.omniture_acct); 
        }
        t.prevChunk();
      }
    };
    Larrow.onmouseover = function(){
      var YUD = YAHOO.util.Dom;
      var prevClass = YUD.hasClass(this,"videoPArrowLN") ? "videoPArrowLN" : "videoPArrowL";
      if(prevClass != "videoPArrowLN"){
        YUD.replaceClass(this,prevClass,"videoPArrowLMo");
        this.setAttribute("prevClass",prevClass);
      }
    }
    Larrow.onmouseout = function(){
      var YUD = YAHOO.util.Dom;
      var replacementClass = this.getAttribute("prevClass");
      if(YUD.hasClass(this,"videoPArrowLMo")){
        YUD.replaceClass(this,"videoPArrowLMo",replacementClass);
      }
    }
    var Rarrow = document.createElement("DIV");
    Rarrow.setAttribute("id",[this.widgetId,"_right"].join(''));
    var d = (this.numberOfChunks <= 1) ? this.RarrowNotSelected : this.RarrowSelected;
    YAHOO.util.Dom.addClass(Rarrow,d);

    arrowsContainer.appendChild(Rarrow);
    this.rightArrowObj = Rarrow;
    if(typeof wxVideo.events == "undefined")wxVideo.events = {};
    var E = wxVideo.events;
    if(typeof E.onStartOfPlay == "undefined")E.onStartOfPlay = new YAHOO.util.CustomEvent("onStartOfPlay");
    E.onStartOfPlay.subscribe(function(type,args){
	var clipObj = args[0];
	var keywordChunk = clipObj.keywords.substring(clipObj.keywords.length-12,clipObj.keywords.length);
	if (keywordChunk.match("Default")) {
		var chunkingValue = clipObj.keywords.substring(clipObj.keywords.lastIndexOf("Default"));
		var RarrowIDString = "";
		RarrowIDString = Rarrow.getAttribute("id");
		if (RarrowIDString == "collectionObj_right")
		{
		   if(t.currentChunk != parseInt(chunkingValue.substring(7)))
			t.gotoChunk(parseInt(chunkingValue.substring(7)));
		}
	}
    });

    Rarrow.onclick=function(){
      if(t.clicked == false){
        t.clicked = true;
        if(t.vmObj.videoObj.videoNamespace.actionTrack.pagination){
          sc_trackAction(this,"video_pagination_click",wxVideo.omniture_acct); 
        }
        t.nextChunk();
      }
    };
    Rarrow.onmouseover = function(){
      var YUD = YAHOO.util.Dom;
      var prevClass = YUD.hasClass(this,"videoPArrowRN") ? "videoPArrowRN" : "videoPArrowR";
      if(prevClass != "videoPArrowRN"){
        YUD.replaceClass(this,prevClass,"videoPArrowRMo");
        this.setAttribute("prevClass",prevClass);
      }
    }
    Rarrow.onmouseout = function(){
      var YUD = YAHOO.util.Dom;
      var replacementClass = this.getAttribute("prevClass");
      if(YUD.hasClass(this,"videoPArrowRMo")){
        YUD.replaceClass(this,"videoPArrowRMo",replacementClass);
      }
    }

    this.containerObj.appendChild(arrowsContainer);
    this.containerObj.appendChild(dotContainer);

    this.drawChunks(this.targetObj,this.widgetId);
    setTimeout(function(){t.showChunk(0);},50);
     if(this.widgetId == "collectionObj") {
	if(wxVideo.whichBtn == 0) {
           wxVideo.whichBtn = 1;
	}
	var chunkIndex = 0;
	for(var i=0;i<this.dataArray.length;i++) {
	    if(this.dataArray[i].id == playClipID){
	       if(t.currentChunk != parseInt(i/6)) {
	          chunkIndex = parseInt(i/6);
                  break;
	          }
                }
	     }
	t.gotoChunk(chunkIndex);
     }
    if(linkAttribute != null) {
      if (this.widgetId == "popularObj" && linkAttribute == "most_popular") {
		t.showMore();
		var scrollTop = YAHOO.util.Dom.getY("container4");
		window.scrollTo(0,scrollTop);
      }
      if (this.widgetId == "recentObj" && linkAttribute == "most_recent")
      {
		t.showMore();
		var scrollTop = YAHOO.util.Dom.getY("container3");
		window.scrollTo(0,scrollTop);
      }
    }
    return this;
  },
  turnChunkOn: function(c){
    this.chunkChunkObjArray[c].className = this.chunkSelected;
  },
  turnChunkOff: function(c){
    this.chunkChunkObjArray[c].className = this.chunkNotSelected;
  },
  turnLeftOn: function(){
    this.leftArrowObj.className = this.LarrowSelected;
  },
  turnLeftOff: function(){
    this.leftArrowObj.className = this.LarrowNotSelected;
  },
  turnRightOn: function(){
    this.rightArrowObj.className = this.RarrowSelected;
  },
  turnRightOff: function(){
    this.rightArrowObj.className = this.RarrowNotSelected;
  },
  drawChunks:function(parentDiv,objName){
    this.targetObj.innerHTML = "";
    var thisVmObj = this.vmObj;
    for (var a=0;a<this.dataArray.length;a++) {
      this.dataArray[a].imgLoaded = false;
      this.dataArray[a][this.targetInitMethodName](thisVmObj,parentDiv,objName,a);
    }
  },
  showChunk: function(c){
    var t = this;
    var startingObjNum = this.currentChunk * this.chunkAmount;
    var endingObjNum = (this.currentChunk === this.numberOfChunks - 1) ? this.dataArray.length - 1 : startingObjNum + this.chunkAmount - 1;
    //this.targetObj.innerHTML = "";
    for (var a=startingObjNum;a<=endingObjNum;a++) {
      this.dataArray[a][this.targetMethodName](this.targetObj,this.widgetId);
    }
    var tcc = this.currentChunk;
    var to = this.targetObj;
    var tw = this.currentWidgetWidth =(this.currentChunk + 1) * this.widgetWidth;
    if(tw > parseInt(YAHOO.util.Dom.getStyle(to,"width"))){
      YAHOO.util.Dom.setStyle(to,"width",tw + "px");
    }
    if(this.anm == null){
      this.anm = new YAHOO.util.Anim(to,{left:{to:(tcc*-this.widgetWidth)}},.2);
			this.anm.onComplete.subscribe(function(){
				YAHOO.util.Dom.setStyle(to,"width",t.currentWidgetWidth + "px");
				t.clicked = false;
			});
    }else{
      this.anm.attributes.left.to =tcc*-this.widgetWidth;
    }
    this.anm.animate();
  },
  showMore: function(){
    var YUD = YAHOO.util.Dom;
    var videoGallery = YUD.get(this.targetObj).parentNode;
    if(YUD.hasClass(this.smol,"videoPShowA")){
      YUD.replaceClass(this.smol,"videoPShowA","videoPShowL");
      YUD.addClass(this.pg,"displayNone");
      this.currentWidgetWidth = YAHOO.util.Dom.getStyle(this.targetObj,"width");
      YUD.setStyle(this.targetObj,"width",[this.widgetWidth,"px"].join(""));
      YUD.setStyle(this.targetObj,"left","0px");
      for(var a=0;a<this.dataArray.length;a++){
        this.dataArray[a][this.targetMethodName](this.targetObj,this.widgetId);
      }
      YUD.replaceClass(videoGallery,"videoGallery","videoGalleryShowAll");
      //YUD.setStyle(videoGallery,"height","auto");
    }
  },
  showMoreOrLess: function(){
    var YUD = YAHOO.util.Dom;
    var videoGallery = YUD.get(this.targetObj).parentNode;
    if(YUD.hasClass(this.smol,"videoPShowA")){
      YUD.replaceClass(this.smol,"videoPShowA","videoPShowL");
      YUD.addClass(this.pg,"displayNone");
      this.currentWidgetWidth = YAHOO.util.Dom.getStyle(this.targetObj,"width");
      YUD.setStyle(this.targetObj,"width",[this.widgetWidth,"px"].join(""));
      YUD.setStyle(this.targetObj,"left","0px");
      for(var a=0;a<this.dataArray.length;a++){
        this.dataArray[a][this.targetMethodName](this.targetObj,this.widgetId);
      }
      YUD.replaceClass(videoGallery,"videoGallery","videoGalleryShowAll");
      YUD.setStyle(videoGallery,"height","1%");
    }
    else{
      YUD.replaceClass(this.smol,"videoPShowL","videoPShowA");
      YUD.removeClass(this.pg,"displayNone");
      YUD.setStyle(this.targetObj,"width",this.currentWidgetWidth);
      YUD.replaceClass(videoGallery,"videoGalleryShowAll","videoGallery");
      YUD.setStyle(videoGallery,"height","135px");
      this.showChunk(this.currentChunk);
    }
  },
  nextChunk: function(){
    if (this.currentChunk < this.numberOfChunks - 1) {
      this.turnChunkOff(this.currentChunk);
      this.currentChunk++;
      this.turnChunkOn(this.currentChunk);
      this.updateArrows();
      this.showChunk(this.currentChunk);
    }else{
      this.clicked = false;
    }
  },
  updateArrows: function(){
    if (this.currentChunk === 0) {
      this.turnLeftOff();
    } else {
      this.turnLeftOn();
    }
    if (this.currentChunk === this.numberOfChunks - 1) {
      this.turnRightOff();
    } else {
      this.turnRightOn();
    }
  },
  prevChunk: function(){
    if (this.currentChunk > 0) {
      this.turnChunkOff(this.currentChunk);
      this.currentChunk--;
      this.turnChunkOn(this.currentChunk);
      this.updateArrows();
      this.showChunk(this.currentChunk);
    }else{
      this.clicked = false;
    }
  },
  gotoChunk: function(c){
    if (this.chunkChunkObjArray[c] && this.currentChunk !== c) {
      this.turnChunkOff(this.currentChunk);
      this.currentChunk = c;
      this.turnChunkOn(this.currentChunk);
      this.updateArrows();
      this.showChunk(this.currentChunk);
    }else{
      this.clicked = false;
    }

  }
};
