GalleryQuicktime = Class.create();
GalleryQuicktime.prototype = {
	initialize: function(initialMovie, options) {
		// DOM
		var wrapper = $('gallerymovie-content');
		var displayPanel = $('gallerymovie-movie');
		var controller = 'gallerymovie-controller';
		var descriptionPanel = wrapper.getElementsByTagName('p')[0];
		var gallerySections = $('gallerymovie-nav').getElementsByClassName('video');

		// if no qt...
		if (!AC.Detector.isQTInstalled()) {
			$('gallerymovie-noqt').style.display = 'block';
		}

		var initialSection = null;

		//create sections to populate frontrow with
		var sections = [];
		for(var i = 0; i < gallerySections.length; i++) {
			var section = gallerySections[i];
			var movieUrl = section.href;
			var title = section.firstChild.alt;
			var description = section.target;
			
			var id = gallerySections[i].id.replace(/^mov-/, '');
			
			//replace href of the movielinks 
			section.setAttribute('href', '?movie=' + id);
			
			// create frontrow section
			var newSection = new AC.FrontRowSection(section, 'gallerymovie-movie'+i, movieUrl, description);
			sections.push(newSection);

			//if this is the requested movie, be sure to show it first
			if (initialMovie == id) { 
				initialSection = newSection;
			}
		}
		
		// if we have options, i.e. height or width
		var moviewidth = (options && options.width) ? options.width : 256;
		var movieheight = (options && options.height) ? options.height : 212;

		// if we're Opera, use the standard movie controller, otherwise attach movie controller
		if (AC.Detector.isOpera()) {
			var controllerstatus = true;
			$(controller).style.display = 'none';
			movieheight += 16;
			wrapper.style.width = moviewidth+'px';
		} else {
			var controllerstatus = false;
			var movieController = new AC.QuicktimeController();
			movieController.render(controller);
		}

		// package movie
		var movie = new AC.Quicktime.packageMovie('gallerymovie-movieobject', initialSection.movieUrl, {
			width: moviewidth,
			height: movieheight,
			autostart: true,
			controller: controllerstatus,
			showlogo: false,
			cache: true,
			bgcolor: '#ffffff'
		});

		// sort of initialize frontrow
		var frontrow = new AC.FrontRow(movie, displayPanel, descriptionPanel, sections, options);
		frontrow.show(initialSection);
		
		if (movieController) {
			movieController.attachToMovie(movie);
			movieController.monitorMovie();
		}
		
	}
}

// local
Event.observe(window, 'load', function () {
	var requestedMovieId = document.location.search.toQueryParams()['movie'];
	if (!requestedMovieId) requestedMovieId = 'perfectfit';

	new GalleryQuicktime(requestedMovieId, {width:320, height:240});
}, false);
