Element.implement({toggleDisplay:function(){if(this.visible()){this.hide()}else{this.show()}},show:function(){this.setStyle('display','')},hide:function(){this.setStyle('display','none')},visible:function(a){return this.getStyle('display')!='none'}});
$A=function(d,f,c){if(Browser.Engine.trident&&$type(d)=="collection"){f=f||0;if(f<0){f=d.length+f}c=c||(d.length-f);var e=[];for(var b=0;b<c;b++){e[b]=d[f++]}return e}f=(f||0)+((f<0)?d.length:0);var a=((!$chk(c))?d.length:c)+f;return Array.prototype.slice.call(d,f,a)};(function(){var b=[Array,Function,String,RegExp,Number];for(var c=0,a=b.length;c<a;c++){b[c].extend=b[c].implement}})();window.extend=document.extend=function(a){for(var b in a){this[b]=a[b]}};window[Browser.Engine.name]=window[Browser.Engine.name+Browser.Engine.version]=true;window.ie=window.trident;window.ie6=window.trident4;window.ie7=window.trident5;Class.empty=$empty;Class.prototype.extend=function(a){a.Extends=this;return new Class(a)};Array.implement({copy:function(b,a){return $A(this,b,a)}});Array.alias({erase:"remove",combine:"merge"});Function.extend({bindAsEventListener:function(b,a){return this.create({bind:b,event:true,"arguments":a})}});Function.empty=$empty;Hash.alias({getKeys:"keys",getValues:"values",has:"hasKey",combine:"merge"});var Abstract=Hash;Element.extend=Element.implement;Elements.extend=Elements.implement;Element.implement({getFormElements:function(){return this.getElements("input, textarea, select")},replaceWith:function(a){a=$(a);this.parentNode.replaceChild(a,this);return a},removeElements:function(){return this.dispose()}});Element.alias({dispose:"remove",getLast:"getLastChild"});Element.implement({getText:function(){return this.get("text")},setText:function(a){return this.set("text",a)},setHTML:function(){return this.set("html",arguments)},getHTML:function(){return this.get("html")},getTag:function(){return this.get("tag")}});Event.keys=Event.Keys;Element.implement({setOpacity:function(a){return this.set("opacity",a)}});Object.toQueryString=Hash.toQueryString;var XHR=new Class({Extends:Request,options:{update:false},initialize:function(b,a){this.parent(a);this.url=b},request:function(a){return this.send(this.url,a||this.options.data)},send:function(a,b){if(!this.check(arguments.callee,a,b)){return this}return this.parent({url:a,data:b})},success:function(b,a){b=this.processScripts(b);if(this.options.update){$(this.options.update).empty().set("html",b)}this.onSuccess(b,a)},failure:function(){this.fireEvent("failure",this.xhr)}});var Ajax=XHR;JSON.Remote=new Class({options:{key:"json"},Extends:Request.JSON,initialize:function(b,a){this.parent(a);this.onComplete=$empty;this.url=b},send:function(a){if(!this.check(arguments.callee,a)){return this}return this.parent({url:this.url,data:{json:Json.encode(a)}})},failure:function(){this.fireEvent("failure",this.xhr)}});Fx.implement({custom:function(b,a){return this.start(b,a)},clearTimer:function(){return this.cancel()},stop:function(){return this.cancel()}});Fx.Base=Fx;Fx.Style=function(b,c,a){return new Fx.Tween(b,$extend({property:c},a))};Element.implement({effect:function(b,a){return new Fx.Tween(this,$extend({property:b},a))}});Fx.Styles=Fx.Morph;Element.implement({effects:function(a){return new Fx.Morph(this,a)}});Native.implement([Element,Document],{getElementsByClassName:function(a){return this.getElements("."+a)},getElementsBySelector:function(a){return this.getElements(a)}});Elements.implement({filterByTag:function(a){return this.filter(a)},filterByClass:function(a){return this.filter("."+a)},filterById:function(a){return this.filter("#"+a)},filterByAttribute:function(b,a,c){return this.filter("["+b+(a||"")+(c||"")+"]")}});var $E=function(a,b){return($(b)||document).getElement(a)};var $ES=function(a,b){return($(b)||document).getElements(a)};var Json=JSON;JSON.toString=JSON.encode;JSON.evaluate=JSON.decode;Cookie.set=function(b,c,a){return new Cookie(b,a).write(c)};Cookie.get=function(a){return new Cookie(a).read()};Cookie.remove=function(b,a){return new Cookie(b,a).dispose()};Fx.Scroll.implement({scrollTo:function(b,a){return this.start(b,a)}});var HoverBehavior = new Class({
initialize: function() {
if (window.ie) {
$A(arguments).each( function(arg) {

$$(arg).each( function(tag) {
tag.addEvent('mouseenter',
function(event) {
setTimeout( function() { tag.addClass('hover'); }, 0 );
}
);
tag.addEvent('mouseleave',
function(event) {
setTimeout( function() { tag.removeClass('hover'); }, 0 );
}
);
});
});
}
}
});
var gammaDebug = false;
function toUnFocusedFilmImageUrl(src) {
return alterFilmUrl(src, 2, "_bw");
}
function toFocusedFilmImageUrl(src) {
return alterFilmUrl(src, 2, "");
}
function alterFilmUrl(url, indexOffset, appendString) {

var splitArray = url.split( /\// );
var dirName = splitArray[splitArray.length - indexOffset];
splitArray[splitArray.length - indexOffset] = dirName.charAt(0) + appendString;
	return splitArray.join('/').replace( /http:\/([^\/])/ , 'http://$1' );
}
var GammaHoverBehavior = new Class({
initialize: function(hoverSelector, imgSubSelector) {
this.hoverSelector = hoverSelector;
this.imgSubSelector = imgSubSelector;

if(gammaDebug) console.log("Adding gamma hover behavior with hover selector: %s and img sub selector: %s", hoverSelector, imgSubSelector);
$$(hoverSelector).each( function(hoverTag) {
if(gammaDebug) console.log("Inspecting %o", hoverTag);

if (document.images)
{
$ES(imgSubSelector, hoverTag).each( function(imgTag) {
if(imgTag.src) {

var imgPreload = new Image();
imgPreload.src = toFocusedFilmImageUrl(imgTag.src);
}
});
}
hoverTag.addEvent('mouseenter',
function(event) {
$ES(imgSubSelector, hoverTag).each( function(imgTag) {
if(imgTag.src) {
var origSrc = imgTag.src;
var newSrc = toFocusedFilmImageUrl(origSrc);
if(origSrc != newSrc) {
imgTag.src = newSrc;
}
}
});
}
);
hoverTag.addEvent('mouseleave',
function(event) {
$ES(imgSubSelector, hoverTag).each( function(imgTag) {
if(imgTag.src && !imgTag.hasClass('bs_gammaActive')) {
var origSrc = imgTag.src;
var newSrc = toUnFocusedFilmImageUrl(origSrc);
if(origSrc != newSrc) {
imgTag.src = newSrc;
}
}
});
}
);
});
},
activate: function(section) {
$ES(this.imgSubSelector, section).each( function(imgTag) {
if(imgTag.src) {
imgTag.addClass('bs_gammaActive');
var origSrc = imgTag.src;
var newSrc = toFocusedFilmImageUrl(origSrc);
if(origSrc != newSrc) {
imgTag.src = newSrc;
}
}
});
},
deactivate: function(section) {
$ES(this.imgSubSelector, section).each( function(imgTag) {
if(imgTag.src) {
imgTag.removeClass('bs_gammaActive');
var origSrc = imgTag.src;
var newSrc = toUnFocusedFilmImageUrl(origSrc);
if(origSrc != newSrc) {
imgTag.src = newSrc;
}
}
});
}
});

var Observer = new Class({
Implements: [Options, Events],
options: {
periodical: false,
delay: 1000
},
initialize: function(el, onFired, options){
this.setOptions(options);
this.addEvent('onFired', onFired);
this.element = $(el) || $$(el);
this.value = this.element.get('value');
if (this.options.periodical) this.timer = this.changed.periodical(this.options.periodical, this);
else this.element.addEvent('keyup', this.changed.bind(this));
},
changed: function() {
var value = this.element.get('value');
if ($equals(this.value, value)) return;
this.clear();
this.value = value;
this.timeout = this.onFired.delay(this.options.delay, this);
},
setValue: function(value) {
this.value = value;
this.element.set('value', value);
return this.clear();
},
onFired: function() {
this.fireEvent('onFired', [this.value, this.element]);
},
clear: function() {
$clear(this.timeout || null);
return this;
}
});
var $equals = function(obj1, obj2) {
return (obj1 == obj2 || JSON.encode(obj1) == JSON.encode(obj2));
};
var Autocompleter = {};
Autocompleter.Base = new Class({
options: {
minLength: 1,
markQuery: true,
width: 'inherit',
maxChoices: 10,
injectChoice: null,
customChoices: null,
className: 'autocompleter-choices',
zIndex: 99999,
delay: 400,
observerOptions: {},
fxOptions: {},
onOver: $empty,
onSelect: $empty,
onSelection: $empty,
onShow: $empty,
onHide: $empty,
onBlur: $empty,
onFocus: $empty,
autoSubmit: false,
overflow: false,
overflowMargin: 25,
selectFirst: true,
filter: null,
filterCase: false,
filterSubset: false,
forceSelect: false,
selectMode: true,
choicesMatch: null,
multiple: false,
separator: ', ',
separatorSplit: /\s*[,;]\s*/,
autoTrim: true,
allowDupes: false,
cache: true,
relative: false
},
initialize: function(element, options) {
this.element = $(element);
this.setOptions(options);
this.build();
this.observer = new Observer(this.element, this.prefetch.bind(this), $merge({
'delay': this.options.delay
}, this.options.observerOptions));
this.queryValue = null;
if (this.options.filter) this.filter = this.options.filter.bind(this);
var mode = this.options.selectMode;
this.typeAhead = (mode == 'type-ahead');
this.selectMode = (mode === true) ? 'selection' : mode;
this.cached = [];
},

build: function() {
if ($(this.options.customChoices)) {
this.choices = this.options.customChoices;
} else {
this.choices = new Element('ul', {
'class': this.options.className,
'styles': {
'zIndex': this.options.zIndex
}
}).inject(document.body);
this.relative = false;
if (this.options.relative) {
this.choices.inject(this.element, 'after');
this.relative = this.element.getOffsetParent();
}
this.fix = new OverlayFix(this.choices);
}
if (!this.options.separator.test(this.options.separatorSplit)) {
this.options.separatorSplit = this.options.separator;
}
this.fx = (!this.options.fxOptions) ? null : new Fx.Tween(this.choices, $merge({
'property': 'opacity',
'link': 'cancel',
'duration': 200
}, this.options.fxOptions)).addEvent('onStart', Chain.prototype.clearChain).set(0);
this.element.setProperty('autocomplete', 'off')
.addEvent((Browser.Engine.trident || Browser.Engine.webkit) ? 'keydown' : 'keypress', this.onCommand.bind(this))
.addEvent('click', this.onCommand.bind(this, [false]))
.addEvent('focus', this.toggleFocus.create({bind: this, arguments: true, delay: 100}))
.addEvent('blur', this.toggleFocus.create({bind: this, arguments: false, delay: 100}));
},
destroy: function() {
if (this.fix) this.fix.destroy();
this.choices = this.selected = this.choices.destroy();
},
toggleFocus: function(state) {
this.focussed = state;
if (!state) this.hideChoices(true);
this.fireEvent((state) ? 'onFocus' : 'onBlur', [this.element]);
},
onCommand: function(e) {
if (!e && this.focussed) return this.prefetch();
if (e && e.key && !e.shift) {
switch (e.key) {
case 'enter':



if (this.selected && this.visible) {
this.choiceSelect(this.selected);
return !!(this.options.autoSubmit);
}
break;
case 'up': case 'down':
if (!this.prefetch() && this.queryValue !== null) {
var up = (e.key == 'up');
this.choiceOver((this.selected || this.choices)[
(this.selected) ? ((up) ? 'getPrevious' : 'getNext') : ((up) ? 'getLast' : 'getFirst')
](this.options.choicesMatch), true);
}
return false;
case 'esc': case 'tab':
this.hideChoices(true);
break;
}
}
return true;
},
setSelection: function(finish) {
var input = this.selected.inputValue, value = input;
var start = this.queryValue.length, end = input.length;
if (input.substr(0, start).toLowerCase() != this.queryValue.toLowerCase()) start = 0;
if (this.options.multiple) {
var split = this.options.separatorSplit;
value = this.element.value;
start += this.queryIndex;
end += this.queryIndex;
var old = value.substr(this.queryIndex).split(split, 1)[0];
value = value.substr(0, this.queryIndex) + input + value.substr(this.queryIndex + old.length);
if (finish) {
var space = /[^\s,]+/;
var tokens = value.split(this.options.separatorSplit).filter(space.test, space);
if (!this.options.allowDupes) tokens = [].combine(tokens);
var sep = this.options.separator;
value = tokens.join(sep) + sep;
end = value.length;
}
}
this.observer.setValue(value);
this.opted = value;
if (finish || this.selectMode == 'pick') start = end;
this.element.selectRange(start, end);
this.fireEvent('onSelection', [this.element, this.selected, value, input]);
},
showChoices: function() {
var match = this.options.choicesMatch, first = this.choices.getFirst(match);
this.selected = this.selectedValue = null;
if (this.fix) {
var pos = this.element.getCoordinates(this.relative), width = this.options.width || 'auto';
this.choices.setStyles({
'left': pos.left,
'top': pos.bottom,
'width': (width === true || width == 'inherit') ? pos.width : width
});
}
if (!first) return;
if (!this.visible) {
this.visible = true;
this.choices.setStyle('display', '');
if (this.fx) this.fx.start(1);
this.fireEvent('onShow', [this.element, this.choices]);
}
if (this.options.selectFirst || this.typeAhead || first.inputValue == this.queryValue) this.choiceOver(first, this.typeAhead);
var items = this.choices.getChildren(match), max = this.options.maxChoices;
var styles = {'overflowY': 'hidden', 'height': ''};
this.overflown = false;
if (items.length > max) {
var item = items[max - 1];
styles.overflowY = 'scroll';
styles.height = item.getCoordinates(this.choices).bottom;
this.overflown = true;
};
this.choices.setStyles(styles);
this.fix.show();
},
hideChoices: function(clear) {
if (clear) {
var value = this.element.value;
if (this.options.forceSelect) value = this.opted;
if (this.options.autoTrim) {
value = value.split(this.options.separatorSplit).filter($arguments(0)).join(this.options.separator);
}
this.observer.setValue(value);
}
if (!this.visible) return;
this.visible = false;
this.observer.clear();
var hide = function(){
this.choices.setStyle('display', 'none');
this.fix.hide();
}.bind(this);
if (this.fx) this.fx.start(0).chain(hide);
else hide();
this.fireEvent('onHide', [this.element, this.choices]);
},
prefetch: function() {
var value = this.element.value, query = value;
if (this.options.multiple) {
var split = this.options.separatorSplit;
var values = value.split(split);
var index = this.element.getCaretPosition();
var toIndex = value.substr(0, index).split(split);
var last = toIndex.length - 1;
index -= toIndex[last].length;
query = values[last];
}
if (query.length < this.options.minLength) {
this.hideChoices();
} else {
if (query === this.queryValue || (this.visible && query == this.selectedValue)) {
if (this.visible) return false;
this.showChoices();
} else {
this.queryValue = query;
this.queryIndex = index;
if (!this.fetchCached()) this.query();
}
}
return true;
},
fetchCached: function() {
return false;
if (!this.options.cache
|| !this.cached
|| !this.cached.length
|| this.cached.length >= this.options.maxChoices
|| this.queryValue) return false;
this.update(this.filter(this.cached));
return true;
},
update: function(tokens) {
this.choices.empty();
this.cached = tokens;
if (!tokens || !tokens.length) {
this.hideChoices();
} else {
if (this.options.maxChoices < tokens.length && !this.options.overflow) tokens.length = this.options.maxChoices;
tokens.each(this.options.injectChoice || function(token){
var choice = new Element('li', {'html': this.markQueryValue(token)});
choice.inputValue = token;
this.addChoiceEvents(choice).inject(this.choices);
}, this);
this.showChoices();
}
},
choiceOver: function(choice, selection) {
if (!choice || choice == this.selected) {

this.selectedValue = this.selected.inputValue;
this.setSelection();
return;
}
if (this.selected) this.selected.removeClass('autocompleter-selected');
this.selected = choice.addClass('autocompleter-selected');


if (!selection) return;
this.selectedValue = this.selected.inputValue;
if (this.overflown) {
var coords = this.selected.getCoordinates(this.choices), margin = this.options.overflowMargin,
top = this.choices.scrollTop, height = this.choices.offsetHeight, bottom = top + height;
if (coords.top - margin < top && top) this.choices.scrollTop = Math.max(coords.top - margin, 0);
else if (coords.bottom + margin > bottom) this.choices.scrollTop = Math.min(coords.bottom - height + margin, bottom);
}
if (this.selectMode) this.setSelection();
},
choiceSelect: function(choice) {
if (choice) this.choiceOver(choice);
this.setSelection(true);
this.queryValue = false;
this.hideChoices();

this.fireEvent('onSelect', [this.element, choice], 20);
},
filter: function(tokens) {
var regex = new RegExp(((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp(), (this.options.filterCase) ? '' : 'i');
return (tokens || this.tokens).filter(regex.test, regex);
},

markQueryValue: function(str) {
return (!this.options.markQuery || !this.queryValue) ? str
: str.replace(new RegExp('(' + ((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp() + ')', (this.options.filterCase) ? '' : 'i'), '<span class="autocompleter-queried">$1</span>');
},

addChoiceEvents: function(el) {
return el.addEvents({
'mouseover': this.choiceOver.bind(this, [el]),
'click': this.choiceSelect.bind(this, [el])
});
}
});
Autocompleter.Base.implement(new Events);
Autocompleter.Base.implement(new Options);
Autocompleter.Local = new Class({
Extends: Autocompleter.Base,
options: {
minLength: 0,
delay: 200
},
initialize: function(element, tokens, options) {
this.parent(element, options);
this.tokens = tokens;
},
query: function() {
this.update(this.filter());
}
});
Autocompleter.Ajax = {};
Autocompleter.Ajax.Base = new Class({
Extends: Autocompleter.Base,
options: {
postVar: 'value',
postData: {},
ajaxOptions: {},
onRequest: $empty,
onComplete: $empty
},
initialize: function(element, options) {
this.parent(element, options);
var indicator = $(this.options.indicator);
if (indicator) {
this.addEvents({
'onRequest': indicator.show.bind(indicator),
'onComplete': indicator.hide.bind(indicator)
}, true);
}
},
query: function(){
var data = $unlink(this.options.postData);
data[this.options.postVar] = this.queryValue;
this.fireEvent('onRequest', [this.element, this.request, data, this.queryValue]);
this.request.send({'data': data});
},

queryResponse: function() {
this.fireEvent('onComplete', [this.element, this.request, this.response]);
}
});
Autocompleter.Ajax.Json = new Class({
Extends: Autocompleter.Ajax.Base,
initialize: function(el, url, options) {
this.parent(el, options);
this.request = new Request.JSON($merge({
'url': url,
'link': 'cancel'
}, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this));
},
queryResponse: function(response) {
this.parent();
this.update(response);
}
});
Autocompleter.Ajax.Xhtml = new Class({
Extends: Autocompleter.Ajax.Base,
initialize: function(el, url, options) {
this.parent(el, options);
this.request = new Request.HTML($merge({
'url': url,
'link': 'cancel',
'update': this.choices
}, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this));
},
queryResponse: function(tree, elements) {
this.parent();
if (!elements || !elements.length) {
this.hideChoices();
} else {
this.choices.getChildren(this.options.choicesMatch).each(this.options.injectChoice || function(choice) {
var value = choice.innerHTML;
choice.inputValue = value;
this.addChoiceEvents(choice.set('html', this.markQueryValue(value)));
}, this);
this.showChoices();
}
}
});
var OverlayFix = new Class({
initialize: function(el) {
if (Browser.Engine.trident) {
this.element = $(el);
this.relative = this.element.getOffsetParent();
this.fix = new Element('iframe', {
'frameborder': '0',
'scrolling': 'no',
'src': 'javascript:false;',
'styles': {
'position': 'absolute',
'border': 'none',
'display': 'none',
'filter': 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
}
}).inject(this.element, 'after');
}
},
show: function() {
if (this.fix) {
var coords = this.element.getCoordinates(this.relative);
delete coords.right;
delete coords.bottom;
this.fix.setStyles($extend(coords, {
'display': '',
'zIndex': (this.element.getStyle('zIndex') || 1) - 1
}));
}
return this;
},
hide: function() {
if (this.fix) this.fix.setStyle('display', 'none');
return this;
},
destroy: function() {
this.fix = this.fix.destroy();
}
});

Element.implement({
getOffsetParent: function() {
var body = this.getDocument().body;
if (this == body) return null;
if (!Browser.Engine.trident) return $(this.offsetParent);
var el = this;
while ((el = el.parentNode)){
if (el == body || Element.getComputedStyle(el, 'position') != 'static') return $(el);
}
return null;
},
getCaretPosition: function() {
if (!Browser.Engine.trident) return this.selectionStart;
this.focus();
var work = document.selection.createRange();
var all = this.createTextRange();
work.setEndPoint('StartToStart', all);
return work.text.length;
},
selectRange: function(start, end) {
if (Browser.Engine.trident) {
var range = this.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
} else {
this.focus();
this.setSelectionRange(start, end);
}
return this;
}
});
var rating_controls_by_sku = new Array();
function register_rating_controls() {
var rating_controls = $ES('.bs_ratingControl');
rating_controls.each(function(el) {
var sku = $(el).getProperty('sku');
if (sku) {
register_rating_control(sku, el.id);
}
});
}
function register_rating_control(sku, id) {
var rating_controls = rating_controls_by_sku[sku];
if(!rating_controls) {
rating_controls = new Array();
rating_controls_by_sku[sku] = rating_controls;
}
rating_controls.push(id);
}
function setCurrentUserRating(sku, rating) {
var rating_controls = rating_controls_by_sku[sku];
for (var i = 0; i < rating_controls.length; i++){
var elementId = rating_controls[i];
if($(elementId)) {
var ulElement = $E('ul', elementId);
if(ulElement) {
ulElement.removeClass('bs_otherUser');
ulElement.addClass('bs_ratingCurrentUser');
}
var rating_control = $E('li', elementId);
if(rating_control && rating_control.style) {
rating_control.style.width = rating * 20 + '%';
}
var clickToRate = $E('span.bs_clickToRate', elementId);
if (clickToRate) {
clickToRate.addClass('bs_userRating');
clickToRate.setHTML('my rating');
}
}
}
}
function unrateFilm(sku, rating) {
var rating_controls = rating_controls_by_sku[sku];
for (var i = 0; i < rating_controls.length; i++){
var elementId = rating_controls[i];
var ulElement = $E('ul', elementId);
if(ulElement) {
ulElement.removeClass('bs_ratingCurrentUser');
ulElement.addClass('bs_otherUser');
}
var rating_control = $E('li', elementId);
if(rating_control && rating_control.style) {
rating_control.style.width = rating * 20 + '%';
}
var clickToRate = $E('span.bs_clickToRate', elementId);
if (clickToRate) {
clickToRate.removeClass('bs_userRating');
clickToRate.setHTML('click to rate');
}
}
}
function getCurrentUserRating(sku) {
var rating_controls = rating_controls_by_sku[sku];


for(var id in rating_controls) {
var rating_control = $(rating_controls[id]);
if(rating_control && rating_control.style) {
var widthString = rating_control.style.width;
return widthString.substring(0, widthString.length - 1) / 20;
}
}
return 0;
}
function markSaving(id) {

}
function refreshAudienceBuzzPanel() {
var audienceBuzz = $E('.bs_festivalBuzzRefreshLink');

if (audienceBuzz != null) audienceBuzz.onclick();
}