function Film(a){
	this.viewport=$(a);
	this.navItems=this.viewport.find(".navigation li");
	this.reel=this.viewport.find(".reel");
	this.frames=this.reel.find(".frame");
	this.tween=null;
	this.selectedIndex=0;
	this.previous=this.viewport.find(".previous");
	this.previousCaption=this.previous.find(".caption span");
	this.next=this.viewport.find(".next");
	this.nextCaption=this.next.find(".caption span");
	this.logo=$("p#logo img");
	this.normalLogoSrc=this.logo.attr("src");
	this.funkyFrameIndex=9;
	this.funkyFrameLogo=new Image();
	this.funkyFrameLogo.src="";
	this.prepare()}Film.prototype={
		prepare:function(){
			var c=this;this.navItems.each(
				function(b){
					$(this).click(function(){this.blur();
					return c.activate(b)});
					$(this).keydown(function(a){this.blur();
					return a.keyCode!=13||c.activate(b)})});
					this.frames.each(function(a){
						$(this).find("p.further span").click(function(){
							this.blur();return c.activate(a+1)})});
							this.previous.click(function(){this.blur();
							return c.activate(c.selectedIndex-1)});
							this.previous.keydown(
								function(a){this.blur();
								return a.keyCode!=13||c.activate(c.selectedIndex-1)});
							this.next.click(function(){this.blur();
							return c.activate(c.selectedIndex+1)});
							this.next.keydown(function(a){this.blur();
							return a.keyCode!=13||c.activate(c.selectedIndex+1)});
							this.previous.css("display","none");
							this.nextCaption.text(this.navItems.eq(this.selectedIndex+1).find("span").text());
							return this},num:function(a,b){
						return parseInt($.css(a.jquery?a[0]:a,b),10)||0},activate:function(a){
							if(a>=0&&a<this.frames.length&&a!=this.selectedIndex){
								var b=this;
								var kkk=0;
								

								
								while (kkk <= this.frames.length) {
								this.navItems.eq(kkk).removeClass("selected"+kkk);
								kkk=kkk+1;
								}
								
								this.navItems.eq(a).addClass("selected"+a);
								this.previous.fadeOut("fast");
								this.next.fadeOut("fast");
							
								
								if(this.selectedIndex==this.funkyFrameIndex){
									this.deactivateFunkyFrame()}this.moveTo(a,function(){
										if(a>0 && a!=1){b.previousCaption.text(b.navItems.eq(a-1).find("span").text());
										b.previous.fadeIn("fast")}
										if(a<b.frames.length-1 && a!=0){b.nextCaption.text(b.navItems.eq(a+1).find("span").text());
										
										
										
										b.next.fadeIn("fast")}if(a==b.funkyFrameIndex){b.activateFunkyFrame()}});
										
										if(a==0) {this.next.css("display","none");};
										if(a==1) {this.previous.css("display","none");};
										
										this.selectedIndex=a}return this},moveTo:function(a,b){
											if(this.tween){this.tween.stop()}var c=-100*a;this.tween=new Tween(this.reel,"left",EEQ.Quartic.easeInOut,this.num(this.reel,"left"),c,50,"%");
											this.tween.onMotionFinished=function(){b()};return this},activateFunkyFrame:function(){$(document.body).addClass("funky");this.logo.attr("src",this.funkyFrameLogo.src);return this},deactivateFunkyFrame:function(){$(document.body).removeClass("funky");this.logo.attr("src",this.normalLogoSrc);return this}};$(function(){$(".film").each(function(){new Film(this)})});