var newIconLight = 'http://movies.apple.com/trailers/images/generic/hud_icon_new.png';
var newIconDark = 'http://movies.apple.com/trailers/images/generic/hud_icon_new.png';
var hudContrast = 'light';
var hudArrowContrast = 'light';

/*PosterPopup = Class.create({
	clickX: null,
	clickY: null,
	initialize: function(posterSrc) {
		this.setupOverlay();
		this.setupPopup(posterSrc);
		this.addHoverEvent();
		this.addClickEvent();
	},
	
	setupOverlay: function() {
		this.overlayElement = Builder.node('div', { id:'poster-overlay'});
		$$('body').first().appendChild(this.overlayElement);
		Element.hide(this.overlayElement);
	},
	
	setupPopup: function(posterSrc) {
		this.poster = $('poster');
		this.popup = new Element('div', {
			id:'poster-popup'
		});
		this.popupShadow = new Element('img', { 
			id:'poster-popupShadow',
			src:'http://movies.apple.com/trailers/images/generic/poster_popup_bg.png',
			border:0
		 });
		this.popupPoster = new Element('img', {
			id:'poster-popupPoster',
			src:posterSrc,
			border:0
		});
		this.popup.appendChild(this.popupShadow);
		this.popup.appendChild(this.popupPoster);
		document.body.appendChild(this.popup);
		this.popup.hide();		
	},
	
	addHoverEvent: function() {
		this.poster.observe('mouseover', function() {
			this.poster.hasClassName('active') ? this.poster.removeClassName('active') : this.poster.addClassName('active');
		}.bind(this));
		this.poster.observe('mouseout', function() {
			this.poster.hasClassName('active') ? this.poster.removeClassName('active') : this.poster.addClassName('active');
		}.bind(this));
	},
	
	addClickEvent: function() {
		this.poster.observe('click', function(e) {
			Event.stop(e);
			this.clickX = Position.cumulativeOffset(this.poster)[0];
			this.clickY = Position.cumulativeOffset(this.poster)[1] + 2;
			this.overlayElement.setStyle({ height: getPageDimensions().height +'px' });
			this.overlayElement.show();
			this.showPopup();						
		}.bind(this));
	},

	showPopup: function() {
		var left = (windowSize().width/2) - (357/2);
		var top = ((windowSize().height/2) + windowSize().y) - (500/2);
		this.popup.setStyle({
			height:'209px',
			width:'141px',
			left:this.clickX + 'px',
			top:this.clickY + 'px'
		});
		this.popupShadow.setStyle({
			height:'209px',
			width:'141px',
			left:'0',
			top:'0'
		});
		this.popupPoster.setStyle({
			height:'193px',
			width:'134px',
			left:'1px',
			top:'1px'
		});
		this.popup.show();
		new Effect.Transform([
			{ '#poster-popup' :
				'height:481px;' +
				'width:357px;' +
				'left:'+left + 'px;' +
				'top:'+top + 'px;' },
			{ '#poster-popupShadow' :
				'height:481px;' +
				'width:357px;' +
				'left:'+left + 'px;' +
				'top:'+top + 'px;' },
			{ '#poster-popupPoster' :
				'height:385px;' +
				'width:261px;' +
				'left:48px;' +
				'top:48px;' }	
		], { duration: .4 , afterFinish:this.addPopupClickEvent.bind(this) }).play();

	},
	
	hidePopup: function() {
		this.overlayElement.hide();		
		new Effect.Transform([
			{ '#poster-popup' :
				'height:209px;' +
				'width:141px;' +
				'left:'+this.clickX + 'px;' +
				'top:'+this.clickY + 'px;' },
			{ '#poster-popupShadow' :
			'height:193px;' +
			'width:134px;' +
				'left:1px;' +
				'top:1px;' },
			{ '#poster-popupPoster' :
			'height:193px;' +
			'width:134px;' +
				'left:1px;' +
				'top:1px;' },
		], { duration: .4 , afterFinish:this.afterClose.bind(this) }).play();
	},
	
	addPopupClickEvent: function() {
		Event.observe(this.popup, 'click', function() {
			this.hidePopup();
		}.bind(this));
		Event.observe(this.overlayElement, 'click', function() {
			this.hidePopup();
		}.bind(this));
	},

	afterClose: function() {
		this.popup.hide();
	}
});
*/
/*
STAF = Class.create({
	prevHeight: null,
	initialize: function(trailerTitle, trailerURL, trailerPosterURL) {
		Share.shareId = 109;
		Share.parameters = { 'trailerTitle':trailerTitle, 'trailerURL':trailerURL, 'trailerPosterURL':trailerPosterURL };
		Share.initOptions(arguments);
		Share.buildForm();
		Share.addValidation();
		
		this.trailerTitle = trailerTitle
		this.tell = $('tellafriend');
		this.tellTrigger = $('tellafriend-trigger');
		this.tellTrigger.observe('click', this.showForm.bindAsEventListener(this));
		
		this.trailerTrigger = $('trailer-trigger');
		this.trailerTrigger.observe('click', this.hideForm.bindAsEventListener(this));
		
		$('movie-title').innerHTML = trailerTitle;
		$('movie-poster').src = trailerPosterURL;
		$('movie-poster').alt = trailerTitle+' poster';
	},
	showForm: function(e) {
		Event.stop(e);
		AC.Tracking.trackClick({
			pageName: 'Apple - Movie Trailers - ' +this.trailerTitle+ ' - Send to a Friend',
			prop3: 'Apple - Movie Trailers - ' +this.trailerTitle+ ' - Send to a Friend'
		});
		$('content').style.height=($('content').getHeight()-40)+'px';
		this.prevHeight = $('content').getHeight()-40;
		$('content').morph('height:'+563+'px', { duration:0.3 });
		$('promofooter', 'trailer').each(function(elem) { new Effect.Fade(elem, { duration:0.1 }) });
		new Effect.Appear(this.tell, { duration:0.1, queue:'end'} );
	},
	hideForm: function(e) {
		Event.stop(e);
		$('content').morph('height:'+this.prevHeight+'px', { duration:0.3 });
		new Effect.Fade(this.tell, { duration:0.1,
			afterFinish: function() {
				$('trailer', 'promofooter').each(function(elem) { new Effect.Appear(elem, { duration:0.2 }) });
			}.bind(this)				
		});
	}			
});
*/

