(function(D){D.fn.jCarouselLite=function(E){E=D.extend({btnPrev:null,btnNext:null,btnGo:null,mouseWheel:false,auto:null,speed:200,easing:null,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null},E||{});
return this.each(function(){var N=false,L=E.vertical?"top":"left",G=E.vertical?"height":"width";
var F=D(this),P=D("ul",F),I=D("li",P),T=I.size(),S=E.visible;
if(E.circular){P.prepend(I.slice(T-S-1+1).clone()).append(I.slice(0,S).clone());
E.start+=S;
}var R=D("li",P),O=R.size(),U=E.start;
F.css("visibility","visible");
R.css({"overflow":"hidden","float":(E.vertical?"none":"left")});
P.css({"margin":"0","padding":"0","position":"relative","list-style-type":"none","z-index":"1"});
F.css({"overflow":"hidden","position":"relative","z-index":"1","left":"0px"});
var K=E.vertical?A(R):C(R);
var Q=K*O;
var M=K*S;
R.css({width:R.width(),height:R.height()});
P.css(G,Q+"px").css(L,-(U*K));
F.css(G,M+"px");
if(E.btnPrev){D(E.btnPrev).click(function(){return J(U-E.scroll);
});
}if(E.btnNext){D(E.btnNext).click(function(){return J(U+E.scroll);
});
}if(E.btnGo){D.each(E.btnGo,function(V,W){D(W).click(function(){return J(E.circular?E.visible+V:V);
});
});
}if(E.mouseWheel&&F.mousewheel){F.mousewheel(function(V,W){return W>0?J(U-E.scroll):J(U+E.scroll);
});
}if(E.auto){setInterval(function(){J(U+E.scroll);
},E.auto+E.speed);
}function H(){return R.slice(U).slice(0,S);
}function J(V){if(!N){if(E.beforeStart){E.beforeStart.call(this,H());
}if(E.circular){if(V<=E.start-S-1){P.css(L,-((O-(S*2))*K)+"px");
U=V==E.start-S-1?O-(S*2)-1:O-(S*2)-E.scroll;
}else{if(V>=O-S+1){P.css(L,-((S)*K)+"px");
U=V==O-S+1?S+1:S+E.scroll;
}else{U=V;
}}}else{if(V<0||V>O-S){return ;
}else{U=V;
}}N=true;
P.animate(L=="left"?{left:-(U*K)}:{top:-(U*K)},E.speed,E.easing,function(){if(E.afterEnd){E.afterEnd.call(this,H());
}N=false;
});
if(!E.circular){D(E.btnPrev+","+E.btnNext).removeClass("disabled");
D((U-E.scroll<0&&E.btnPrev)||(U+E.scroll>O-S&&E.btnNext)||[]).addClass("disabled");
}}return false;
}});
};
function B(E,F){return parseInt(D.css(E[0],F))||0;
}function C(E){return E[0].offsetWidth+B(E,"marginLeft")+B(E,"marginRight");
}function A(E){return E[0].offsetHeight+B(E,"marginTop")+B(E,"marginBottom");
}})(jQuery);




