Object.extend(AC.OverlayPanel.prototype, {
	superTriggerClicked: AC.ViewMaster.Viewer.prototype.triggerClicked,
	triggerClicked: function(evt,element) {
 		// stop the default event
 		Event.stop(evt);
		if(element.href.indexOf('mobileoverlay') != -1 || element.href.indexOf('languages') != -1) {
			console.log(element.title)
			AC.Tracking.trackClick({
				pageName: 'Apple - iPhone - Features - '+ element.title
			});
		}

        if(this._isDisplaying) return;
        
		//Reset shadow image
		this.setOverlayShadowImageSrc(null);
		
		this._popPosition = null;
		this.currentSectionEvent = evt;
		this.superTriggerClicked(evt,element);	
	}
});

Object.extend(AC.ViewMaster.Section.prototype, {
	didShow: function(viewer) {
		var needsController = this.hasMovie() && !this.isMobile;
		if (needsController) {
			this._movieController = new AC.QuicktimeController();
			this.controllerPanel.innerHTML = '';
			this.controllerPanel.appendChild(this._movieController.render());
		}

		this._playMovie();

		if (needsController) {
			this._onMoviePlayable = this._movieController.monitorMovie.bind(this._movieController);
			this._onMovieFinished = this.didFinishMovie.bind(this);

			var movieName = document.title + ' - ';
			if(this.content.down('h2')) movieName += this.content.down('h2').innerHTML.stripTags();
			this._movieController.attachToMovie(this.movie, {
				onMoviePlayable: function() {
					movieName = movieName.replace(/Apple -/, 'V@S:') + ' (US)';
					AC.Tracking.trackPage({
						pageName: movieName,
						prop4: this.movieLink.href,
						prop6: movieName,
						prop13: movieName
					});
					this._movieController.monitorMovie();
				}.bind(this),
				onMovieFinished: function() {
					movieName = movieName.replace(/V@S/, 'V@E:') + ' (US)';
					AC.Tracking.trackClick({
						prop13: movieName
					}, this, 'o', movieName);
					this.didFinishMovie();
				}.bind(this)
			});
		}
	},
	
	replayMovie: function() {
		this._playMovie();
		var movieName = document.title + ' - ';
		if(this.content.down('h2')) movieName += this.content.down('h2').innerHTML.stripTags();
		
		this._movieController.attachToMovie(this.movie, {
			onMoviePlayable: function() {
				movieName = movieName.replace(/Apple -/, 'V@R:') + ' (US)';
				AC.Tracking.trackPage({
					pageName: movieName,
					prop4: this.movieLink.href,
					prop6: movieName,
					prop13: movieName
				});
				this._movieController.monitorMovie();
			}.bind(this),
			onMovieFinished: function() {
				movieName = movieName.replace(/V@S/, 'V@E:') + ' (US)';
				AC.Tracking.trackClick({
					prop13: movieName
				}, this, 'o', movieName);
				this.didFinishMovie();
			}.bind(this)
		});
	}
});
