
var cachetimestamp=new Date().getTime();var ReelPlayer=new Class({Implements:[Options,Events],options:{layout:'/wp-content/themes/thereelplace/assets/js/promo/js/templates/layout.html',center:'/wp-content/themes/thereelplace/assets/js/promo/js/templates/center.html',json:'/promojson.js?'+cachetimestamp,centerSelector:'#reel_center',start:0},jQuery:'reelPlayer',initialize:function(selector,options){this.jqueryObject=jQuery(selector);this.setOptions(options);this.key=this.options.start;this.addEvent('onTemplateReady',this.render);this.getTemplates();},getTemplates:function(){var count=0;this.templates={};this.templates.items=[];jQuery.ajax({url:this.options.layout,async:false,success:function(text){this.templates.layout=text;}.bind(this)});jQuery.ajax({url:this.options.center,async:false,success:function(text){this.templates.center=text;}.bind(this)});jQuery.ajax({url:this.options.json,async:false,success:function(json){this.data=jQuery.parseJSON(json);if(this.processDataEvents()){this.data.images.each(function(item,key){jQuery.preloadImages(item.img);this.templates.items[key]=Mustache.to_html(this.templates.center,this.data.images[key]);}.bind(this));}}.bind(this)});this.render();},processDataEvents:function(){this.data.leftImages=function(){var leftImages=[];for(var i=0;i<(this.data.images.length/2);i++){leftImages.push(this.data.images[i]);};return leftImages;}.bind(this)
this.data.rightImages=function(){var rightImages=[];for(var i=(this.data.images.length/2);i<this.data.images.length;i++){rightImages.push(this.data.images[i]);};return rightImages;}.bind(this)
return true;},render:function(){this.jqueryObject.html(Mustache.to_html(this.templates.layout,this.data)).find(this.options.centerSelector).html(this.templates.items.join('').replace(/\\/g,''));this.jqueryObject.find('li a').click(function(evt){var key=jQuery(evt.currentTarget).attr('data-key');this.jumpTo(key);$clear(this.periodicalTimer);return false;}.bind(this));this.renderCurrent();this.periodicalTimer=this.next.periodical(this.data.mytimer,this);},incrementKey:function(count){this.key+=count;if(this.key>(this.data.images.length-1)){this.key=0;}
if(this.key<0){this.key=this.data.images.length-1;}},next:function(){this.incrementKey(1);this.renderCurrent();},previous:function(){this.incrementKey(-1);this.renderCurrent();},renderCurrent:function(){this.jqueryObject.find('.featured_item[data-key="'+this.key+'"]').fadeIn().siblings().fadeOut();this.jqueryObject.find('a').removeClass('selected');this.jqueryObject.find('a[data-key="'+this.key+'"]').addClass('selected');},jumpTo:function(where){this.key=where;this.renderCurrent();}});jQuery(document).ready(function(){jQuery('#reel_player').reelPlayer();});