Lightbox=Backbone.View.extend({events:{"click a[bax\\:sub=close]":"close","click .lightbox":"maybeClose"},initialize:function(A){_.bindAll(this);
this._counter=0;
$(document).bind("bax:lightbox",this.showLightbox);
},maybeClose:function(A){if(A.target===this.el[0]){this.close(A);
}},close:function(A){this._contained=null;
this._content.empty();
this.el.hide();
this._content.hide();
this._closeContainer.hide();
$(document.body).css({"overflow-y":this._origOverflow});
$(document).unbind("keydown",this._boundKeydown).unbind("mousemove",this._boundMousemove);
window.clearInterval(this._intervalTimer);
$(this._triggerTarget).trigger("bax:close");
},onInterval:function(){this._counter=(this._counter+1)%8;
if(0===this._counter){this._close.addClass("idle");
}},onMouseMove:function(A){this._counter=0;
this._close.removeClass("idle");
},showLightbox:function(C,B){this._triggerTarget=C.target;
var A=$(document.body);
this._origOverflow=A.css("overflow-y");
A.css({"overflow-y":"hidden"});
if(!this._content){this.initLightbox();
}this._content.show();
this._closeContainer.show();
this._content.empty().html(this._contained=B);
this._boundKeydown=$.proxy(this.keyboard,this);
this._boundMousemove=$.proxy(this.onMouseMove,this);
$(document).bind("keydown",this._boundKeydown).bind("mousemove",this._boundMousemove);
this._intervalTimer=window.setInterval($.proxy(this.onInterval,this),250);
this.el.show();
},initLightbox:function(){var A=this;
this._content=$("<div></div>").addClass("content");
this._close=$("<a></a>").addClass("button close animated fast").attr("bax:sub","close");
this._closeContainer=$("<div></div>").addClass("content closeContainer right").append(this._close);
this.el=new ScreenOverlay().el.append(this._closeContainer).append(this._content).appendTo(document.body);
},keyboard:function(B){if(!$(this.el).hasClass("hidden")){if(27===B.keyCode){B.preventDefault();
this.close(B);
}else{if(this._contained){var A=new jQuery.Event("bax:key",{keyCode:B.keyCode});
$(this._contained).trigger(A);
}}}}});
ScreenOverlay=Backbone.View.extend({initialize:function(A){_.bindAll(this);
this.el=ScreenOverlay.instance;
if(!this.el){this.init(A);
}else{this.el.show();
}},init:function(){this.el=ScreenOverlay.instance=$("<div></div>").addClass("lightbox").appendTo(document.body);
},show:function(){this.el.show();
},hide:function(){this.el.hide();
}});
(function(){var A={};
$(document).bind("bax:modal",function(C,B){B.eventCaller=$(C.target);
if(A[C.target.id]==undefined){A[C.target.id]=new Modal(B);
}A[C.target.id].showModal(B);
});
})();
Modal=Backbone.View.extend({events:{"click a[bax\\:sub~=close]":"close","bax:modalClose":"close","bax:recenter":"onrecenter"},onrecenter:function(B,A){var C={};
if(A.width){C.overrideWidth=A.width;
}if(A.height){C.overrideHeight=A.height;
}this.center(this.modal,C);
},initialize:function(A){_.bindAll(this);
this.eventCaller=A.eventCaller;
this.options=A;
},showModal:function(D){var B=this;
if(!this.overlay){this.overlay=new ScreenOverlay();
}var C=this.overlay;
if(!this.modal){this.modal=$("<div></div>").addClass("modalContainer").appendTo(document.body).css({width:D.width||"auto",height:D.height||"auto",zIndex:parseInt(this.overlay.el.css("zIndex"),10)+1});
}this.modal.html(this.el);
var E=this.modal;
if(undefined===D.closeButton||!!D.closeButton){if(!this.modalClose){this.modalClose=$('<a href="#"><i class="icon modal close topRight"></i></a>').attr("role","button").prependTo(this.el);
}this.modalClose.click(this.close);
}else{this.modalClose=null;
}if(undefined===D.closeOnClick||!!D.closeOnClick){C.el.click(this.close);
}var A=$(document.body);
this._origPos=A.css("position");
A.css({"position":"static"});
this.center(E);
this.overlay.show();
this.modal.show();
if(this.modalClose){this.modalClose.show();
}},close:function(A){this.overlay.hide();
this.modal.hide();
$(document.body).css({"position":this._origPos});
if(this.eventCaller){var B={};
if(A){B.target=A.target;
}$(this.eventCaller).trigger("bax:close",B);
}return false;
},closeChrome:function(A){this.modal.hide();
},open:function(){this.showModal(this.options);
this.overlay.show();
this.modal.show();
},center:function(C,E){var A=C.is(":visible");
if(!A){C.show();
}this.modal.css({top:"50%",left:"50%"});
var D=Math.min(this.$el.width(),$(window).width());
var B=Math.min(this.$el.height(),$(window).height());
D=(D/2)*-1;
B=(B/2)*-1;
this.$el.css({"position":"relative","left":D+"px","top":B+"px"});
}});




