var $BIMWO=jQuery.noConflict(),BIMWONJS;BIMWONJS||(BIMWONJS={});BIMWONJS.viewModel=null;BIMWONJS.counter=1;BIMWONJS.SetAccordian=function(n,t){$BIMWO.getJSON(n,function(n){BIMWONJS.viewModel=ko.mapping.fromJS(n);ko.applyBindings(BIMWONJS.viewModel,$BIMWO("#firstSection")[0]);BIMWONJS.FillAccordian(t)}).fail(function(n,t,i){var r=t+", "+i})};BIMWONJS.createDetails=function(n){var t=$BIMWO("<div>").attr("id",n),i=$BIMWO("<div>").attr("data-bind","template: { name: 'parentTabTemplate',data: ChannelList()[0]} ");return t.append(i),t};BIMWONJS.FillDetailsTable=function(n,t,i){var r;t.attr("loaded","true");var f=n.attr("tabId"),o=BIMWONJS.viewModel.Stations.Station()[f].regKey(),u=BIMWONJS.viewModel.Stations.Station()[f].type(),e=3;try{e=BIMWONJS.viewModel.Stations.showCount()}catch(s){}u=u=="NS"?1:2;r="PTNS"+BIMWONJS.counter++;t.prepend(BIMWONJS.createDetails(r));document.addEventListener?$BIMWO("#"+r).bind("DOMNodeInserted",function(n){n.type=="DOMNodeInserted"&&($BIMWO("#"+r).next().remove(),$BIMWO("#"+r).unbind("DOMNodeInserted"))}):$BIMWO("#"+r).next().remove();$BIMWO("#"+r).ttvGuide({serviceType:u,registrationKey:o,elementId:r,qa:i,showCount:e})};BIMWONJS.FillAccordian=function(n){$BIMWO(".accordion h4").click(function(){$BIMWO(".showMe").slideToggle("fast").removeClass("showMe");$BIMWO(".accordion h4").removeClass("on");$BIMWO(".accordionContent").slideUp("swing");var t=$BIMWO(this).next();t.is(":hidden")==!0&&($BIMWO(this).addClass("on"),t.attr("loaded")!="true"&&BIMWONJS.FillDetailsTable($BIMWO(this),t,n),t.slideDown("swing"))});$BIMWO(".accordionContent").hide();$BIMWO(".accordion h4:first").click().addClass("on")};BIMWONJS.showMe=function(n){var t=$BIMWO(n).find("div:nth-child(2)");if(t.is(":visible")){t.removeClass("showMe");t.slideToggle("fast");return}var i=$BIMWO(n).parent().parent(),r=i.position().top,u=i.position().left,f=i.height()+50;t.css({top:r,left:u,width:285,height:f}).addClass("showMe");t.slideToggle("swing")};Date.prototype.format=function(n){var i=this,u=i.getDate(),f=i.getMonth()+1,r=i.getFullYear(),t=i.getHours(),e=i.getMinutes(),o=i.getSeconds();return n||(n="MM/dd/yyyy"),n=n.replace("MM",f.toString().replace(/^(\d)$/,"0$1")),n.indexOf("yyyy")>-1?n=n.replace("yyyy",r.toString()):n.indexOf("yy")>-1&&(n=n.replace("yy",r.toString().substr(2,2))),n=n.replace("dd",u.toString().replace(/^(\d)$/,"0$1")),n.indexOf("T")>-1&&(n=t>11?n.replace("T","PM"):n.replace("T","AM")),n.indexOf("HH")>-1&&(n=n.replace("HH",t.toString().replace(/^(\d)$/,"0$1"))),n.indexOf("hh")>-1&&(t>12&&(t-=12),t===0&&(t=12),n=n.replace("hh",t.toString().replace(/^(\d)$/,"0$1"))),n.indexOf("mm")>-1&&(n=n.replace("mm",e.toString().replace(/^(\d)$/,"0$1"))),n.indexOf("ss")>-1&&(n=n.replace("ss",o.toString().replace(/^(\d)$/,"0$1"))),n},function(n){return n.fn.ttvGuide=function(t){var i=n.extend({serviceType:1,registrationKey:null,showCount:3,guideUrl:null,elementId:null,sectionName:"",qa:!1,complete:null},t),u="http://titantvguide.titantv.com/apg/ttv.aspx?siteid=",f=function(n){var t=this;ko.mapping.fromJS(n,{},this);t.SectionName=i.sectionName;t.TitanTVGuideUrl=ko.computed(function(){return i.guideUrl?i.guideUrl:u+t.SiteId()});t.PrettyTime=function(n){n=n().split(":");var t=new Date;return t.setHours(n[0]),t.setMinutes(n[1]),t.format("hh:mm T")};t.PrettyDate=function(n){var r=n().slice(0,4),u=n().slice(4,6),f=n().slice(6),t,i;return n=new Date(r,u-1,f),t=", ",i=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][n.getDay()],i+(t+n.format("MM/dd"))};t.PrettyDuration=function(n){var t,i;return n=n().split(":"),t="",n[0]>0&&(t=parseInt(n[0])+" hr"+(n[0]==1?" ":"s ")),i="",n[1]>0&&(i=parseInt(n[1])+" min"),t+i};t.IsStreaming=function(n){return n!=null?!0:!1};t.FormatRepeat=function(n){return n()=="W"?"New":n()=="Y"?"Repeat":""};t.FormatCategory=function(n){return n().replace("/",", ","g")};this.DisplayLine=ko.computed(function(){})};n.isFunction(i.complete)&&i.complete.call(this);var e=i.qa?"qa.":"",o="https:"==document.location.protocol,r=(o?"https:":"http:")+"//"+e+"webservices.titantvguide.titantv.com/contentblocks.asmx/";r+=i.serviceType==1?"NowShowingJSON":"TonightOnJSON";r+="?registrationKey="+i.registrationKey;i.serviceType==1&&(r+="&showCount="+i.showCount);r+="&callback=?";n.ajax({type:"GET",url:r,dataType:"json",crossDomain:!0,jsonp:!0,cache:!1,success:function(n){n.Error=="OK"&&ko.applyBindings(new f(n),document.getElementById(i.elementId))},error:function(n){console.log("Fail "+n.status+" ")}})},this}(jQuery)