Component.UserCommentDeleteLink=Class.create(Component.Link,{onClick:function(A){A.stop();
new View.ConfirmationPopup(this.element,{content:"Are you sure you want to delete this comment?",onConfirm:this.onDelete.bindAsEventListener(this),onCancel:this.onCancel.bindAsEventListener(this)});
},onCancel:function(){},onDelete:function(){new Ajax.Request("/api/v1/users/"+this.element.readAttribute("user")+"/comments/"+this.element.readAttribute("comment")+".json",{parameters:{_method:"delete"},method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
Tracker.tag("RemoveProfileComment");
},onSuccess:function(A){new Effect.Shrink(this.element.up("li"),{direction:"top-left",duration:0.5});
},onFailure:function(A){new View.ErrorPopup(this.element,{title:"Unexpected Error",content:"Failed to delete the comment."});
}});
Component.FriendSelect=Class.create(Component.Select,{onChange:function(A){if($F(this.element)!=""){document.location=$F(this.element);
}}});
Component.NominateSuperReviewerLink=Class.create(Component.Link,{onClick:function(A){A.stop();
var B="userId=${user.id}&eliteRole=REV";
new Ajax.Request("/elites/action/nominate",{parameters:B,onSuccess:this.onSuccess.bind(this)});
},onSuccess:function(A){window.location.reload(true);
}});
Component.BlockUserLink=Class.create(Component.Link,{onClick:function(A){A.stop();
new View.ConfirmationPopup(this.element,{content:"Are you sure you want to block this member?",onConfirm:this.onBlock.bindAsEventListener(this)});
},onBlock:function(){this.blocked=this.element.readAttribute("blocked");
this.blocker=this.element.readAttribute("blocker");
var A={_format:"json",_method:"post"};
new Ajax.Request("/api/v1/users/"+this.blocked+"/blocks",{parameters:A,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
this.element.update("...");
},onSuccess:function(A){this.element.replace("Blocked.");
},onFailure:function(A){this.element.update("Oops, please try again later.");
}});
Component.UnblockUserLink=Class.create(Component.Link,{onClick:function(A){A.stop();
new View.ConfirmationPopup(this.element,{content:"Are you sure you want to unblock this member?",onConfirm:this.onBlock.bindAsEventListener(this)});
},onBlock:function(){this.blocked=this.element.readAttribute("blocked");
this.blocker=this.element.readAttribute("blocker");
var A={_format:"json",_method:"delete"};
new Ajax.Request("/api/v1/users/"+this.blocked+"/blocks/"+this.blocker,{parameters:A,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
this.element.update("...");
},onSuccess:function(A){this.element.replace("Unblocked.");
},onFailure:function(A){this.element.update("Oops, please try again later.");
}});
Component.RemoveBuddyLink=Class.create(Component.Link,{onClick:function(A){A.stop();
new View.ConfirmationPopup(this.element,{content:"Are you sure you want to remove this friend?",onConfirm:this.onDelete.bindAsEventListener(this)});
},onDelete:function(){var B=this.element.readAttribute("me");
var A=this.element.readAttribute("friend");
var C={_method:"delete",_format:"json"};
new Ajax.Request("/api/v1/users/"+B+"/friends/"+A,{parameters:C,onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onSuccess:function(A){this.element.replace("Removed.");
},onFailure:function(A){this.element.replace("Oops, please try again later.");
}});
Component.ChangeSkinLink=Class.create(Component.Link,{onClick:function(A){A.stop();
var B={skin:this.element.readAttribute("skin")};
new Ajax.Request("/skins/action/change",{parameters:B,onSuccess:this.onSuccess.bind(this)});
},onSuccess:function(A){new View.SuccessPopup(this.element,{title:"Profile Updated.",content:"Click 'ok' to check out your new profile skin.",onClose:this.onClose.bindAsEventListener(this)});
},onClose:function(A){document.location="/profile";
}});
Component.FlashWidget=Class.create(Component.FlashMovieMeeboBarDecoupler);




Component.MovieListTextField=Class.create(Component.TextField,{initialize:function($super,A){$super(A);
this.element.observe("keyup",this.onKeyup.bindAsEventListener(this));
},onKeyup:function(A){$(this.element.readAttribute("echo")).update($F(this.element));
return true;
}});
Component.MovieListTitleField=Class.create(Component.MovieListTextField,{onKeyup:function(A){if(!this.titleField){this.titleField=$("listTitleHeaderText").down("h1");
}this.titleField.update($F(this.element));
return true;
}});
Component.MovieListForm=Class.create(Component.Form,{counter:0,onSubmit:function(A){if($F("listType")=="USR"&&(!TextUtils.hasText($F("listTitle"))||$F("listTitle")==$("listTitle").readAttribute("default"))){A.stop();
new View.ErrorPopup(this.element,{title:"Whoops",content:"Don't forget to give your list a title :)"});
return false;
}if($F("listDescription")==$("listDescription").readAttribute("default")){$("listDescription").value="";
return true;
}if(listEditor.items.length==0){new View.ConfirmationPopup(this.element,{content:"Are you sure you want to submit an empty list?",onConfirm:this.onConfirm.bindAsEventListener(this)});
A.stop();
return false;
}if(this.counter>=1){alert("Please wait -- we're working on your request.");
Event.stop(A);
return false;
}else{this.counter+=1;
return true;
}},onConfirm:function(A){this.element.submit();
}});
Movie.Cache=new Cache();
var MovieSearch=Class.create();
MovieSearch.prototype={STATES:{READY:0,SEARCHING:1,TIMEOUT:2,FAILURE:3},initialize:function(A){this.setOptions(A);
this.setObservers();
},setOptions:function(A){this.options={SEARCHING:GENERIC_VIEWS.LOADING,TIMEOUT:GENERIC_VIEWS.TIMEOUT,EMPTY:"No movies found.",MOVIE:new Template('<li id="searchItem_#{id}"><a href="" class="clearfix"  onclick="listEditor.onAddItem(event, #{id});"><span class="title">#{title}</span> <span class="add">add</span></li>'),FAILURE:GENERIC_VIEWS.FAILURE,searchField:"searchField",searchButton:"searchButton",searchResults:"searchResults",timeout:15000};
Object.extend(this.options,A||{});
},setObservers:function(){Event.observe($(this.options.searchField),"keypress",this.onEnter.bindAsEventListener(this));
Event.observe($(this.options.searchButton),"click",this.onSearch.bindAsEventListener(this));
new DefaultTextWidget($(this.options.searchField),"Type movie title, click SEARCH");
},onEnter:function(A){if(A.keyCode==Event.KEY_RETURN){Event.stop(A);
this.onSearch(A);
return false;
}else{return true;
}},onSearch:function(B){if(this.state==this.STATES.SEARCHING){return ;
}if($F(this.options.searchField)=="Type movie title, click SEARCH"){return ;
}if($F(this.options.searchField).length<2){return ;
}$(this.options.searchResults).show();
var A="movieAction=searchMovies&format=json&search="+encodeURIComponent($F(this.options.searchField));
new Ajax.Request("/movie.sv",{parameters:A,onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this),onTimeout:this.onTimeout.bind(this),timeout:this.options.timeout});
this.state=this.STATES.SEARCHING;
this.paint();
},onSuccess:function(response){this.movies=eval("("+response.responseText+")");
Movie.Cache.putList(this.movies);
this.state=this.STATES.READY;
this.paint();
},onFailure:function(){this.state=this.STATES.FAILURE;
this.paint();
},onTimeout:function(){this.state=this.STATES.TIMEOUT;
this.paint();
},paint:function(){switch(this.state){case this.STATES.READY:this.html="";
if(this.movies.length==0){this.html=this.options.EMPTY;
}else{this.html="<ul class='clearFix'>";
this.movies.each(function(A,B){this.html+=this.options.MOVIE.evaluate(A);
}.bind(this));
this.html+="</ul>";
}$(this.options.searchResults).update(this.html);
break;
case this.STATES.SEARCHING:$(this.options.searchResults).update(this.options.SEARCHING);
break;
case this.STATES.TIMEOUT:$(this.options.searchResults).update(this.options.TIMEOUT);
break;
case this.STATES.FAILURE:$(this.options.searchResults).update(this.options.FAILURE);
break;
}}};
var MovieBrowse=Class.create();
MovieBrowse.prototype={STATES:{READY:0,SEARCHING:1,TIMEOUT:2,FAILURE:3},initialize:function(A){this.setOptions(A);
Event.observe($("selectCategory"),"change",this.onChange.bindAsEventListener(this));
},setOptions:function(A){this.options={SEARCHING:GENERIC_VIEWS.LOADING,TIMEOUT:GENERIC_VIEWS.TIMEOUT,EMPTY:"No movies found.",MOVIE:new Template('<li id="searchItem_#{id}"><a href="" class="clearfix"  onclick="listEditor.onAddItem(event, #{id});"><span class="title">#{title}</span> <span class="add">add</span></li>'),FAILURE:GENERIC_VIEWS.FAILURE,browseResults:"browseResults",timeout:30000};
Object.extend(this.options,A||{});
},onChange:function(B){var A=Event.element(B);
this.callForResource($F(A));
if(this.state==this.STATES.SEARCHING){return ;
}this.paint();
},onSuccess:function(response){this.movies=eval("("+response.responseText+")");
Movie.Cache.putList(this.movies);
this.state=this.STATES.READY;
this.paint();
},onFailure:function(){this.state=this.STATES.FAILURE;
this.paint();
},onTimeout:function(){this.state=this.STATES.TIMEOUT;
this.paint();
},callForResource:function(A){this.state=this.STATES.SEARCHING;
this.paint();
var B="service=movieSearch&format=json&type="+A;
new Ajax.Request("/list.sv",{parameters:B,onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this),onTimeout:this.onTimeout.bind(this),timeout:this.options.timeout});
},paint:function(){var A=$(this.options.browseResults);
switch(this.state){case this.STATES.READY:this.html="";
if(this.movies.length==0){this.html=this.options.EMPTY;
}else{this.html="<ul class='clearFix'>";
this.movies.each(function(B,C){this.html+=this.options.MOVIE.evaluate(B);
}.bind(this));
this.html+="</ul>";
}if(A){A.update(this.html);
}break;
case this.STATES.SEARCHING:if(A){A.update(this.options.SEARCHING);
}break;
case this.STATES.TIMEOUT:if(A){A.update(this.options.TIMEOUT);
}break;
case this.STATES.FAILURE:if(A){A.update(this.options.FAILURE);
}break;
}}};
var ListEditor=Class.create();
ListEditor.prototype={initialize:function(A){this.setOptions(A);
this.items=new Array();
this.dirty=false;
},setOptions:function(A){this.options={items:"listTableBody",searchItem:"searchItem",tag:"tr",handle:"handle",ghosting:true};
Object.extend(this.options,A||{});
},setupList:function(){var A=Sortable.create(this.options.items,{tag:this.options.tag,scroll:window,handle:this.options.handle,constraint:false,onChange:function(){var B=$("listTableBody").getElementsBySelector("tr");
B.each(function(D,C){D.down("index").update(C+1);
});
}});
},onAddItem:function(B,C){var A=$("listTableBody").immediateDescendants().length+1;
new Effect.Highlight(this.options.searchItem+"_"+C);
if(this.items.indexOf(C)>=0){alert("Whoops, this item is already on your list.");
new Effect.Highlight("_"+C);
Event.stop(B);
return false;
}this.dirty=true;
this.items.push(C);
new Ajax.Request("/movie-list/movie/row?movieId="+C+"&rowNumber="+A,{method:"GET",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this),onTimeout:this.onTimeout.bind(this)});
Event.stop(B);
return false;
},onRemoveItem:function(A){this.dirty=true;
this.items=this.items.without(A);
Element.remove($("_"+A));
this.setupList();
this.paint();
},paint:function(){if($("listTableBody").immediateDescendants().length>0){$("emptyView").hide();
$("editView").show();
}else{$("emptyView").show();
$("editView").hide();
}},onSuccess:function(A){$(this.options.items).insert(A.responseText);
this.paint();
Sortable.addSortable($("listTableBody"),$(this.options.items+"_"+itemId),Sortable.sortables["listTableBody"]);
new Effect.Highlight($("_"+itemId));
},onFailure:function(){this.form.enable();
this.form.down("fieldSet").removeClassName("loading");
},onTimeout:function(){this.form.enable();
this.form.down("fieldSet").removeClassName("loading");
}};
var MovieListComments=Class.create();
MovieListComments.prototype={initialize:function(){this.form=$("addComment");
Event.observe(this.form,"submit",this.onSubmit.bindAsEventListener(this));
new TextCounter($("commentText"),1000,$("counter"),"Sorry, please keep your description under 1000 characters.  Thanks.");
},onSubmit:function(B){if(!TextUtils.hasText($F("commentText"))||$F("commentText").length<3){alert("hey, comments gotta have at least 3 lousy characters...");
Event.stop(B);
return false;
}this.form.disable();
this.form.getElementsBySelector("fieldSet")[0].addClassName("loading");
var A="commentText="+encodeURIComponent($F("commentText"));
new Ajax.Request(document.URL+"/comment/add",{parameters:A,onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this),onTimeout:this.onTimeout.bind(this)});
Event.stop(B);
return false;
},onSuccess:function(A){this.form.enable();
this.form.down("fieldset").removeClassName("loading");
$("commentsList").insert(A.responseText);
$("commentText").value="";
var B=$("commentsList").immediateDescendants();
B.last().scrollTo();
},onFailure:function(){this.form.enable();
this.form.down("fieldSet").removeClassName("loading");
},onTimeout:function(){this.form.enable();
this.form.down("fieldSet").removeClassName("loading");
}};
var MovieListRating=Class.create();
MovieListRating.prototype={initialize:function(){this.form=$("ratingForm");
this.ratingWidget=$("ratingWidget");
if(this.form!=null){this.form.getElements().each(function(A){Event.observe(A,"click",this.onClick.bindAsEventListener(this));
}.bind(this));
Event.observe(this.form,"submit",this.onClick.bindAsEventListener(this));
}},onClick:function(B){this.form.disable();
this.form.down("fieldSet").addClassName("loading");
var A="userRating="+Event.element(B).value;
new Ajax.Request(document.URL+"/rate/action",{parameters:A,onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this),onTimeout:this.onTimeout.bind(this)});
Event.stop(B);
return false;
},onSuccess:function(A){this.form.enable();
this.form.down("fieldset").removeClassName("loading");
this.form.hide();
$("ratingWidget").insert(A.responseText,{position:"bottom"});
},onFailure:function(){this.form.enable();
this.form.down("fieldSet").removeClassName("loading");
},onTimeout:function(){this.form.enable();
this.form.down("fieldSet").removeClassName("loading");
}};
var MovieListFavoriting=Class.create();
MovieListFavoriting.prototype={initialize:function(){this.favoriteLink=$("favoriteLink");
if(this.favoriteLink!=null){Event.observe(this.favoriteLink,"click",this.onClick.bindAsEventListener(this));
}},onClick:function(A){this.favoriteLink.addClassName("loading");
new Ajax.Request(this.favoriteLink.getAttribute("href"),{method:"GET",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this),onTimeout:this.onTimeout.bind(this)});
Event.stop(A);
return false;
},onSuccess:function(A){this.favoriteLink.removeClassName("loading");
this.favoriteLink.hide();
this.favoriteLink.next("span").show();
this.favoriteLink.next("a").show();
},onFailure:function(){this.favoriteLink.removeClassName("loading");
alert("we borked adding this to your favorites! please try again later");
},onTimeout:function(){this.favoriteLink.removeClassName("loading");
alert("it's takin' to long to add this movie list to your favorites. give it another shot in a little bit. ");
}};
var MovieListUserHomepage=Class.create();
MovieListUserHomepage.prototype={initialize:function(){this.userCreated=$("userCreated").down("tbody").getElementsBySelector("tr");
this.favorites=$("favorites").down("tbody").getElementsBySelector("tr");
if(this.userCreated!=null){this.userCreated.each(function(B){var A=B.down("a.action");
if(A!=null){Event.observe(A,"click",this.onClick.bindAsEventListener(this));
}}.bind(this));
}if(this.favories!=null){this.favories.each(function(B){var A=B.down("a.action");
Event.observe(A,"click",this.onClick.bindAsEventListener(this));
}.bind(this));
}},onClick:function(B){var A=Event.element(B);
if(A.hasAttribute("delete")){if(!confirm("Really? We're gonna rip this movie list apart and tear it to shreds.")){Event.stop(B);
return false;
}}new Ajax.Request(A.href,{method:"POST",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this),onTimeout:this.onTimeout.bind(this)});
A.up("tr").remove();
Event.stop(B);
return false;
},onSuccess:function(A,B){},onFailure:function(){},onTimeout:function(){}};




var package_rating_staticServer="http://static5.flixster.com/static";
var RatingsApi={updateRating:function(B,D){var A="/api/v1/users/"+B.user+"/ratings/"+B.movie;
var C={score:B.score,source:B.source};
new Ajax.Request(A,{method:"put",onSuccess:D,parameters:C});
},updateReview:function(B,D){var A="/api/v1/users/"+B.user+"/ratings/"+B.movie;
var C={review:B.review,source:B.source};
new Ajax.Request(A,{method:"put",onSuccess:D,parameters:C});
},updateRatingAndReview:function(B,D){var A="/api/v1/users/"+B.user+"/ratings/"+B.movie;
var C={score:B.score,review:B.review,source:B.source};
new Ajax.Request(A,{method:"put",onSuccess:D,parameters:C});
},clearRating:function(A,B){RatingsApi.updateRatingAndReview(A,B);
}};
Component.RatingButton=Class.create({SCORE:-1,initialize:function(A){this.button=$(A);
this.score=parseInt($F(this.button));
this.controller=$(this.button.readAttribute("controller"));
this.button.observe("click",this.onClick.bindAsEventListener(this));
this.button.observe("mouseout",this.onMouseout.bindAsEventListener(this));
this.controller.observe("rating:score",this.onRate.bindAsEventListener(this));
this.controller.observe("rating:clear",this.onClear.bindAsEventListener(this));
},onClick:function(A){A.stop();
A.target.fire("rating:score",{score:this.SCORE});
},onRate:function(A){this.score=A.memo.score;
this.button.value=this.score;
this.paint(this.score);
},onMouseout:function(A){this.paint(this.score);
},onClear:function(A){this.score=-1;
this.button.value=this.score;
this.paint(this.score);
}});
Component.RatingWtsButton=Class.create(Component.RatingButton,{SCORE:12,initialize:function($super,A){$super(A);
this.button.observe("mouseover",this.onMouseover.bindAsEventListener(this));
},onMouseover:function(A){if(this.score!=this.SCORE){$(this.button).setStyle({backgroundPosition:"-148px -30px"});
}},paint:function(A){if(A==this.SCORE){$(this.button).setStyle({backgroundPosition:"-74px -30px"});
}else{$(this.button).setStyle({backgroundPosition:"0px -30px"});
}}});
Component.RatingNiButton=Class.create(Component.RatingButton,{SCORE:11,initialize:function($super,A){$super(A);
this.button.observe("mouseover",this.onMouseover.bindAsEventListener(this));
},onMouseover:function(A){if(this.score!=this.SCORE){$(this.button).setStyle({backgroundPosition:"-148px -45px"});
}},paint:function(A){if(A==this.SCORE){$(this.button).setStyle({backgroundPosition:"-74px -45px"});
}else{$(this.button).setStyle({backgroundPosition:"0px -45px"});
}}});
Component.RatingStars=Class.create(Component.RatingButton,{initialize:function($super,A){$super(A);
this.button.observe("mousemove",this.onMousemove.bindAsEventListener(this));
},onMousemove:function(A){this.paint(this.map(A));
},onClick:function(A){A.stop();
this.button.blur();
var B=this.map(A);
if(B==this.score){B=-1;
}A.target.fire("rating:score",{score:B});
},map:function(B){var C=B.pointerX();
var D=B.target.cumulativeOffset().left;
var A=C-D;
if($R(0,6).include(A)){return 6;
}else{if($R(7,13).include(A)){return 1;
}else{if($R(14,20).include(A)){return 7;
}else{if($R(21,27).include(A)){return 2;
}else{if($R(28,34).include(A)){return 8;
}else{if($R(35,41).include(A)){return 3;
}else{if($R(42,49).include(A)){return 9;
}else{if($R(50,55).include(A)){return 4;
}else{if($R(56,62).include(A)){return 10;
}else{if($R(63,70).include(A)){return 5;
}else{return -1;
}}}}}}}}}}},paint:function(A){switch(A){case 1:$(this.button).setStyle({backgroundPosition:"-56px 0px"});
break;
case 2:$(this.button).setStyle({backgroundPosition:"-42px 0px"});
break;
case 3:$(this.button).setStyle({backgroundPosition:"-28px 0px"});
break;
case 4:$(this.button).setStyle({backgroundPosition:"-14px 0px"});
break;
case 5:$(this.button).setStyle({backgroundPosition:"0px 0px"});
break;
case 6:$(this.button).setStyle({backgroundPosition:"-56px -15px"});
break;
case 7:$(this.button).setStyle({backgroundPosition:"-42px -15px"});
break;
case 8:$(this.button).setStyle({backgroundPosition:"-28px -15px"});
break;
case 9:$(this.button).setStyle({backgroundPosition:"-14px -15px"});
break;
case 10:$(this.button).setStyle({backgroundPosition:"0px -15px"});
break;
default:$(this.button).setStyle({backgroundPosition:"-70px 0px"});
}}});
Component.RatingCancelLink=Class.create(Component.Link,{onClick:function(A){A.stop();
this.element.fire("rating:cancel",{});
}});
Component.RatingEditLink=Class.create(Component.Link,{onClick:function(A){A.stop();
this.element.fire("rating:edit",{});
}});
Component.RatingClearButton=Class.create(Component.Button,{onClick:function(A){A.stop();
A.target.fire("rating:clear",{score:-1});
}});
Component.ReviewWidget=Class.create({initialize:function(A){this.textarea=$(A);
this.hasDefaultText=(this.textarea.readAttribute("defaultText")!=null);
if(this.hasDefaultText){this.defaultTextValue=this.textarea.readAttribute("defaultText");
if($F(this.textarea)==null||$F(this.textarea).blank()){this.textarea.value=this.defaultTextValue;
}}this.controller=$(this.textarea.readAttribute("controller"));
this.textarea.observe("focus",this.onFocus.bindAsEventListener(this));
this.controller.observe("rating:clear",this.onClear.bindAsEventListener(this));
},onFocus:function(A){A.target.fire("review:change",{});
if(this.hasDefaultText){if($F(this.textarea)==this.defaultTextValue){this.textarea.value="";
}}},onClear:function(A){this.textarea.value="";
}});
Component.ReviewSaveButton=Class.create({initialize:function(A){this.button=A;
this.controller=$(this.button.readAttribute("controller"));
this.button.observe("click",this.onClick.bindAsEventListener(this));
},onClick:function(A){A.stop();
A.target.fire("review:save",{});
}});




Component.ExpandoRatingWidget=Class.create({initialize:function(A){this.element=$(A);
this.currentView=null;
this.isAnonUser=true;
this.isInitialized=false;
this.element.observe("mouseover",this.onLazyInit.bindAsEventListener(this));
},onLazyInit:function(){if(!this.isInitialized){this.isInitialized=true;
this.rating=this.element.serialize(true);
this.rating.unsavedScore=this.rating.score;
this.isAnonUser=(this.rating.user==null||this.rating.user.blank());
this.element.observe("rating:score",this.onRate.bindAsEventListener(this));
this.element.observe("rating:clear",this.onClear.bindAsEventListener(this));
this.element.observe("review:save",this.onSave.bindAsEventListener(this));
this.element.observe("rating:edit",this.onEdit.bindAsEventListener(this));
this.element.observe("rating:cancel",this.onCancel.bindAsEventListener(this));
}},onRate:function(A){this.rating.unsavedScore=A.memo.score;
A.memo.rating=this.rating;
},onEdit:function(){if(!this.isAnonUser){this.makeEditable();
}else{this.showAnonAlert();
}},onClear:function(A){this.rating.score=-1;
this.rating.unsavedScore=-1;
this.rating.review="";
RatingsApi.clearRating(this.rating);
A.memo.rating=this.rating;
this.makeNonEditable();
},onSave:function(A){var B=this.element.select("textarea.commentField").first();
this.rating.review=($F(B)==B.readAttribute("defaultText")||$F(B).blank())?"":$F(B);
this.rating.score=this.rating.unsavedScore;
RatingsApi.updateRatingAndReview(this.rating);
A.memo.rating=this.rating;
this.makeNonEditable();
},onCancel:function(){this.makeNonEditable();
},makeEditable:function(){this.element.down(".elementsWrapper").makePositioned();
this.currentView=new View.RatingElementsEditable(this.element,{eid:this.element.readAttribute("id"),rating:this.rating});
},makeNonEditable:function(){this.element.undoPositioned();
this.currentView=new View.RatingElementsNonEditable(this.element,{eid:this.element.readAttribute("id"),rating:this.rating});
},showAnonAlert:function(){new View.ErrorPopup(this.element,{title:"Whoops",content:"To rate movies, you must be logged in"});
}});
View.RatingElementsEditable=Class.create(View.AbstractView,{render:function(C){var B="";
var A="http://static5.flixster.com/static/images/pixel.gif";
C.rating.wtsBtnState=((parseInt(C.rating.score)==12)?"On":"Off");
C.rating.niBtnState=((parseInt(C.rating.score)==11)?"On":"Off");
C.rating.scoreCssCode=this.cssScoreMap(parseInt(C.rating.score))+"";
if($("expandoRatingWidgetInputForm")!=null){if($("expandoRatingWidgetInputForm").up("form")!=$(C.eid)){$("expandoRatingWidgetInputForm").getOffsetParent().undoPositioned();
}$("expandoRatingWidgetInputForm").remove();
}this.element.down(".elementsWrapper").innerHTML+="<div id='expandoRatingWidgetInputForm' class='inputForm'>&nbsp;</div>";
B="";
B+="<h4>";
B+="<span class='closeBtn' component='RatingCancelLink'>&nbsp;</span>";
B+="Rate &quot;"+C.rating.movieTitle+"&quot;";
B+="</h4>";
B+="<div class='controls'>";
B+="<input type='image' value='"+C.rating.score+"' class='wtsBtn ratingInterest wts"+C.rating.wtsBtnState+"' src='"+A+"' component='RatingWtsButton'  controller='"+C.eid+"'/>";
B+="<input type='image' value='"+C.rating.score+"' class='niBtn ratingInterest ni"+C.rating.niBtnState+"' src='"+A+"' component='RatingNiButton' controller='"+C.eid+"'/>";
B+="<input type='image' value='"+C.rating.score+"' class='scoreBtn ratingStars score"+C.rating.scoreCssCode+"' src='"+A+"' component='RatingStars' controller='"+C.eid+"'/>";
B+="<textarea class='commentField' component='ReviewWidget' controller='"+C.eid+"' defaultText='Add a review...'>"+C.rating.review.escapeHTML()+"</textarea>";
B+="<input type='image' src='"+A+"' component='ReviewSaveButton' controller='"+C.eid+"' class='saveBtn' />";
if(C.rating.showClear=="true"){B+="<a href='#' component='RatingClearButton' class='clearLink'>clear rating</a>";
}B+="<a href='#' component='RatingCancelLink' class='cancelLink'>cancel</a>";
B+="</div>";
$("expandoRatingWidgetInputForm").update(B);
new Component.Binder(this.element);
},cssScoreMap:function(A){switch(A){case 1:return 10;
break;
case 2:return 20;
break;
case 3:return 30;
break;
case 4:return 40;
break;
case 5:return 50;
break;
case 6:return 5;
break;
case 7:return 15;
break;
case 8:return 25;
break;
case 9:return 35;
break;
case 10:return 45;
break;
case 11:return"wts";
break;
case 12:return"ni";
break;
default:return 0;
}}});
View.RatingElementsNonEditable=Class.create(View.AbstractView,{render:function(C){var B="";
var A="http://static5.flixster.com/static/images/pixel.gif";
var E=(parseInt(C.rating.score)>-1);
var D=(C.rating.review!="");
B+="<div class='elementsWrapper'>\n";
if(D){B+="<input type='image' src='"+A+"' component='RatingEditLink' class='editCommentBtn'/>\n";
}B+="<input type='image' src='"+A+"' component='RatingEditLink' class='"+((E)?"editBtn":"rateBtn")+"'/>\n";
B+="</div>";
this.element.update(B);
new View.RatingScoreView(this.element.down(".elementsWrapper"),C.rating);
new Component.Binder(this.element);
}});
View.RatingScoreView=Class.create(View.AbstractView,{render:function(A){switch(parseInt(A.score)){case 1:this.element.insert({"top":"<span class='ratingStars score10'> </span>\n"});
break;
case 2:this.element.insert({"top":"<span class='ratingStars score20'> </span>\n"});
break;
case 3:this.element.insert({"top":"<span class='ratingStars score30'> </span>\n"});
break;
case 4:this.element.insert({"top":"<span class='ratingStars score40'> </span>\n"});
break;
case 5:this.element.insert({"top":"<span class='ratingStars score50'> </span>\n"});
break;
case 6:this.element.insert({"top":"<span class='ratingStars score05'> </span>\n"});
break;
case 7:this.element.insert({"top":"<span class='ratingStars score15'> </span>\n"});
break;
case 8:this.element.insert({"top":"<span class='ratingStars score25'> </span>\n"});
break;
case 9:this.element.insert({"top":"<span class='ratingStars score35'> </span>\n"});
break;
case 10:this.element.insert({"top":"<span class='ratingStars score45'> </span>\n"});
break;
case 11:this.element.insert({"top":"<span class='ratingInterest niOn'> </span>\n"});
break;
case 12:this.element.insert({"top":"<span class='ratingInterest wtsOn'> </span>\n"});
break;
default:this.element.insert({"top":"\n"});
}}});