RT.Backbone.Views.HoverBubble=Backbone.View.extend({initialize:function(){_.bindAll(this);
_.templateSettings={interpolate:/\{\{([\s\S]+?)\}\}/g,evaluate:/\{%([\s\S]+?)%\}/g};
this.hoverBubbleTmpl=$(this.$el).find(".hoverBubbleTmpl").html();
this.removeTimeout=null;
},events:{"mouseenter .movie_list tr":"onmouseenterRow","mouseleave .movie_list tr":"onmouseleaveRow","mouseenter .hoverBubble":"onmouseenterBubble","mouseleave .hoverBubble":"onmouseleaveBubble","click .movie_list tr":"clickRow"},onmouseenterRow:function(B){var A=this;
var C=$(B.currentTarget);
if(C.data("bubble")){this.cancelRemoveHoverBubble(C.data("bubble"));
}else{this.renderHoverBubble(C);
}},onmouseleaveRow:function(A){this.removeHoverBubble($(A.currentTarget).data("bubble"),true);
},clickRow:function(A){this.removeHoverBubble($(A.currentTarget).data("bubble"),true);
},onmouseenterBubble:function(A){this.cancelRemoveHoverBubble($(A.currentTarget));
},onmouseleaveBubble:function(A){this.removeHoverBubble($(A.currentTarget));
},renderHoverBubble:function(J){var C=220;
var I=170;
var F=J.position();
unit=this.$ele;
var G,B;
if(J.position().top<I){B=J.position().top;
G=0;
}else{if(J.offset().top+(C-I)>$(window).scrollTop()+$(window).height()){B=(J.offset().top-$(window).scrollTop())-$(window).height()+C;
G=F.top-B;
}else{G=F.top-I;
B=I;
}}var H=J.data("movie-id");
var A=J.data("season-id");
var D=$('<div class="hoverBubble fade in"></div>');
D.css("top",G);
D.data("row",J);
D.prepend("<style>.hoverBubble .bubbleContent:before { top:"+B+"px; } .hoverBubble .bubbleContent:after { top:"+(B+1)+"px; }</style>");
this.$el.append(D);
J.data("bubble",D);
var E=this;
if(H){RT.ord.movies.getCurrentUserRating(H).deferred.done(function(K){var L=$(_.template(E.hoverBubbleTmpl,K.media));
D.append(L);
E.initRatingWidget(D);
});
}else{RT.ord.tvSeasons.getCurrentUserRating(A).deferred.done(function(K){var L=$(_.template(E.hoverBubbleTmpl,K.media));
D.append(L);
E.initRatingWidget(D);
});
}},initRatingWidget:function(A){var B=A.find(".rating_widget");
B.data("ratingView",new RT.Backbone.Views.RatingWidget({el:B}));
B.data("fbView",new RT.Backbone.Views.FacebookManager({el:B}));
console.log("Activating Rating Widget (Hover)");
},removeHoverBubble:function(A,B){if(A!=undefined){if(B){A.hide();
}else{A.removeClass("in");
}A.data("removeTimeout",setTimeout(function(){if(A.data("row")!=undefined){A.data("row").removeData("bubble");
}var C=A.find(".rating_widget");
if(C.data("ratingView")){C.data("ratingView").remove();
}if(C.data("fbView")){C.data("fbView").remove();
}A.remove();
},500));
}},cancelRemoveHoverBubble:function(A){clearTimeout(A.data("removeTimeout"));
A.removeData("removeTimeout");
A.show().addClass("in");
}});