function ToggleDescription() {
	var limit;
	$('content').hasClassName('single') ? limit = 1100 : limit = 690;
	var des = $('movie-description').down('p');
	if(des.innerHTML.length > limit) {
		var desFull = des.innerHTML;
		var desTrunc = des.innerHTML.truncate(limit, '&nbsp;...');
		des.innerHTML = desTrunc;
		$('toggle').observe('click', function(e) {
			$('content').style.height='auto';
			Event.stop(e);
			if(des.hasClassName('expanded')) {
				new Effect.Morph($('movie-description'), { style:'height:12em;', duration:0.3, afterFinish:function() { 
					des.innerHTML = desTrunc;
					des.removeClassName('expanded');
					$('toggle').down('a').innerHTML = 'さらに見る';
					$('toggle').down('a').removeClassName('up');
					$('toggle').down('a').addClassName('down');
				}});
			} else {
				des.innerHTML = desFull;
				var fullHeight = des.getHeight()/12;
				new Effect.Morph($('movie-description'), { style:'height:'+fullHeight+'em;', duration:0.3, afterFinish:function() {
					des.addClassName('expanded');
					$('toggle').down('a').innerHTML = '閉じる';
					$('toggle').down('a').addClassName('up');
				}});
			}
		});
	} else {
		$('toggle').style.display='none';
	}
};

Event.onDOMReady(function() {
	ToggleDescription();
});
