releasing = {


	attachBehaviors: function(){

		var self = this;

		$('.itemthumb').bind('mouseenter mouseleave', function(e){
			self.linkswap(this);
		});

		this.trailerBanner.init($('#rel_trailer_banner'));

		$('#rel_trailer_banner .trailer').click(function(){
			var obj = $(this).parent();
			self.trailerBanner.watchTrailer(obj);
			return false;
		});

	}, // attachBehaviors()


	init: function(){
		this.attachBehaviors();
	}, // init()


	linkswap: function(item){
		var id = $(item).attr('id').split('_')[1];
		var item = $('#item_' + id)
		item.toggleClass('selected');
	}, // linkswap()


	trailerBanner: {

		instance: null,
		interval: null,
		json: null,

		buildNav: function(){
			var self = this;
			var nav = $('.nav', this.instance);
			var totalsteps = this.getTotalSteps();
			var html = '';
			var index;
			for (var i = 0; i < totalsteps; i++) {
				index = i + 1;
				html += '<li' + (i == 0 ? ' class="selected"' : '') + '><a href="#" rel="' + index + '">' + index + '</a></li>';
			}
			nav.html(html);
			$('li', nav).click(function(e){
				var id = $('a', this).attr('rel');
				self.gotoBanner(id);
				return false;
			});
		}, // buildNav()

		init: function(item){
			var self = this;
			this.instance = item;
			this.json = $('#rel_trailer_banner_json').val();
			this.buildNav();
			$('.banner:first', this.instance).addClass('selected');
			this.interval = window.setInterval(function(){
				self.stepForward();
			}, 7000);
		}, // init()

		getCurrentStep: function(){
			var selectedId = $('.banner.selected', this.instance).attr('id');
			if(!!selectedId){
				return selectedId.split('_')[1];
			}else{
				return "";
			}
		}, // getCurrentStep()

		getTotalSteps: function(){
			var steps = $('.banner', this.instance).length;
			return steps;
		}, // getTotalSteps()

		gotoBanner: function(id){
			this.showBanner(id);
			window.clearInterval(this.interval);
		}, // gotoBanner()

		showBanner: function(index){
			var self = this;
			var curstep = this.getCurrentStep();
			var curbanner = $('#banner_' + curstep, this.instance);
			var newbanner = $('#banner_' + index, this.instance);
			curbanner.fadeOut(function(){
				$('#rel_trailer_banner .banner .trailer_container').empty().hide();
				$('.banner', self.instance).removeClass('selected');
				newbanner.fadeIn(function(){
					newbanner.addClass('selected');
					self.updateNav();
				});
			});
		}, // showBanner()

		stepBackward: function(){
			var curstep = this.getCurrentStep;
			var totalsteps = this.getTotalSteps();
			var newstep = parseInt(curstep) - 1;
			if (newstep <= 0) {
				newstep = totalsteps;
			}
			this.showBanner(newstep);
		}, // stepBackward()

		stepForward: function(){
			var curstep = this.getCurrentStep();
			var totalsteps = this.getTotalSteps();
			var newstep = parseInt(curstep) + 1;
			if (newstep > totalsteps) {
				newstep = 1;
			}
			this.showBanner(newstep);
		}, // stepForward()

		updateNav: function(){
			var curstep = this.getCurrentStep();
			$('.nav li').removeClass('selected');
			$('.nav li:eq(' + (curstep - 1) + ')', this.instance).addClass('selected');
		}, // updateNav()

		watchTrailer: function(obj){
			var container = $('.trailer_container', obj);
			var trailerid = container.attr('id').split('_')[1];
			var embed = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="195" height="194" id="viddler_' + trailerid + '"><param name="flashvars" value="autoplay=t&wmode=transparent" /><param name="movie" value="http://www.viddler.com/simple/' + trailerid + '/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/simple/' + trailerid + '/" width="195" height="194" type="application/x-shockwave-flash" allowScriptAccess="always" flashvars="autoplay=t&wmode=transparent" allowFullScreen="true" name="viddler_' + trailerid + '" ></embed></object>';
			window.clearInterval(this.interval);
			container.html(embed).show();
		} // watchTrailer()

	} // trailerBanner


}; // releasing





$(document).ready(function(){

	releasing.init();

}); // document ready