RT.Backbone.Models.Media=Backbone.Model.extend({sync:function(D,C,B){if(D=="patch"||D=="update"||D=="create"){var A=RT.social_init.pipe(function(){var E=B.xhr=Backbone.ajax({type:"POST",url:_.result(C,"url")||urlError(),data:{review:C.get("review"),score:C.get("score"),source:"RTM"}});
C.trigger("request",C,E,B);
return E;
});
return A;
}else{return Backbone.sync.call(this,D,C,B);
}},loginIfNecessary:function(){if(RT.LoginStatusModel.get("loginPlatformCode")==undefined){var B=$(this);
var A=B.attr("scope");
if(A==undefined){A="email,publish_actions";
}FB.login(function(C){fb_connected.done(function(){if(B.data("redirect")!=undefined){window.location.href=B.data("redirect");
}});
},{scope:A});
}}});
RT.Backbone.Models.Movie=RT.Backbone.Models.Media.extend({initialize:function(){this.bind("change",function(){console.log("Movie model changed - "+this.id);
});
},parse:function(B,A){B.id=B.media.id;
return B;
},loginAndSave:function(B,A){this.loginIfNecessary();
this.save();
this._eventAction=$(this.el).data("event-action")||"Rating";
if(B!==""){dataLayer.push({"event":"RatingWidget","mediaType":"Movie","target":"Flixster","action":B});
}if(A!==""){dataLayer.push({"event":"RatingWidget","mediaType":"Movie","target":"Flixster","action":"Review"});
}}});
RT.Backbone.Models.TvSeason=RT.Backbone.Models.Media.extend({initialize:function(){this.bind("change",function(){console.log("Season model changed - "+this.id);
});
},parse:function(B,A){B.id=B.media.id;
return B;
},loginAndSave:function(B,A){this.loginIfNecessary();
this.save();
if(B!==""){dataLayer.push({"event":"RatingWidget","mediaType":"TV","target":"Flixster","action":B});
}if(A!==""){dataLayer.push({"event":"RatingWidget","mediaType":"TV","target":"Flixster","action":"Review"});
}}});
RT.Backbone.Collections.MovieCollection=Backbone.Collection.extend({model:RT.Backbone.Models.Movie,url:"/api/private/v1.0/users/current/ratings/",getCurrentUserRating:function(B){var A;
if(this.get(B)==null){A=new RT.Backbone.Models.Movie({id:B},{collection:this});
A.deferred=A.fetch();
this.add(A);
}else{A=this.get(B);
}console.log("Retrieving Movie model id:"+A.id+". Hydrated:"+A.deferred.isResolved());
return A;
}});
RT.Backbone.Collections.TvSeasonCollection=Backbone.Collection.extend({model:RT.Backbone.Models.TvSeason,url:"/api/private/v1.0/users/current/tvratings/",getCurrentUserRating:function(B){var A;
if(this.get(B)==null){A=new RT.Backbone.Models.TvSeason({id:B},{collection:this});
A.deferred=A.fetch();
this.add(A);
}else{A=this.get(B);
}console.log("Retrieving TV model id:"+A.id+". Hydrated:"+A.deferred.isResolved());
return A;
}});
RT.Backbone.Views.RatingWidget=Backbone.View.extend({starClasses:"score00 score05 score10 score15 score20 score25 score30 score35 score40 score45 score50",initialize:function(){_.bindAll(this,"render","initialRender","changeRating","postReview");
var B=this.$el.data("media-id");
var A=this.$el.data("type");
if(A=="movie"){console.log("initializing rating widget for movie:"+B);
this.model=RT.ord.movies.getCurrentUserRating(B);
}else{if(A=="season"){console.log("initializing rating widget for season:"+B);
this.model=RT.ord.tvSeasons.getCurrentUserRating(B);
}else{console.error("Rating widget - invalid media type");
}}this.model.deferred.done(this.initialRender);
},events:{"click .rating_buttons input":"changeRating","mousemove .stars":"starMousemove","mouseout .stars":"starMouseout","click .post_button":"postReview","click .edit_button":"editReview"},changeRating:function(D){var E=$(D.currentTarget).val();
if(!E){var A=$(".stars",this.el);
var C=$(D.currentTarget).width();
var B=D.pageX-A.offset().left;
E=this.computeScore(C,B);
}this.model.set("score",E);
this.model.loginAndSave(E,"");
},starMousemove:function(D){var A=$(".stars",this.el);
var C=$(D.currentTarget).width();
var B=D.pageX-A.offset().left;
var E=this.computeScore(C,B);
A.removeClass(this.starClasses).addClass("score"+E.replace(".",""));
},starMouseout:function(){var A=$(".stars",this.el);
A.removeClass(this.starClasses);
var B=this.model.get("score");
if($.isNumeric(B)){A.addClass("score"+B.replace(".",""));
}},postReview:function(){var A=$(".review",this.el);
if(A!=undefined&&A.val().length>0){$(".post_button",this.el).hide();
A.addClass("disabled");
}var B=$(".edit_button",this.el);
$(".status").addClass("wait");
B.html("Saved").show().delay(3000).fadeOut("slow",function(){B.html("Edit");
if(A!=undefined&&A.val().length>0){B.show();
}$(".status").removeClass("wait");
});
this.model.set("review",A.val());
this.model.loginAndSave("",A.val());
},editReview:function(){$(".review",this.el).removeClass("disabled");
$(".edit_button",this.el).hide();
$(".post_button",this.el).show();
},computeScore:function(B,A){var C=90*(A/B);
var D="0.0";
if(90<C){D="5.0";
}else{if(80<C){D="4.5";
}else{if(70<C){D="4.0";
}else{if(60<C){D="3.5";
}else{if(50<C){D="3.0";
}else{if(40<C){D="2.5";
}else{if(30<C){D="2.0";
}else{if(20<C){D="1.5";
}else{if(10<C){D="1.0";
}else{if(5<C){D="0.5";
}}}}}}}}}}return D;
},initialRender:function(){this.render();
this.renderFacepile();
this.listenTo(this.model,"change",this.render);
},render:function(){console.log("Rendering rating widget");
var G=this.model.get("score");
var D=this.model.get("review");
var E=$(".wts",this.el);
var F=$(".ni",this.el);
var B=$(".stars",this.el);
E.removeClass("on");
F.removeClass("on");
B.removeClass(this.starClasses);
if(G!=undefined){switch(G){case"+":E.addClass("on").show();
break;
case"-":F.addClass("on").show();
break;
default:B.addClass("score"+G.replace(".",""));
}}var A=$(".review",this.el);
var C=$(".edit_button",this.el);
if(A==undefined||A.val()==undefined||A.val().length==0){A.val(D);
if(D!=undefined&&D.length>0){A.addClass("disabled");
C.show();
$(".post_button",this.el).hide();
if(A[0]!=undefined){A.height(A[0].scrollHeight);
}}else{C.hide();
}}},renderFacepile:function(){var B=this.model.get("friends_ratings");
if(B){var C=0;
var A=this.$el.find(".facepile");
$.each(B,function(D,E){if(E.type=="fblike"||($.isNumeric(E.rating)&&parseFloat(E.rating)>=3)||E.rating=="wts"){A.append("<img src='"+E.user.picture+"' />");
C++;
}});
if(C>0){A.append("<span class='facepile-caption'>"+C+(C==1?" friend likes it":" friends like it"));
}}}});
RT.Backbone.Views.FacebookManager=Backbone.View.extend({initialize:function(){_.bindAll(this,"render","initialRender","toggle","postReview");
var A=$(this.el).data("type");
var B=$(this.el).data("media-id");
if(A=="movie"){this.model=RT.ord.movies.getCurrentUserRating(B);
}else{if(A=="season"){this.model=RT.ord.tvSeasons.getCurrentUserRating(B);
}else{console.error("FacebookManager: invalid media type");
}}this.model.deferred.done(this.initialRender);
},initialRender:function(){this.render();
this.listenTo(this.model,"change",this.render);
},events:{"click .rating_buttons input":"postReview","click .fb_button":"toggle","click .edit_button":"editReview","click .post_button":"postReview",},toggle:function(){var A=$(".fb_button",this.el);
if(A.hasClass("on")){A.removeClass("on");
$.post("/user/account/facebook-share-rating-setting/",{sharingEnabled:false,facebookId:RT.LoginStatusModel.get("facebookId")});
}else{A.addClass("on");
$.post("/user/account/facebook-share-rating-setting/",{sharingEnabled:true,facebookId:RT.LoginStatusModel.get("facebookId")});
}},editReview:function(){$(".fb_button",this.el).show();
},postReview:function(){var B=this.model.get("score");
var A=this.model.get("review");
if($(".fb_button",this.el).hasClass("on")&&B!=undefined){this.postToFacebook(B,A);
}},render:function(){var C=this.model.get("review");
var A=$(".review",this.el);
var B=$(".fb_button",this.el);
if(A==undefined||A.val()==undefined||A.val().length==0){if(C!=undefined&&C.length>0){B.hide();
}else{B.show();
}}},postToFacebook:function(E,B){console.log("Posting to Facebook.");
if($(".fb_button").hasClass("on")){var D=B!=undefined&&B.length>0;
var C=this.model.url().indexOf("tvratings")==-1;
FB.api("/me/video.wants_to_watch",{object:$(location).attr("href")},function(G){if(G.data&&G.data.length>0){var F=G.data[0];
console.log("Prev action found (id="+F.id+" type="+F.type+"). Deleting.");
FB.api("/"+F.id,"delete",function(){console.log(F.type+" deleted");
});
}else{console.log("No previous video:wants_to_watch actions found");
}});
FB.api("/me/video.rates",{object:$(location).attr("href")},function(G){if(G.data&&G.data.length>0){var F=G.data[0];
console.log("Prev action found (id="+F.id+" type="+F.type+"). Deleting.");
FB.api("/"+F.id,"delete",function(){console.log(F.type+" deleted");
});
}else{console.log("No previous video:rates actions found");
}});
var A=$(".socialMsg",this.el);
if("wts"===E||"+"===E){A.html("Posting want to see").show().delay(3000).fadeOut("slow",function(){A.html("Added to your timeline").show();
var F={"fb:explicitly_shared":true,"expires_in":15768000};
F[C?"movie":"tv_show"]=$(location).attr("href");
FB.api("/me/video.wants_to_watch","post",F,function(G){if(!G||G.error){console.log(G.error.code+":"+G.error.message);
}else{console.log(G.id+" : "+"Action was successful");
}});
});
}else{if("-"===E||"ni"===E||""===E||(E!=undefined&&parseInt(E)==0)){A.html("Removing Facebook action").show().delay(3000).fadeOut("slow",function(){A.html("Removed from your timeline").show();
});
}else{if(!isNaN(E)&&isFinite(E)){A.html("Posting "+E+" star rating").show().delay(3000).fadeOut("slow",function(){A.html("Added to your timeline").show();
var F={"rating:value":E,"rating:scale":5,"rating:normalized_value":E/5,"review_text":B,"fb:explicitly_shared":true,"expires_in":2};
F[C?"movie":"tv_show"]=$(location).attr("href");
FB.api("/me/video.rates","post",F,function(G){if(!G||G.error){console.log(G.error.code+":"+G.error.message);
}else{console.log(G.id+" : "+"Action was successful");
}});
});
}}}}}});
RT.ord={movies:new RT.Backbone.Collections.MovieCollection(),tvSeasons:new RT.Backbone.Collections.TvSeasonCollection()};




